FreeBASIC  0.91.0
rtl-system.bas
Go to the documentation of this file.
1 '' intrinsic runtime lib system functions (END, COMMAND, BEEP, SLEEP, TIMER, ...)
2 ''
3 '' chng: oct/2004 written [v1ctor]
4 '' jan/2007 fb_DylibSymbolByOrd [voodooattack]
5 
6 #include once "fb.bi"
7 #include once "fbint.bi"
8 #include once "ast.bi"
9 #include once "rtl.bi"
10 
11 declare function hMultithread_cb ( byval sym as FBSYMBOL ptr ) as integer
12 declare function hThreadCall_cb ( byval sym as FBSYMBOL ptr ) as integer
13 
14  dim shared as FB_RTL_PROCDEF funcdata( 0 to ... ) = _
15  { _
16 /' function fb_CpuDetect cdecl( ) as ulong '/ _
17  ( _
18  @FB_RTL_CPUDETECT, NULL, _
19  FB_DATATYPE_ULONG, FB_FUNCMODE_CDECL, _
20  NULL, FB_RTL_OPT_X86ONLY, _
21  0 _
22  ), _
23 /' sub fb_Init( byval argc as long, byval argv as zstring ptr ptr, byval lang as long ) '/ _
24  ( _
25  @FB_RTL_INIT, NULL, _
26  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
27  NULL, FB_RTL_OPT_NONE, _
28  3, _
29  { _
30  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ), _
31  ( typeMultAddrOf( FB_DATATYPE_CHAR, 2 ), FB_PARAMMODE_BYVAL, FALSE ), _
32  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ) _
33  } _
34  ), _
35 /' sub fb_InitSignals( ) '/ _
36  ( _
37  @FB_RTL_INITSIGNALS, NULL, _
38  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
39  NULL, FB_RTL_OPT_NONE, _
40  0 _
41  ), _
42 /' sub __main cdecl( ) '/ _
43  ( _
44  @FB_RTL_INITCRTCTOR, @"__main", _
45  FB_DATATYPE_VOID, FB_FUNCMODE_CDECL, _
46  NULL, FB_RTL_OPT_NONE, _
47  0 _
48  ), _
49 /' sub fb_End( byval errlevel as long ) '/ _
50  ( _
51  @FB_RTL_END, NULL, _
52  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
53  NULL, FB_RTL_OPT_NONE, _
54  1, _
55  { _
56  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ) _
57  } _
58  ), _
59 /' function atexit cdecl( byval proc as sub cdecl() ) as long '/ _
60  ( _
61  @FB_RTL_ATEXIT, @"atexit", _
62  FB_DATATYPE_LONG, FB_FUNCMODE_CDECL, _
63  NULL, FB_RTL_OPT_NONE, _
64  1, _
65  { _
66  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
67  } _
68  ), _
69 /' function command( byval argc as long = -1 ) as string '/ _
70  ( _
71  @"command", @"fb_Command", _
72  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
73  NULL, FB_RTL_OPT_STRSUFFIX, _
74  1, _
75  { _
76  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ) _
77  } _
78  ), _
79 /' function curdir( ) as string '/ _
80  ( _
81  @"curdir", @"fb_CurDir", _
82  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
83  NULL, FB_RTL_OPT_NOQB, _
84  0 _
85  ), _
86 /' function exepath( ) as string '/ _
87  ( _
88  @"exepath", @"fb_ExePath", _
89  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
90  NULL, FB_RTL_OPT_NOQB, _
91  0 _
92  ), _
93 /' function timer( ) as double '/ _
94  ( _
95  @"timer", @"fb_Timer", _
96  FB_DATATYPE_DOUBLE, FB_FUNCMODE_FBCALL, _
97  NULL, FB_RTL_OPT_NONE, _
98  0 _
99  ), _
100 /' function time( ) as string '/ _
101  ( _
102  @"time", @"fb_Time", _
103  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
104  NULL, FB_RTL_OPT_STRSUFFIX, _
105  0 _
106  ), _
107 /' function date( ) as string '/ _
108  ( _
109  @"date", @"fb_Date", _
110  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
111  NULL, FB_RTL_OPT_STRSUFFIX, _
112  0 _
113  ), _
114 /' function shell( byval program as string = "" ) as long '/ _
115  ( _
116  @"shell", @"fb_Shell", _
117  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
118  NULL, FB_RTL_OPT_NONE, _
119  1, _
120  { _
121  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, TRUE, NULL ) _
122  } _
123  ), _
124 /' sub system( byval errlevel as long = 0 ) '/ _
125  ( _
126  @"system", @"fb_End", _
127  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
128  NULL, FB_RTL_OPT_NONE, _
129  1, _
130  { _
131  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, 0 ) _
132  } _
133  ), _
134 /' sub stop( byval errlevel as long = 0 ) '/ _
135  ( _
136  @"stop", @"fb_End", _
137  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
138  NULL, FB_RTL_OPT_NONE, _
139  1, _
140  { _
141  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, 0 ) _
142  } _
143  ), _
144 /' function run( byref program as string, byref arguments as string = "" ) as long '/ _
145  ( _
146  @"run", @"fb_Run", _
147  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
148  NULL, FB_RTL_OPT_NONE, _
149  2, _
150  { _
151  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ), _
152  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, TRUE, NULL ) _
153  } _
154  ), _
155 /' function chain( byref program as string ) as long '/ _
156  ( _
157  @"chain", @"fb_Chain", _
158  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
159  NULL, FB_RTL_OPT_NONE, _
160  1, _
161  { _
162  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ) _
163  } _
164  ), _
165 /' function exec( byref program as string, byref args as string ) as long '/ _
166  ( _
167  @"exec", @"fb_Exec", _
168  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
169  NULL, FB_RTL_OPT_NOQB, _
170  2, _
171  { _
172  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ), _
173  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ) _
174  } _
175  ), _
176 /' function environ( byref varname as string ) as string '/ _
177  ( _
178  @"environ", @"fb_GetEnviron", _
179  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
180  NULL, FB_RTL_OPT_STRSUFFIX, _
181  1, _
182  { _
183  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ) _
184  } _
185  ), _
186 /' function setenviron( byref varname as string ) as long '/ _
187  ( _
188  @"setenviron", @"fb_SetEnviron", _
189  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
190  NULL, FB_RTL_OPT_NONE, _
191  1, _
192  { _
193  ( FB_DATATYPE_STRING,FB_PARAMMODE_BYREF, FALSE ) _
194  } _
195  ), _
196 /' sub sleep overload( byval msecs as long ) '/ _
197  ( _
198  @"sleep", @"fb_Sleep", _
199  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
200  @rtlMultinput_cb, FB_RTL_OPT_OVER or FB_RTL_OPT_NOQB, _
201  1, _
202  { _
203  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ) _
204  } _
205  ), _
206 /' sub sleep overload( byval secs as long ) '/ _
207  ( _
208  @"sleep", @"fb_SleepQB", _
209  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
210  @rtlMultinput_cb, FB_RTL_OPT_OVER or FB_RTL_OPT_QBONLY, _
211  1, _
212  { _
213  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, -1 ) _
214  } _
215  ), _
216 /' function sleep overload( byval msecs as long, byval kind as long ) as long '/ _
217  ( _
218  @"sleep", @"fb_SleepEx", _
219  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
220  @rtlMultinput_cb, FB_RTL_OPT_OVER or FB_RTL_OPT_ERROR, _
221  2, _
222  { _
223  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ), _
224  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ) _
225  } _
226  ), _
227 /' function dir overload( byval out_attrib as long ptr = NULL ) as string '/ _
228  ( _
229  @"dir", @"fb_DirNext", _
230  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
231  NULL, FB_RTL_OPT_OVER or FB_RTL_OPT_NOQB, _
232  1, _
233  { _
234  ( typeAddrOf( FB_DATATYPE_LONG ), FB_PARAMMODE_BYVAL, TRUE, NULL ) _
235  } _
236  ), _
237 /' function dir overload( byref out_attrib as long ) as string '/ _
238  ( _
239  @"dir", @"fb_DirNext", _
240  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
241  NULL, FB_RTL_OPT_OVER or FB_RTL_OPT_NOQB, _
242  1, _
243  { _
244  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYREF, FALSE ) _
245  } _
246  ), _
247 /' function dir overload( byref out_attrib as longint ) as string '/ _
248  ( _
249  @"dir", @"fb_DirNext64", _
250  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
251  NULL, FB_RTL_OPT_OVER or FB_RTL_OPT_NOQB, _
252  1, _
253  { _
254  ( FB_DATATYPE_LONGINT, FB_PARAMMODE_BYREF, FALSE ) _
255  } _
256  ), _
257 /' function dir overload( byref mask as string, _
258  byval attrib_mask as long = &h21, _
259  byval out_attrib as long ptr = NULL ) as string '/ _
260  ( _
261  @"dir", @"fb_Dir", _
262  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
263  NULL, FB_RTL_OPT_OVER or FB_RTL_OPT_NOQB, _
264  3, _
265  { _
266  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ), _
267  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, &h21 ), _
268  ( typeAddrOf( FB_DATATYPE_LONG ), FB_PARAMMODE_BYVAL, TRUE, NULL ) _
269  } _
270  ), _
271 /' function dir overload( byref mask as string, _
272  byval attrib_mask as long = &h21, _
273  byref out_attrib as long ) as string '/ _
274  ( _
275  @"dir", @"fb_Dir", _
276  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
277  NULL, FB_RTL_OPT_OVER or FB_RTL_OPT_NOQB, _
278  3, _
279  { _
280  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ), _
281  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, &h21 ), _
282  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYREF, FALSE ) _
283  } _
284  ), _
285 /' function dir overload( byref mask as string, _
286  byval attrib_mask as long = &h21, _
287  byref out_attrib as longint ) as string '/ _
288  ( _
289  @"dir", @"fb_Dir64", _
290  FB_DATATYPE_STRING, FB_FUNCMODE_FBCALL, _
291  NULL, FB_RTL_OPT_OVER or FB_RTL_OPT_NOQB, _
292  3, _
293  { _
294  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ), _
295  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, TRUE, &h21 ), _
296  ( FB_DATATYPE_LONGINT, FB_PARAMMODE_BYREF, FALSE ) _
297  } _
298  ), _
299 /' function settime( byref time as string ) as long '/ _
300  ( _
301  @"settime", @"fb_SetTime", _
302  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
303  NULL, FB_RTL_OPT_NONE, _
304  1, _
305  { _
306  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ) _
307  } _
308  ), _
309 /' function setdate( byref date as string ) as long '/ _
310  ( _
311  @"setdate", @"fb_SetDate", _
312  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
313  NULL, FB_RTL_OPT_NONE, _
314  1, _
315  { _
316  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ) _
317  } _
318  ), _
319 /' function threadcreate _
320  ( _
321  byval proc as sub( byval param as any ptr ),
322  byval param as any ptr = 0, _
323  byval stack_size as integer = 0 _
324  ) as any ptr '/ _
325  ( _
326  @"threadcreate", @"fb_ThreadCreate", _
327  typeAddrOf( FB_DATATYPE_VOID ), FB_FUNCMODE_FBCALL, _
328  @hMultithread_cb, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
329  5, _
330  { _
331  ( typeAddrOf( FB_DATATYPE_FUNCTION ), FB_PARAMMODE_BYVAL, TRUE, 1 ), _
332  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ), _
333  ( FB_DATATYPE_VOID, NULL, FALSE ), _
334  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, TRUE, 0 ), _
335  ( FB_DATATYPE_INTEGER, FB_PARAMMODE_BYVAL, TRUE, 0 ) _
336  } _
337  ), _
338 /' sub threadwait( byval thread as any ptr ) '/ _
339  ( _
340  @"threadwait", @"fb_ThreadWait", _
341  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
342  @hMultithread_cb, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
343  1, _
344  { _
345  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
346  } _
347  ), _
348 /' function fb_ThreadCall cdecl( byval proc as any ptr, byval abi as long, _
349  byval stack_size as integer, byval num_args as long, ... ) as any ptr '/ _
350  ( _
351  @"fb_ThreadCall", NULL, _
352  typeAddrOf( FB_DATATYPE_VOID ), FB_FUNCMODE_CDECL, _
353  @hThreadCall_cb, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
354  5, _
355  { _
356  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ), _
357  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ), _
358  ( FB_DATATYPE_INTEGER, FB_PARAMMODE_BYVAL, FALSE ), _
359  ( FB_DATATYPE_LONG, FB_PARAMMODE_BYVAL, FALSE ), _
360  ( FB_DATATYPE_INVALID, FB_PARAMMODE_VARARG, FALSE ) _
361  } _
362  ), _
363 /' function mutexcreate( ) as any ptr '/ _
364  ( _
365  @"mutexcreate", @"fb_MutexCreate", _
366  typeAddrOf( FB_DATATYPE_VOID ), FB_FUNCMODE_FBCALL, _
367  NULL, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
368  0 _
369  ), _
370 /' sub mutexdestroy( byval mutex as any ptr ) '/ _
371  ( _
372  @"mutexdestroy", @"fb_MutexDestroy", _
373  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
374  NULL, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
375  1, _
376  { _
377  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
378  } _
379  ), _
380 /' sub mutexlock( byval mutex as any ptr ) '/ _
381  ( _
382  @"mutexlock", @"fb_MutexLock", _
383  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
384  NULL, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
385  1, _
386  { _
387  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
388  } _
389  ), _
390 /' sub mutexunlock( byval mutex as any ptr ) '/ _
391  ( _
392  @"mutexunlock", @"fb_MutexUnlock", _
393  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
394  NULL, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
395  1, _
396  { _
397  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
398  } _
399  ), _
400 /' function condcreate( ) as any ptr '/ _
401  ( _
402  @"condcreate", @"fb_CondCreate", _
403  typeAddrOf( FB_DATATYPE_VOID ), FB_FUNCMODE_FBCALL, _
404  NULL, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
405  0 _
406  ), _
407 /' sub conddestroy( byval cond as any ptr ) '/ _
408  ( _
409  @"conddestroy", @"fb_CondDestroy", _
410  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
411  NULL, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
412  1, _
413  { _
414  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
415  } _
416  ), _
417 /' sub condsignal( byval cond as any ptr ) '/ _
418  ( _
419  @"condsignal", @"fb_CondSignal", _
420  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
421  NULL, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
422  1, _
423  { _
424  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
425  } _
426  ), _
427 /' sub condbroadcast( byval cond as any ptr ) '/ _
428  ( _
429  @"condbroadcast", @"fb_CondBroadcast", _
430  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
431  NULL, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
432  1, _
433  { _
434  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
435  } _
436  ), _
437 /' sub condwait( byval cond as any ptr, byval mutex as any ptr ) '/ _
438  ( _
439  @"condwait", @"fb_CondWait", _
440  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
441  NULL, FB_RTL_OPT_MT or FB_RTL_OPT_NOQB, _
442  2, _
443  { _
444  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ), _
445  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
446  } _
447  ), _
448 /' function dylibload( byref filename as string ) as any ptr '/ _
449  ( _
450  @"dylibload", @"fb_DylibLoad", _
451  typeAddrOf( FB_DATATYPE_VOID ), FB_FUNCMODE_FBCALL, _
452  NULL, FB_RTL_OPT_NOQB, _
453  1, _
454  { _
455  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ) _
456  } _
457  ), _
458 /' function dylibsymbol overload( byval library as any ptr, byref symbol as string ) as any ptr '/ _
459  ( _
460  @"dylibsymbol", @"fb_DylibSymbol", _
461  typeAddrOf( FB_DATATYPE_VOID ), FB_FUNCMODE_FBCALL, _
462  NULL, FB_RTL_OPT_OVER or FB_RTL_OPT_NOQB, _
463  2, _
464  { _
465  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ), _
466  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ) _
467  } _
468  ), _
469 /' function dylibsymbol overload( byval library as any ptr, byval symbol as short ) as any ptr '/ _
470  ( _
471  @"dylibsymbol", @"fb_DylibSymbolByOrd", _
472  typeAddrOf( FB_DATATYPE_VOID ), FB_FUNCMODE_FBCALL, _
473  NULL, FB_RTL_OPT_OVER or FB_RTL_OPT_NOQB, _
474  2, _
475  { _
476  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ), _
477  ( FB_DATATYPE_SHORT, FB_PARAMMODE_BYVAL, FALSE ) _
478  } _
479  ), _
480 /' sub dylibfree( byval library as any ptr ) '/ _
481  ( _
482  @"dylibfree", @"fb_DylibFree", _
483  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
484  NULL, FB_RTL_OPT_NOQB, _
485  1, _
486  { _
487  ( typeAddrOf( FB_DATATYPE_VOID ), FB_PARAMMODE_BYVAL, FALSE ) _
488  } _
489  ), _
490 /' sub beep( ) '/ _
491  ( _
492  @"beep", @"fb_Beep", _
493  FB_DATATYPE_VOID, FB_FUNCMODE_FBCALL, _
494  NULL, FB_RTL_OPT_NONE, _
495  0 _
496  ), _
497 /' function mkdir( byref path as string ) as long '/ _
498  ( _
499  @"mkdir", @"fb_MkDir", _
500  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
501  NULL, FB_RTL_OPT_NONE, _
502  1, _
503  { _
504  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ) _
505  } _
506  ), _
507 /' function rmdir( byref path as string ) as long '/ _
508  ( _
509  @"rmdir", @"fb_RmDir", _
510  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
511  NULL, FB_RTL_OPT_NONE, _
512  1, _
513  { _
514  ( FB_DATATYPE_STRING, FB_PARAMMODE_BYREF, FALSE ) _
515  } _
516  ), _
517 /' function chdir( byref path as string ) as long '/ _
518  ( _
519  @"chdir", @"fb_ChDir", _
520  FB_DATATYPE_LONG, FB_FUNCMODE_FBCALL, _
521  NULL, FB_RTL_OPT_NONE, _
522  1, _
523  { _
524  ( FB_DATATYPE_STRING,FB_PARAMMODE_BYREF, FALSE ) _
525  } _
526  ), _
527 /' EOL '/ _
528  ( _
529  NULL _
530  ) _
531  }
532 
533 '':::::
535 
537 
538 end sub
539 
540 '':::::
542 
543  '' procs will be deleted when symbEnd is called
544 
545 end sub
546 
547 function rtlX86CpuCheck( ) as integer
548  dim as ASTNODE ptr proc = any, cpu = any
549  dim as FBSYMBOL ptr s = any, label = any
550  dim as integer family = any
551  dim as string familystr
552 
553  function = FALSE
554 
555  '' Trim to 686, using higher values from the FB_CPUTYPE_* constants
556  '' doesn't make sense, 786 represents the Intel Itanium (IA-64),
557  '' not FB_CPUTYPE_ATHLON, and so on.
558  family = env.clopt.cputype
559  if( family > FB_CPUTYPE_686 ) then
560  family = FB_CPUTYPE_686
561  end if
562 
563  select case( family )
564  case FB_CPUTYPE_386 : familystr = "386" : family = 3
565  case FB_CPUTYPE_486 : familystr = "486" : family = 4
566  case FB_CPUTYPE_586 : familystr = "586" : family = 5
567  case else : familystr = "686" : family = 6
568  end select
569 
570  ''
571  proc = astNewCALL( PROCLOOKUP( CPUDETECT ), NULL )
572 
573  '' cpu = fb_CpuDetect shr 28
574  cpu = astNewBOP( AST_OP_SHR, proc, astNewCONSTi( 28, FB_DATATYPE_UINT ) )
575 
576  '' if( cpu < family ) then
577  label = symbAddLabel( NULL )
578  astAdd( astNewBOP( AST_OP_GE, cpu, astNewCONSTi( family, FB_DATATYPE_UINT ), label, AST_OPOPT_NONE ) )
579 
580  '' print "This program requires at least a <cpu> to run."
581  s = symbAllocStrConst( "This program requires at least a " + familystr + " to run.", -1 )
582  rtlPrint( astNewCONSTi( 0 ), FALSE, FALSE, astNewVAR( s ) )
583 
584  '' end 1
585  proc = astNewCALL( PROCLOOKUP( END ), NULL )
586  if( astNewARG( proc, astNewCONSTi( 1 ) ) = NULL ) then
587  exit function
588  end if
589  astAdd( proc )
590 
591  '' end if
592  astAdd( astNewLABEL( label ) )
593 
594  if( env.clopt.fputype = FB_FPUTYPE_SSE ) then
595  proc = astNewCALL( PROCLOOKUP( CPUDETECT ), NULL )
596 
597  '' cpu = fb_CpuDetect And &h6000000
598  cpu = astNewBOP( AST_OP_AND, proc, astNewCONSTi( &h6000000, FB_DATATYPE_UINT ) )
599 
600  '' if( fpu <> &h6000000 ) then
601  label = symbAddLabel( NULL )
602  astAdd( astNewBOP( AST_OP_EQ, _
603  cpu, _
604  astNewCONSTi( &h6000000, FB_DATATYPE_UINT ), _
605  label, _
606  AST_OPOPT_NONE ) )
607 
608  '' print "This program requires SSE and SSE2 instructions to run."
609  s = symbAllocStrConst( "This program requires SSE and SSE2 instructions to run.", -1 )
610  rtlPrint( astNewCONSTi( 0 ), FALSE, FALSE, astNewVAR( s ) )
611 
612  '' end 1
613  proc = astNewCALL( PROCLOOKUP( END ), NULL )
614  if( astNewARG( proc, astNewCONSTi( 1 ) ) = NULL ) then
615  exit function
616  end if
617  astAdd( proc )
618 
619  '' end if
620  astAdd( astNewLABEL( label ) )
621  end if
622 
623  function = TRUE
624 end function
625 
626 '':::::
627 function rtlInitApp _
628  ( _
629  byval argc as ASTNODE ptr, _
630  byval argv as ASTNODE ptr _
631  ) as ASTNODE ptr
632 
633  dim as ASTNODE ptr proc = any
634  dim as integer is_exe = any
635 
636  is_exe = (env.clopt.outtype <> FB_OUTTYPE_DYNAMICLIB)
637 
638  if( env.clopt.backend = FB_BACKEND_GAS ) then
639  '' call __monstartup() on win32/cygwin if profiling
640  select case( env.clopt.target )
641  case FB_COMPTARGET_WIN32, FB_COMPTARGET_CYGWIN
642  if( env.clopt.profile ) then
643  '' __monstartup()
645  end if
646  end select
647 
648  '' call default CRT0 constructors (only required for Win32)
649  if( env.clopt.target = FB_COMPTARGET_WIN32 ) then
650  '' __main()
651  astAdd( astNewCALL( PROCLOOKUP( INITCRTCTOR ), NULL ) )
652  end if
653  end if
654 
655  '' fb_Init( argc, argv, lang )
656  proc = astNewCALL( PROCLOOKUP( INIT ), NULL )
657  astNewARG( proc, argc )
658  astNewARG( proc, argv )
659  astNewARG( proc, astNewCONSTi( env.clopt.lang ) )
660  astAdd( proc )
661 
662  '' Error checking enabled and not a DLL?
663  if( env.clopt.errorcheck and is_exe ) then
664  '' fb_InitSignals( )
665  astAdd( astNewCALL( PROCLOOKUP( INITSIGNALS ), NULL ) )
666 
667  '' Checking the CPU for features on x86
668  if( fbCpuTypeIsX86( ) ) then
669  '' Check CPU type
670  rtlX86CpuCheck( )
671  end if
672  end if
673 
674  function = proc
675 end function
676 
677 function rtlExitApp( byval errlevel as ASTNODE ptr ) as integer
678  dim as ASTNODE ptr proc = any
679 
680  function = FALSE
681 
682  '' fb_End( errlevel )
683  proc = astNewCALL( PROCLOOKUP( END ), NULL )
684 
685  if( errlevel = NULL ) then
686  errlevel = astNewCONSTi( 0 )
687  end if
688  if( astNewARG( proc, errlevel ) = NULL ) then
689  exit function
690  end if
691 
692  astAdd( proc )
693 
694  function = TRUE
695 end function
696 
697 '':::::
698 function hMultithread_cb _
699  ( _
700  byval sym as FBSYMBOL ptr _
701  ) as integer
702 
703  env.clopt.multithreaded = TRUE
704 
705  return TRUE
706 
707 end function
708 
709 '':::::
710 function hThreadCall_cb _
711  ( _
712  byval sym as FBSYMBOL ptr _
713  ) as integer
714 
715  static as integer libsAdded = FALSE
716 
717  if( libsadded = FALSE ) then
718  libsAdded = TRUE
719  fbAddLib( "ffi" )
720  end if
721 
722  return hMultithread_cb( sym )
723 end function
724 
725 '':::::
726 function rtlAtExit _
727  ( _
728  byval procexpr as ASTNODE ptr _
729  ) as ASTNODE ptr static
730 
731  dim as ASTNODE ptr proc
732 
733  function = NULL
734 
735  '' atexit( proc )
736  proc = astNewCALL( PROCLOOKUP( ATEXIT ) )
737 
738  if( astNewARG( proc, procexpr ) = NULL ) then
739  exit function
740  end if
741 
742  function = proc
743 
744 end function
745 
746 
747 
748