FreeBASIC  0.91.0
rtl-macro.bas
Go to the documentation of this file.
1 '' intrinsic macros (RGB, BIT, ASSERT, ...)
2 ''
3 '' chng: oct/2004 written [v1ctor]
4 
5 
6 #include once "fb.bi"
7 #include once "fbint.bi"
8 #include once "ast.bi"
9 #include once "rtl.bi"
10 
13  data as const any ptr
14 end type
15 
17  name as const zstring ptr
19  params as integer
20  paramTb(0 to 3) as const zstring ptr
22 end type
23 
24  dim shared as FB_RTL_MACRODEF macrodata(0 to 15) = _
25  { _
26 /' #define RGB(r,g,b) ((cuint(r) shl 16) or (cuint(g) shl 8) or cuint(b) or &hFF000000) '/ _
27  ( _
28  @"RGB", FB_RTL_OPT_NONE, _
29  3, _
30  { _
31  @"R", @"G", @"B" _
32  }, _
33  { _
34  ( FB_DEFTOK_TYPE_TEX, @"((cuint(" ), _
35  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
36  ( FB_DEFTOK_TYPE_TEX, @") shl 16) or (cuint(" ), _
37  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
38  ( FB_DEFTOK_TYPE_TEX, @") shl 8) or cuint(" ), _
39  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 2 ) ), _
40  ( FB_DEFTOK_TYPE_TEX, @") or &hFF000000)" ), _
41  ( -1 ) _
42  } _
43  ), _
44 /' #define RGBA(r,g,b,a) ((cuint(r) shl 16) or (cuint(g) shl 8) or cuint(b) or (cuint(a) shl 24)) '/ _
45  ( _
46  @"RGBA", FB_RTL_OPT_NONE, _
47  4, _
48  { _
49  @"R", @"G", @"B", @"A" _
50  }, _
51  { _
52  ( FB_DEFTOK_TYPE_TEX, @"((cuint(" ), _
53  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
54  ( FB_DEFTOK_TYPE_TEX, @") shl 16) or (cuint(" ), _
55  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
56  ( FB_DEFTOK_TYPE_TEX, @") shl 8) or cuint(" ), _
57  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 2 ) ), _
58  ( FB_DEFTOK_TYPE_TEX, @") or (cuint(" ), _
59  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 3 ) ), _
60  ( FB_DEFTOK_TYPE_TEX, @") shl 24))" ), _
61  ( -1 ) _
62  } _
63  ), _
64 /' #define va_arg(a,t) peek( t, a ) '/ _
65  ( _
66  @"VA_ARG", FB_RTL_OPT_NOGCC, _
67  2, _
68  { _
69  @"A", @"T" _
70  }, _
71  { _
72  ( FB_DEFTOK_TYPE_TEX, @"peek(" ), _
73  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
74  ( FB_DEFTOK_TYPE_TEX, @"," ), _
75  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
76  ( FB_DEFTOK_TYPE_TEX, @")" ), _
77  ( -1 ) _
78  } _
79  ), _
80 /' #define va_next(a,t) (cptr(t ptr, cptr(byte ptr, a) + (sizeof(t)+sizeof(any ptr)-1 and -sizeof(any ptr)) ) ) '/ _
81  ( _
82  @"VA_NEXT", FB_RTL_OPT_NOGCC, _
83  2, _
84  { _
85  @"A", @"T" _
86  }, _
87  { _
88  ( FB_DEFTOK_TYPE_TEX, @"(cptr(" ), _
89  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
90  ( FB_DEFTOK_TYPE_TEX, @" ptr, cptr(byte ptr, " ), _
91  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
92  ( FB_DEFTOK_TYPE_TEX, @") + (sizeof(" ), _
93  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
94  ( FB_DEFTOK_TYPE_TEX, @") + sizeof(any ptr)-1 and -sizeof(any ptr)) ) )" ), _
95  ( -1 ) _
96  } _
97  ), _
98 /' #define ASSERT(e) if (e) = FALSE then fb_Assert(__FILE__, __LINE__, __FUNCTION__, #e) '/ _
99  ( _
100  @"ASSERT", FB_RTL_OPT_DBGONLY, _
101  1, _
102  { _
103  @"E" _
104  }, _
105  { _
106  ( FB_DEFTOK_TYPE_TEX, @"if (" ), _
107  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
108  ( FB_DEFTOK_TYPE_TEX, @") = 0 then fb_Assert(__FILE__, __LINE__, __FUNCTION__, " ), _
109  ( FB_DEFTOK_TYPE_PARAMSTR, cast( any ptr, 0 ) ), _
110  ( FB_DEFTOK_TYPE_TEX, @") end if" ), _
111  ( -1 ) _
112  } _
113  ), _
114 /' #define ASSERTWARN(e) if (e) = FALSE then fb_AssertWarn(__FILE__, __LINE__, __FUNCTION__, #e) '/ _
115  ( _
116  @"ASSERTWARN", FB_RTL_OPT_DBGONLY, _
117  1, _
118  { _
119  @"E" _
120  }, _
121  { _
122  ( FB_DEFTOK_TYPE_TEX, @"if (" ), _
123  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
124  ( FB_DEFTOK_TYPE_TEX, @") = 0 then fb_AssertWarn(__FILE__, __LINE__, __FUNCTION__, " ), _
125  ( FB_DEFTOK_TYPE_PARAMSTR, cast( any ptr, 0 ) ), _
126  ( FB_DEFTOK_TYPE_TEX, @") end if" ), _
127  ( -1 ) _
128  } _
129  ), _
130 /' #define OFFSETOF(type_,field_) cint( @cast( type_ ptr, 0 )->field_ ) '/ _
131  ( _
132  @"OFFSETOF", FB_RTL_OPT_NONE, _
133  2, _
134  { _
135  @"T", @"F" _
136  }, _
137  { _
138  ( FB_DEFTOK_TYPE_TEX, @"cint( @cast( " ), _
139  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
140  ( FB_DEFTOK_TYPE_TEX, @" ptr, 0 )->" ), _
141  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
142  ( FB_DEFTOK_TYPE_TEX, @" )" ), _
143  ( -1 ) _
144  } _
145  ), _
146 /' #define __FB_MIN_VERSION__(major, minor, patch_level) ((__FB_VER_MAJOR__ > (major)) or ((__FB_VER_MAJOR__ = (major)) and ((__FB_VER_MINOR__ > (minor)) or (__FB_VER_MINOR__ = (minor) and __FB_VER_PATCH__ >= (patch_level))))) '/ _
147  ( _
148  @"__FB_MIN_VERSION__", FB_RTL_OPT_NONE, _
149  3, _
150  { _
151  @"MAJOR", @"MINOR", @"PATCH_LEVEL" _
152  }, _
153  { _
154  ( FB_DEFTOK_TYPE_TEX, @"((__FB_VER_MAJOR__ > (" ), _
155  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
156  ( FB_DEFTOK_TYPE_TEX, @")) or ((__FB_VER_MAJOR__ = (" ), _
157  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
158  ( FB_DEFTOK_TYPE_TEX, @")) and ((__FB_VER_MINOR__ > (" ), _
159  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
160  ( FB_DEFTOK_TYPE_TEX, @")) or (__FB_VER_MINOR__ = (" ), _
161  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
162  ( FB_DEFTOK_TYPE_TEX, @") and __FB_VER_PATCH__ >= (" ), _
163  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 2 ) ), _
164  ( FB_DEFTOK_TYPE_TEX, @")))))" ), _
165  ( -1 ) _
166  } _
167  ), _
168 /' #define LOWORD(x) (cuint(x) and &h0000FFFF) '/ _
169  ( _
170  @"LOWORD", FB_RTL_OPT_NONE, _
171  1, _
172  { _
173  @"X" _
174  }, _
175  { _
176  ( FB_DEFTOK_TYPE_TEX, @"(cuint(" ), _
177  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
178  ( FB_DEFTOK_TYPE_TEX, @") and &h0000FFFF)" ), _
179  ( -1 ) _
180  } _
181  ), _
182 /' #define HIWORD(x) (cuint(x) shr 16) '/ _
183  ( _
184  @"HIWORD", FB_RTL_OPT_NONE, _
185  1, _
186  { _
187  @"X" _
188  }, _
189  { _
190  ( FB_DEFTOK_TYPE_TEX, @"(cuint(" ), _
191  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
192  ( FB_DEFTOK_TYPE_TEX, @") shr 16)" ), _
193  ( -1 ) _
194  } _
195  ), _
196 /' #define LOBYTE(x) (cuint(x) and &h000000FF) '/ _
197  ( _
198  @"LOBYTE", FB_RTL_OPT_NONE, _
199  1, _
200  { _
201  @"X" _
202  }, _
203  { _
204  ( FB_DEFTOK_TYPE_TEX, @"(cuint(" ), _
205  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
206  ( FB_DEFTOK_TYPE_TEX, @") and &h000000FF)" ), _
207  ( -1 ) _
208  } _
209  ), _
210 /' #define HIBYTE(x) ((cuint(x) and &h0000FF00) shr 8) '/ _
211  ( _
212  @"HIBYTE", FB_RTL_OPT_NONE, _
213  1, _
214  { _
215  @"X" _
216  }, _
217  { _
218  ( FB_DEFTOK_TYPE_TEX, @"((cuint(" ), _
219  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
220  ( FB_DEFTOK_TYPE_TEX, @") and &h0000FF00) shr 8)" ), _
221  ( -1 ) _
222  } _
223  ), _
224 /' #define BIT(x,y) (((x) and (cast(typeof(x), 1) shl (y))) <> 0) '/ _
225  ( _
226  @"BIT", FB_RTL_OPT_NONE, _
227  2, _
228  { _
229  @"X", @"Y" _
230  }, _
231  { _
232  ( FB_DEFTOK_TYPE_TEX, @"(((" ), _
233  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
234  ( FB_DEFTOK_TYPE_TEX, @") and (cast(typeof(" ), _
235  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
236  ( FB_DEFTOK_TYPE_TEX, @"), 1) shl (" ), _
237  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
238  ( FB_DEFTOK_TYPE_TEX, @"))) <> 0)" ), _
239  ( -1 ) _
240  } _
241  ), _
242 /' #define BITSET(x,y) ((x) or (cast(typeof(x), 1) shl (y))) '/ _
243  ( _
244  @"BITSET", FB_RTL_OPT_NONE, _
245  2, _
246  { _
247  @"X", @"Y" _
248  }, _
249  { _
250  ( FB_DEFTOK_TYPE_TEX, @"((" ), _
251  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
252  ( FB_DEFTOK_TYPE_TEX, @") or (cast(typeof(" ), _
253  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
254  ( FB_DEFTOK_TYPE_TEX, @"), 1) shl (" ), _
255  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
256  ( FB_DEFTOK_TYPE_TEX, @")))" ), _
257  ( -1 ) _
258  } _
259  ), _
260 /' #define BITRESET(x,y) ((x) and not (cast(typeof(x), 1) shl (y))) '/ _
261  ( _
262  @"BITRESET", FB_RTL_OPT_NONE, _
263  2, _
264  { _
265  @"X", @"Y" _
266  }, _
267  { _
268  ( FB_DEFTOK_TYPE_TEX, @"((" ), _
269  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
270  ( FB_DEFTOK_TYPE_TEX, @") and not (cast(typeof(" ), _
271  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
272  ( FB_DEFTOK_TYPE_TEX, @"), 1) shl (" ), _
273  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
274  ( FB_DEFTOK_TYPE_TEX, @")))" ), _
275  ( -1 ) _
276  } _
277  ), _
278 /' EOL '/ _
279  ( _
280  NULL _
281  ) _
282  }
283 
284  '' These are the -lang qb versions of the built-in macros, using the
285  '' '__' prefixes where necessary.
286  dim shared as FB_RTL_MACRODEF macrodataQB(0 to 15) = _
287  { _
288 /' #define RGB(r,g,b) ((cuint(r) shl 16) or (cuint(g) shl 8) or cuint(b) or &hFF000000) '/ _
289  ( _
290  @"__RGB", FB_RTL_OPT_NONE, _
291  3, _
292  { _
293  @"R", @"G", @"B" _
294  }, _
295  { _
296  ( FB_DEFTOK_TYPE_TEX, @"((__cuint(" ), _
297  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
298  ( FB_DEFTOK_TYPE_TEX, @") __shl 16) or (__cuint(" ), _
299  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
300  ( FB_DEFTOK_TYPE_TEX, @") __shl 8) or __cuint(" ), _
301  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 2 ) ), _
302  ( FB_DEFTOK_TYPE_TEX, @") or &hFF000000)" ), _
303  ( -1 ) _
304  } _
305  ), _
306 /' #define RGBA(r,g,b,a) ((cuint(r) shl 16) or (cuint(g) shl 8) or cuint(b) or (cuint(a) shl 24)) '/ _
307  ( _
308  @"__RGBA", FB_RTL_OPT_NONE, _
309  4, _
310  { _
311  @"R", @"G", @"B", @"A" _
312  }, _
313  { _
314  ( FB_DEFTOK_TYPE_TEX, @"((__cuint(" ), _
315  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
316  ( FB_DEFTOK_TYPE_TEX, @") __shl 16) or (__cuint(" ), _
317  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
318  ( FB_DEFTOK_TYPE_TEX, @") __shl 8) or __cuint(" ), _
319  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 2 ) ), _
320  ( FB_DEFTOK_TYPE_TEX, @") or (__cuint(" ), _
321  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 3 ) ), _
322  ( FB_DEFTOK_TYPE_TEX, @") __shl 24))" ), _
323  ( -1 ) _
324  } _
325  ), _
326 /' #define va_arg(a,t) peek( t, a ) '/ _
327  ( _
328  @"__VA_ARG", FB_RTL_OPT_NOGCC, _
329  2, _
330  { _
331  @"A", @"T" _
332  }, _
333  { _
334  ( FB_DEFTOK_TYPE_TEX, @"peek(" ), _
335  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
336  ( FB_DEFTOK_TYPE_TEX, @"," ), _
337  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
338  ( FB_DEFTOK_TYPE_TEX, @")" ), _
339  ( -1 ) _
340  } _
341  ), _
342 /' #define va_next(a,t) (cptr(t ptr, cptr(byte ptr, a) + (sizeof(t)+sizeof(any ptr)-1 and -sizeof(any ptr)) ) ) '/ _
343  ( _
344  @"__VA_NEXT", FB_RTL_OPT_NOGCC, _
345  2, _
346  { _
347  @"A", @"T" _
348  }, _
349  { _
350  ( FB_DEFTOK_TYPE_TEX, @"(__cptr(" ), _
351  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
352  ( FB_DEFTOK_TYPE_TEX, @" __ptr, __cptr(__byte __ptr, " ), _
353  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
354  ( FB_DEFTOK_TYPE_TEX, @") + (__sizeof(" ), _
355  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
356  ( FB_DEFTOK_TYPE_TEX, @") + __sizeof(any __ptr)-1 and -__sizeof(any __ptr)) ) )" ), _
357  ( -1 ) _
358  } _
359  ), _
360 /' #define ASSERT(e) if (e) = FALSE then fb_Assert(__FILE__, __LINE__, __FUNCTION__, #e) '/ _
361  ( _
362  @"__ASSERT", FB_RTL_OPT_DBGONLY, _
363  1, _
364  { _
365  @"E" _
366  }, _
367  { _
368  ( FB_DEFTOK_TYPE_TEX, @"if (" ), _
369  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
370  ( FB_DEFTOK_TYPE_TEX, @") = 0 then fb_Assert(__FILE__, __LINE__, __FUNCTION__, " ), _
371  ( FB_DEFTOK_TYPE_PARAMSTR, cast( any ptr, 0 ) ), _
372  ( FB_DEFTOK_TYPE_TEX, @") end if" ), _
373  ( -1 ) _
374  } _
375  ), _
376 /' #define ASSERTWARN(e) if (e) = FALSE then fb_AssertWarn(__FILE__, __LINE__, __FUNCTION__, #e) '/ _
377  ( _
378  @"__ASSERTWARN", FB_RTL_OPT_DBGONLY, _
379  1, _
380  { _
381  @"E" _
382  }, _
383  { _
384  ( FB_DEFTOK_TYPE_TEX, @"if (" ), _
385  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
386  ( FB_DEFTOK_TYPE_TEX, @") = 0 then fb_AssertWarn(__FILE__, __LINE__, __FUNCTION__, " ), _
387  ( FB_DEFTOK_TYPE_PARAMSTR, cast( any ptr, 0 ) ), _
388  ( FB_DEFTOK_TYPE_TEX, @") end if" ), _
389  ( -1 ) _
390  } _
391  ), _
392 /' #define OFFSETOF(type_,field_) cint( @cast( type_ ptr, 0 )->field_ ) '/ _
393  ( _
394  @"__OFFSETOF", FB_RTL_OPT_NONE, _
395  2, _
396  { _
397  @"T", @"F" _
398  }, _
399  { _
400  ( FB_DEFTOK_TYPE_TEX, @"cint( @__cast( " ), _
401  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
402  ( FB_DEFTOK_TYPE_TEX, @" __ptr, 0 )->" ), _
403  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
404  ( FB_DEFTOK_TYPE_TEX, @" )" ), _
405  ( -1 ) _
406  } _
407  ), _
408 /' #define __FB_MIN_VERSION__(major, minor, patch_level) ((__FB_VER_MAJOR__ > (major)) or ((__FB_VER_MAJOR__ = (major)) and ((__FB_VER_MINOR__ > (minor)) or (__FB_VER_MINOR__ = (minor) and __FB_VER_PATCH__ >= (patch_level))))) '/ _
409  ( _
410  @"__FB_MIN_VERSION__", FB_RTL_OPT_NONE, _
411  3, _
412  { _
413  @"MAJOR", @"MINOR", @"PATCH_LEVEL" _
414  }, _
415  { _
416  ( FB_DEFTOK_TYPE_TEX, @"((__FB_VER_MAJOR__ > (" ), _
417  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
418  ( FB_DEFTOK_TYPE_TEX, @")) or ((__FB_VER_MAJOR__ = (" ), _
419  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
420  ( FB_DEFTOK_TYPE_TEX, @")) and ((__FB_VER_MINOR__ > (" ), _
421  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
422  ( FB_DEFTOK_TYPE_TEX, @")) or (__FB_VER_MINOR__ = (" ), _
423  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
424  ( FB_DEFTOK_TYPE_TEX, @") and __FB_VER_PATCH__ >= (" ), _
425  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 2 ) ), _
426  ( FB_DEFTOK_TYPE_TEX, @")))))" ), _
427  ( -1 ) _
428  } _
429  ), _
430 /' #define LOWORD(x) (cuint(x) and &h0000FFFF) '/ _
431  ( _
432  @"__LOWORD", FB_RTL_OPT_NONE, _
433  1, _
434  { _
435  @"X" _
436  }, _
437  { _
438  ( FB_DEFTOK_TYPE_TEX, @"(__cuint(" ), _
439  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
440  ( FB_DEFTOK_TYPE_TEX, @") and &h0000FFFF)" ), _
441  ( -1 ) _
442  } _
443  ), _
444 /' #define HIWORD(x) (cuint(x) shr 16) '/ _
445  ( _
446  @"__HIWORD", FB_RTL_OPT_NONE, _
447  1, _
448  { _
449  @"X" _
450  }, _
451  { _
452  ( FB_DEFTOK_TYPE_TEX, @"(__cuint(" ), _
453  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
454  ( FB_DEFTOK_TYPE_TEX, @") __shr 16)" ), _
455  ( -1 ) _
456  } _
457  ), _
458 /' #define LOBYTE(x) (cuint(x) and &h000000FF) '/ _
459  ( _
460  @"__LOBYTE", FB_RTL_OPT_NONE, _
461  1, _
462  { _
463  @"X" _
464  }, _
465  { _
466  ( FB_DEFTOK_TYPE_TEX, @"(__cuint(" ), _
467  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
468  ( FB_DEFTOK_TYPE_TEX, @") and &h000000FF)" ), _
469  ( -1 ) _
470  } _
471  ), _
472 /' #define HIBYTE(x) ((cuint(x) and &h0000FF00) shr 8) '/ _
473  ( _
474  @"__HIBYTE", FB_RTL_OPT_NONE, _
475  1, _
476  { _
477  @"X" _
478  }, _
479  { _
480  ( FB_DEFTOK_TYPE_TEX, @"((__cuint(" ), _
481  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
482  ( FB_DEFTOK_TYPE_TEX, @") and &h0000FF00) __shr 8)" ), _
483  ( -1 ) _
484  } _
485  ), _
486 /' #define BIT(x,y) (((x) and (cast(typeof(x), 1) shl (y))) <> 0) '/ _
487  ( _
488  @"__BIT", FB_RTL_OPT_NONE, _
489  2, _
490  { _
491  @"X", @"Y" _
492  }, _
493  { _
494  ( FB_DEFTOK_TYPE_TEX, @"(((" ), _
495  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
496  ( FB_DEFTOK_TYPE_TEX, @") and (__cast(__typeof(" ), _
497  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
498  ( FB_DEFTOK_TYPE_TEX, @"), 1) __shl (" ), _
499  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
500  ( FB_DEFTOK_TYPE_TEX, @"))) <> 0)" ), _
501  ( -1 ) _
502  } _
503  ), _
504 /' #define BITSET(x,y) ((x) or (cast(typeof(x), 1) shl (y))) '/ _
505  ( _
506  @"__BITSET", FB_RTL_OPT_NONE, _
507  2, _
508  { _
509  @"X", @"Y" _
510  }, _
511  { _
512  ( FB_DEFTOK_TYPE_TEX, @"((" ), _
513  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
514  ( FB_DEFTOK_TYPE_TEX, @") or (__cast(__typeof(" ), _
515  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
516  ( FB_DEFTOK_TYPE_TEX, @"), 1) __shl (" ), _
517  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
518  ( FB_DEFTOK_TYPE_TEX, @")))" ), _
519  ( -1 ) _
520  } _
521  ), _
522 /' #define BITRESET(x,y) ((x) and not (cast(typeof(x), 1) shl (y))) '/ _
523  ( _
524  @"__BITRESET", FB_RTL_OPT_NONE, _
525  2, _
526  { _
527  @"X", @"Y" _
528  }, _
529  { _
530  ( FB_DEFTOK_TYPE_TEX, @"((" ), _
531  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
532  ( FB_DEFTOK_TYPE_TEX, @") and not (__cast(__typeof(" ), _
533  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 0 ) ), _
534  ( FB_DEFTOK_TYPE_TEX, @"), 1) __shl (" ), _
535  ( FB_DEFTOK_TYPE_PARAM, cast( any ptr, 1 ) ), _
536  ( FB_DEFTOK_TYPE_TEX, @")))" ), _
537  ( -1 ) _
538  } _
539  ), _
540 /' EOL '/ _
541  ( _
542  NULL _
543  ) _
544  }
545 
546 sub addIntrinsicMacros(byval macdef as FB_RTL_MACRODEF ptr)
547  dim as FB_DEFPARAM ptr param_head = any, lastparam = any
548  dim as FB_DEFTOK ptr tok = any, tok_head = any
549  dim as FB_RTL_MACROTOKEN ptr ptk = any
550 
551  '' for each macro..
552  do
553  var flags = FB_DEFINE_FLAGS_NONE
554  if( macdef->name = NULL ) then
555  exit do
556  end if
557 
558  param_head = NULL
559  lastparam = NULL
560 
561  '' for each parameter..
562  for i as integer = 0 to macdef->params-1
563  lastparam = symbAddDefineParam( lastparam, macdef->paramTb(i) )
564  if( param_head = NULL ) then
565  param_head = lastparam
566  end if
567  next
568 
569  '' for each token..
570  tok_head = NULL
571 
572  dim as integer addbody = TRUE
573 
574  '' only if debugging?
575  if( (macdef->options and FB_RTL_OPT_DBGONLY) <> 0 ) then
576  if( env.clopt.debug = FALSE ) then
577  addbody = FALSE
578  end if
579  end if
580 
581  '' not supported by the C backend?
582  if( (macdef->options and FB_RTL_OPT_NOGCC) <> 0 ) then
583  if( env.clopt.backend = FB_BACKEND_GCC ) then
584  addbody = FALSE
585  flags or= FB_DEFINE_FLAGS_NOGCC
586  end if
587  end if
588 
589  if( addbody ) then
590  tok = NULL
591 
592  ptk = @macdef->tokenTb(0)
593  do
594  if( ptk->type = -1 ) then
595  exit do
596  end if
597 
598  tok = symbAddDefineTok( tok, ptk->type )
599  if( tok_head = NULL ) then
600  tok_head = tok
601  end if
602 
603  select case ptk->type
604  case FB_DEFTOK_TYPE_PARAM, FB_DEFTOK_TYPE_PARAMSTR
605  symbGetDefTokParamNum( tok ) = cint( ptk->data )
606 
607  case FB_DEFTOK_TYPE_TEX
608  ZstrAssign( @symbGetDefTokText( tok ), cast( zstring ptr, ptk->data ) )
609  end select
610 
611  '' next
612  ptk += 1
613  loop
614  end if
615 
616  symbAddDefineMacro( macdef->name, tok_head, macdef->params, param_head, flags )
617 
618  '' next
619  macdef += 1
620  loop
621 
622 end sub
623 
624 '':::::
626  if( fbLangIsSet( FB_LANG_QB ) ) then
628  else
630  end if
631 end sub
632 
633 '':::::
635 
636  '' macros will be deleted when symbEnd is called
637 
638 end sub
639