FreeBASIC  0.91.0
rtl-gosub.bas
Go to the documentation of this file.
1 '' rtlib support for GOSUB/RETURN (using setjmp/longjmp)
2 ''
3 '' chng: apr/2008 written [jeffm]
4 
5 #include once "fb.bi"
6 #include once "fbint.bi"
7 #include once "ast.bi"
8 #include once "lex.bi"
9 #include once "rtl.bi"
10 
11  dim shared as FB_RTL_PROCDEF funcdata( 0 to ... ) = _
12  { _
13 /' function fb_GosubPush( byval ctx as any ptr ptr ) as any ptr '/ _
14  ( _
15  @FB_RTL_GOSUBPUSH, NULL, _
16  typeAddrOf( FB_DATATYPE_VOID ), FB_FUNCMODE_FBCALL, _
17  NULL, FB_RTL_OPT_NONE, _
18  1, _
19  { _
20  ( typeMultAddrOf( FB_DATATYPE_VOID, 2 ), FB_PARAMMODE_BYVAL, FALSE ) _
21  } _
22  ), _
23 /' function fb_GosubPop( byval ctx as any ptr ptr ) as long '/ _
24  ( _
25  @FB_RTL_GOSUBPOP, NULL, _
26  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
27  NULL, FB_RTL_OPT_NONE, _
28  1, _
29  { _
30  ( typeMultAddrOf( FB_DATATYPE_VOID, 2 ), FB_PARAMMODE_BYVAL, FALSE ) _
31  } _
32  ), _
33 /' function fb_GosubReturn( byval ctx as any ptr ptr ) as long '/ _
34  ( _
35  @FB_RTL_GOSUBRETURN, NULL, _
36  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
37  NULL, FB_RTL_OPT_NONE, _
38  1, _
39  { _
40  ( typeMultAddrOf( FB_DATATYPE_VOID, 2 ), FB_PARAMMODE_BYVAL, FALSE ) _
41  } _
42  ), _
43 /' sub fb_GosubExit( byval ctx as any ptr ptr ) '/ _
44  ( _
45  @FB_RTL_GOSUBEXIT, NULL, _
46  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
47  NULL, FB_RTL_OPT_NONE, _
48  1, _
49  { _
50  ( typeMultAddrOf( FB_DATATYPE_VOID, 2 ), FB_PARAMMODE_BYVAL, FALSE ) _
51  } _
52  ), _
53 /' EOL '/ _
54  ( _
55  NULL _
56  ) _
57  }
58 
59  '' Win32 _setjmp()
60  dim shared as FB_RTL_PROCDEF funcdata1( 0 to ... ) = _
61  { _
62 /' function fb_SetJmp cdecl( byval buf as any ptr ) as long '/ _
63  ( _
64  @FB_RTL_SETJMP, @"_setjmp", _
65  FB_DATATYPE_LONG, FB_FUNCMODE_CDECL, _
66  NULL, FB_RTL_OPT_NONE, _
67  1, _
68  { _
69  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
70  } _
71  ), _
72 /' EOL '/ _
73  ( _
74  NULL _
75  ) _
76  }
77 
78  '' Linux/DOS setjmp()
79  dim shared as FB_RTL_PROCDEF funcdata2( 0 to ... ) = _
80  { _
81 /' function fb_SetJmp cdecl( byval buf as any ptr ) as long '/ _
82  ( _
83  @FB_RTL_SETJMP, @"setjmp", _
84  FB_DATATYPE_LONG, FB_FUNCMODE_CDECL, _
85  NULL, FB_RTL_OPT_NONE, _
86  1, _
87  { _
88  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
89  } _
90  ), _
91 /' EOL '/ _
92  ( _
93  NULL _
94  ) _
95  }
96 
97 '':::::
99 
100  '' No need to add these procs if GOSUB isn't allowed in the dialect...
101  if( fbLangOptIsSet( FB_LANG_OPT_GOSUB ) ) then
102 
104 
105  if( env.clopt.target = FB_COMPTARGET_WIN32 ) then
107  else
109  end if
110 
111  end if
112 
113 end sub
114 
115 '':::::
117 
118  '' procs will be deleted when symbEnd is called
119 
120 end sub
121 
122 '':::::
123 function rtlGosubPush _
124  ( _
125  byval ctx as ASTNODE ptr _
126  ) as ASTNODE ptr
127 
128  dim as ASTNODE ptr proc = any
129 
130  function = NULL
131 
132  proc = astNewCALL( PROCLOOKUP( GOSUBPUSH ) )
133 
134  '' byval ctx as any ptr ptr
135  if( astNewARG( proc, ctx ) = NULL ) then
136  exit function
137  end if
138 
139  function = proc
140 
141 end function
142 
143 '':::::
144 function rtlGosubPop _
145  ( _
146  byval ctx as ASTNODE ptr _
147  ) as ASTNODE ptr
148 
149  dim as ASTNODE ptr proc = any
150 
151  function = NULL
152 
153  proc = astNewCALL( PROCLOOKUP( GOSUBPOP ) )
154 
155  '' byval ctx as any ptr ptr
156  if( astNewARG( proc, ctx ) = NULL ) then
157  exit function
158  end if
159 
160  function = proc
161 
162 end function
163 
164 function rtlGosubReturn( byval ctx as ASTNODE ptr ) as integer
165  dim as ASTNODE ptr proc = any
166 
167  proc = astNewCALL( PROCLOOKUP( GOSUBRETURN ) )
168 
169  '' byval ctx as any ptr ptr
170  if( astNewARG( proc, ctx ) = NULL ) then
171  exit function
172  end if
173 
174  astAdd( rtlErrorCheck( proc ) )
175  function = TRUE
176 end function
177 
178 '':::::
179 function rtlGosubExit _
180  ( _
181  byval ctx as ASTNODE ptr _
182  ) as ASTNODE ptr
183 
184  dim as ASTNODE ptr proc = any
185 
186  function = NULL
187 
188  proc = astNewCALL( PROCLOOKUP( GOSUBEXIT ) )
189 
190  '' byval ctx as any ptr ptr
191  if( astNewARG( proc, ctx ) = NULL ) then
192  exit function
193  end if
194 
195  function = proc
196 
197 end function
198 
199 '':::::
200 function rtlSetJmp _
201  ( _
202  byval ctx as ASTNODE ptr _
203  ) as ASTNODE ptr
204 
205  dim as ASTNODE ptr proc = any
206 
207  function = NULL
208 
209  proc = astNewCALL( PROCLOOKUP( SETJMP ) )
210 
211  '' byval ctx as any ptr ptr
212  if( astNewARG( proc, ctx ) = NULL ) then
213  exit function
214  end if
215 
216  function = proc
217 
218 end function
219