1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.22
4: Copyright (C) 1989-2015 Dr. BERTRAND Joël
5:
6: This file is part of RPL/2.
7:
8: RPL/2 is free software; you can redistribute it and/or modify it
9: under the terms of the CeCILL V2 License as published by the french
10: CEA, CNRS and INRIA.
11:
12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
15: for more details.
16:
17: You should have received a copy of the CeCILL License
18: along with RPL/2. If not, write to info@cecill.info.
19: ================================================================================
20: */
21:
22:
23: #ifndef INCLUSION_RPLARGS
24: # define INCLUSION_RPLARGS
25:
26: /*
27: ================================================================================
28: INCLUSIONS
29: ================================================================================
30: */
31:
32: # define RPLARGS
33: # define struct_processus void
34: # include "rpl.h"
35:
36: /*
37: ================================================================================
38: MACROS SPECIFIQUES
39: ================================================================================
40: */
41:
42: #define __RPL__ struct_rpl_arguments *rpl_arguments; \
43: rpl_arguments = &__static_rpl_arguments;
44:
45: #define __CATCH_SYSTEM_ERROR__ \
46: do { if (((*rpl_arguments).erreur != 0) && \
47: ((*rpl_arguments).type_erreur == 'S')) \
48: return 0; } while(0)
49: #define leave do { return(0); } while(0)
50: #define allocation(a) librpl_allocation((*rpl_arguments).s_etat_processus, a)
51: #define copie_objet(a, b) librpl_copie_objet( \
52: (*rpl_arguments).s_etat_processus, a, b)
53: #define liberation(a) librpl_liberation((*rpl_arguments).s_etat_processus, a)
54:
55: #ifdef __RPLC_MAIN
56: struct_rpl_arguments __static_rpl_arguments;
57: # define global
58: # define initialize(a, b) a = b
59: # define declarePersistantObject(rpl_object) declareObject(rpl_object)
60: #else
61: extern struct_rpl_arguments __static_rpl_arguments;
62: # define global extern
63: # define initialize(a, b) a;
64: # define declarePersistantObject(rpl_object) extern struct_objet *rpl_object
65: #endif
66:
67: #define empty int
68:
69: /*
70: --------------------------------------------------------------------------------
71: Types
72: --------------------------------------------------------------------------------
73: */
74:
75: #define declareObject(rpl_object) struct_objet *rpl_object = NULL
76: #define declareInteger(integer) integer8 integer
77: #define declareReal(real) real8 real
78: #define declareComplex(complex) complex16 complex
79: #define declareDaisyChain(daisyChain) struct_liste_chainee *daisyChain = NULL
80:
81: #define getDaisyChainFromList(list, daisyChain) \
82: __CATCH_SYSTEM_ERROR__; \
83: do { \
84: typeof(list) __list = list; \
85: daisyChain = NULL; \
86: ifIsList(__list) { daisyChain = (*__list).objet; } \
87: else executionError("Type mistmatch error"); } while(0)
88:
89: #define fetchElementFromDaisyChain(daisyChain) \
90: ({ __CATCH_SYSTEM_ERROR__; typeof(daisyChain) __daisyChain = daisyChain; \
91: if (__daisyChain == NULL) executionError("End of daisy chain"); \
92: (__daisyChain == NULL) ? NULL : (*__daisyChain).donnee; })
93:
94: #define replaceElementIntoDaisyChain(daisyChain, element) \
95: __CATCH_SYSTEM_ERROR__; \
96: do { typeof(daisyChain) __daisyChain = daisyChain; \
97: if (__daisyChain == NULL) executionError("Nullified daisy chain"); \
98: freeObject((*__daisyChain).donnee); \
99: (*__daisyChain).donnee = element; } while(0)
100:
101: #define nextElementOfDaisyChain(daisyChain) \
102: ({ __CATCH_SYSTEM_ERROR__; typeof(daisyChain) __daisyChain = daisyChain; \
103: if (__daisyChain == NULL) executionError("End of daisy chain"); \
104: (__daisyChain == NULL) ? NULL : (*__daisyChain).suivant; })
105:
106: #define null NULL
107: #define nullify(ptr) __CATCH_SYSTEM_ERROR__; do { ptr = NULL; } while(0)
108: #define nullified(ptr) ((ptr) == NULL)
109:
110: #define postIncr(x) (x++)
111: #define preIncr(x) (++x)
112: #define postDecr(x) (x--)
113: #define preDecr(x) (--x)
114:
115: #define eq ==
116: #define ne !=
117: #define ge >=
118: #define gt >
119: #define le <=
120: #define lt <
121: #define not !
122: #define and &&
123: #define or ||
124: #define false 0
125: #define true -1
126:
127: #define setFalse(a) a = false
128: #define setTrue(a) a = true
129:
130: #define logical int
131: #define string char *
132: #define integer int
133: #define object struct_objet *
134:
135: #define declareStructure typedef struct {
136: #define declareUnion typedef union {
137: #define as(name) } name;
138:
139: #define target(a) (*a)
140: #define address(a) (&a)
141:
142: #define beginGroup { __CATCH_SYSTEM_ERROR__;
143: #define endGroup __CATCH_SYSTEM_ERROR__; }
144: #define beginMacro do beginGroup
145: #define endMacro endGroup while(0)
146: #define stopRequest ({ __CATCH_SYSTEM_ERROR__; \
147: test_arret((*rpl_arguments).s_etat_processus); })
148:
149: /*
150: --------------------------------------------------------------------------------
151: Signaux
152: --------------------------------------------------------------------------------*/
153:
154: #define blockSignals \
155: { __CATCH_SYSTEM_ERROR__; sigset_t set, oldset; sigfillset(&set); \
156: pthread_sigmask(SIG_BLOCK, &set, &oldset);
157: #define unblockSignals \
158: pthread_sigmask(SIG_SETMASK, &oldset, NULL); __CATCH_SYSTEM_ERROR__; }
159:
160: /*
161: --------------------------------------------------------------------------------
162: Constructeurs
163: --------------------------------------------------------------------------------
164: */
165:
166: #define DISABLE_SET_BUT_NOT_USED_WARNING(a) if (&a != ((&a) + 1));
167:
168: #define HEADER \
169: int __constante; \
170: logical1 __evaluation; \
171: logical1 __validation_instruction = d_faux; \
172: logical1 __presence_aide = d_faux; \
173: logical1 __presence_validation = d_faux; \
174: unsigned char __indice_bit; \
175: unsigned char __indice_bloc; \
176: unsigned char __taille_bloc; \
177: unsigned char __type; \
178: t_8_bits __masque; \
179: { \
180: (*rpl_arguments).instruction_valide = 'Y'; \
181: (*rpl_arguments).erreur = 0; \
182: __constante = 0; \
183: __evaluation = d_faux; \
184: DISABLE_SET_BUT_NOT_USED_WARNING(__evaluation); \
185: DISABLE_SET_BUT_NOT_USED_WARNING(__type); \
186: DISABLE_SET_BUT_NOT_USED_WARNING(__indice_bit); \
187: DISABLE_SET_BUT_NOT_USED_WARNING(__indice_bloc); \
188: DISABLE_SET_BUT_NOT_USED_WARNING(__taille_bloc); \
189: DISABLE_SET_BUT_NOT_USED_WARNING(__masque);
190:
191: #define FUNCTION \
192: if (__validation_instruction == d_vrai) return 0; \
193: if (__presence_aide == d_faux) \
194: { \
195: systemError("Help string not defined"); \
196: } \
197: else if (__presence_validation == d_faux) \
198: { \
199: systemError("Number of arguments not defined"); \
200: } \
201: __indice_bit = 0; \
202: __indice_bloc = 0; \
203: __taille_bloc = 0; \
204: __type = 0; \
205: __masque = 0; \
206: {
207:
208: #define END \
209: strcpy((char *) __function_name, ""); \
210: if (__constante != 0) \
211: systemError("Constant definition error"); \
212: __CATCH_SYSTEM_ERROR__; \
213: } } \
214: leave;
215:
216: /*
217: --------------------------------------------------------------------------------
218: Destruction d'un objet
219: --------------------------------------------------------------------------------
220: */
221:
222: #define freeObject(rpl_object) \
223: __CATCH_SYSTEM_ERROR__; \
224: do { \
225: if (rpl_object == NULL) \
226: systemError("Nullified object"); \
227: liberation(rpl_object); \
228: rpl_object = NULL; \
229: } while(0)
230:
231: /*
232: --------------------------------------------------------------------------------
233: Copie d'un objet
234: --------------------------------------------------------------------------------
235: */
236:
237: #define dupObject(rpl_object) \
238: __CATCH_SYSTEM_ERROR__; \
239: do { if (copie_objet(rpl_object, 'P') != rpl_object) \
240: systemError("Memory allocation error"); } while(0)
241:
242: /*
243: --------------------------------------------------------------------------------
244: Déclaration des fonctions internes
245: --------------------------------------------------------------------------------
246: */
247:
248: #define CONCAT(a, b) __CONCAT(a, b)
249: #define __CONCAT(a, b) a##b
250: #define FIRST(...) FIRST_HELPER(__VA_ARGS__, throwaway)
251: #define FIRST_HELPER(first, ...) first
252: #define REST(...) REST_HELPER(NUM(__VA_ARGS__), __VA_ARGS__)
253: #define REST_HELPER(qty, ...) REST_HELPER2(qty, __VA_ARGS__)
254: #define REST_HELPER2(qty, ...) REST_HELPER_##qty(__VA_ARGS__)
255: #define REST_HELPER_ONE(first)
256: #define REST_HELPER_TWOORMORE(first, ...) , __VA_ARGS__
257: #define NUM(...) \
258: SELECT_10TH(__VA_ARGS__, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE,\
259: TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, ONE, throwaway)
260: #define SELECT_10TH(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, ...) a10
261:
262: #define declareInternalFunction(type, ...) \
263: type CONCAT(__internal_, FIRST(__VA_ARGS__)) \
264: (struct_rpl_arguments *rpl_arguments REST(__VA_ARGS__)) { \
265: type __internal_return; __internal_return = 0; int __type; \
266: DISABLE_SET_BUT_NOT_USED_WARNING(__type);
267:
268: #define endInternalFunction return(__internal_return); }
269:
270: #define useInternalFunction(type, ...) \
271: type CONCAT(__internal_, FIRST(__VA_ARGS__)) \
272: (struct_rpl_arguments *rpl_arguments REST(__VA_ARGS__))
273:
274: #define callInternalFunction(...) \
275: CONCAT(__internal_, FIRST(__VA_ARGS__))(rpl_arguments REST(__VA_ARGS__))
276:
277: /*
278: --------------------------------------------------------------------------------
279: Déclaration des fonctions C
280: --------------------------------------------------------------------------------
281: */
282:
283: #define declareCFunction(type, name, ...) \
284: type name(__VA_ARGS__) { __RPL__ type __c_return;
285: #define endCFunction return(__c_return); }
286:
287: #define useCFunction(type, name, ...) type name(__VA_ARGS__)
288:
289: /*
290: --------------------------------------------------------------------------------
291: Déclaration des fonctions externes
292: --------------------------------------------------------------------------------
293: */
294:
295: #define declareExternalFunction(name) \
296: int __external_##name(struct_rpl_arguments *rpl_arguments) { \
297: char __function_name[] = "__external_"#name; \
298: __static_rpl_arguments = (*rpl_arguments);
299:
300: #define useExternalFunction(function) \
301: int __external_##function(struct_rpl_arguments *rpl_arguments)
302:
303: #define libraryName(name) char __library_name[] = #name;
304:
305: #define __onLoading int __runOnLoading(struct_rpl_arguments *rpl_arguments)
306: #define __onClosing int __runOnClosing(struct_rpl_arguments *rpl_arguments)
307: #define declareSubroutine(when) __##when { \
308: char __function_name[] = #when; \
309: __static_rpl_arguments = (*rpl_arguments); \
310: HEADER \
311: declareHelpString(""); \
312: numberOfArguments(0); \
313: FUNCTION
314: #define endSubroutine END }
315:
316: #define notice(s, ...) __CATCH_SYSTEM_ERROR__; \
317: do { ufprintf(s, __VA_ARGS__); fflush(s); } while(0)
318: #define logger(...) __CATCH_SYSTEM_ERROR__; \
319: do { syslog(LOG_NOTICE, __VA_ARGS__); } while(0)
320:
321: #define exportExternalFunctions(...) \
322: char **__external_symbols(struct_rpl_arguments *rpl_arguments, \
323: integer8 *nb_symbols, \
324: const char *version) { \
325: char arguments[] = #__VA_ARGS__; \
326: char **tableau; \
327: char *ptr1, *ptr2; \
328: int drapeau; \
329: unsigned long i; \
330: if (strcmp(version, _d_version_rpl) != 0) \
331: { \
332: notice(stdout, "Versions mismatch : library %s, expected %s\n", \
333: _d_version_rpl, version); \
334: (*nb_symbols) = -1; return(NULL); \
335: } \
336: (*nb_symbols) = 0; ptr1 = arguments; drapeau = 0; \
337: while((*ptr1) != 0) \
338: { \
339: if (((*ptr1) != ',') && ((*ptr1) != ' ')) drapeau = -1; \
340: ptr1++; \
341: } \
342: if (drapeau == 0) return(NULL); \
343: ptr1 = arguments; (*nb_symbols) = 1; \
344: while((*ptr1) != 0) if ((*ptr1++) == ',') (*nb_symbols)++; \
345: if ((tableau = malloc((*nb_symbols) * sizeof(char *))) == NULL) \
346: return(NULL); \
347: ptr2 = arguments; i = 0; \
348: while(*ptr2 != 0) \
349: { \
350: while(((*ptr2) == ' ') || ((*ptr2) == ',')) ptr2++; \
351: ptr1 = ptr2; \
352: while(((*ptr2) != 0) && ((*ptr2) != ',') && ((*ptr2) != ' ')) \
353: ptr2++; \
354: if ((tableau[i] = malloc((ptr2 + 2 + \
355: strlen(__library_name) - ptr1) * \
356: sizeof(unsigned char))) == NULL) \
357: return(NULL); \
358: sprintf(tableau[i], "%s$", __library_name); \
359: strncat(&tableau[i][strlen(tableau[i])], ptr1, ptr2 - ptr1); \
360: i++; \
361: if ((*ptr2) != 0) \
362: { \
363: while((*ptr2) == ' ') ptr2++; \
364: if ((*ptr2) == ',') ptr2++; \
365: } \
366: } \
367: (*nb_symbols) = i; \
368: return(tableau); \
369: }
370:
371: #define endExternalFunction leave; }
372:
373: #define callExternalFunction(function) do { \
374: __CATCH_SYSTEM_ERROR__; \
375: __taille_bloc = sizeof(t_8_bits) * 8; \
376: __indice_bloc = (35 - 1) / __taille_bloc; \
377: __indice_bit = (35 - 1) % __taille_bloc; \
378: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
379: __evaluation = ((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) \
380: ? d_vrai : d_faux; \
381: __masque = ~(((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1)); \
382: (*rpl_arguments).drapeaux_etat[__indice_bloc] &= __masque; \
383: __external_##function(rpl_arguments); \
384: if (__evaluation == d_vrai) \
385: { \
386: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
387: (*rpl_arguments).drapeaux_etat[__indice_bloc] |= __masque; \
388: } \
389: else \
390: { \
391: __masque = ~(((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1)); \
392: (*rpl_arguments).drapeaux_etat[__indice_bloc] &= __masque; \
393: } } while(0)
394:
395: /*
396: --------------------------------------------------------------------------------
397: Macros spécifiques à l'en-tête
398: --------------------------------------------------------------------------------
399: */
400:
401: #define declareHelpString(h) do { \
402: __presence_aide = d_vrai; \
403: if ((*rpl_arguments).affichage_arguments == 'Y') \
404: { \
405: uprintf("%s\n", h); \
406: return 0; \
407: } } while(0)
408:
409: #define declareSymbolicConstant do { \
410: numberOfArguments(0); \
411: (*rpl_arguments).constante_symbolique = 'Y'; \
412: __constante++; } while(0)
413:
414: #define numberOfArguments(n) do { \
415: __presence_validation = d_vrai; \
416: if ((*rpl_arguments).test_instruction == 'Y') \
417: { \
418: if (n < 0) \
419: systemError("Number of arguments must be positive or null"); \
420: (*rpl_arguments).nombre_arguments = n; \
421: __validation_instruction = d_vrai; \
422: } \
423: else \
424: { \
425: __taille_bloc = sizeof(t_8_bits) * 8; \
426: __indice_bloc = (31 - 1) / __taille_bloc; \
427: __indice_bit = (31 - 1) % __taille_bloc; \
428: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
429: if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
430: { \
431: (*rpl_arguments).l_base_pile_last = \
432: sauvegarde_arguments(rpl_arguments, n); \
433: } \
434: } } while(0)
435:
436: /*
437: --------------------------------------------------------------------------------
438: Gestion des boucles
439: --------------------------------------------------------------------------------
440: */
441:
442: #define loop(b, e, s) for(b; e; s) {
443: #define endLoop __CATCH_SYSTEM_ERROR__; }
444:
445: #define repeatWhile(c) while(c) {
446: #define endWhile __CATCH_SYSTEM_ERROR__; }
447:
448: #define doUntil do {
449: #define repeatUntil(c) __CATCH_SYSTEM_ERROR__; } while(!(c));
450:
451: #define select(s) switch(s) {
452: #define endSelect __CATCH_SYSTEM_ERROR__; }
453: #define nonExclusiveCase(c) case c: {
454: #define endNonExclusiveCase __CATCH_SYSTEM_ERROR__; }
455: #define exclusiveCase(c) case c: {
456: #define endExclusiveCase break; __CATCH_SYSTEM_ERROR__; }
457: #define defaultCase default:
458: #define endDefaultCase break; __CATCH_SYSTEM_ERROR__; }
459:
460: /*
461: --------------------------------------------------------------------------------
462: Gestion des erreurs
463: --------------------------------------------------------------------------------
464: */
465:
466: #define returnOnError(...) do { \
467: if ((*rpl_arguments).erreur != 0) \
468: { \
469: __VA_ARGS__; \
470: return 0; \
471: } } while(0)
472:
473: #define systemError(message) do { \
474: (*rpl_arguments).erreur = __LINE__; \
475: (*rpl_arguments).type_erreur = 'S'; \
476: (*rpl_arguments).message_erreur = (unsigned char *) message; \
477: return 0; } while(0)
478:
479: #define executionError(message) do { \
480: (*rpl_arguments).erreur = __LINE__; \
481: (*rpl_arguments).type_erreur = 'E'; \
482: (*rpl_arguments).message_erreur = (unsigned char *) message; } while(0)
483:
484: #define onSystemError(...) do { \
485: if (((*rpl_arguments).erreur != 0) && \
486: ((*rpl_arguments).type_erreur == 'S')) \
487: { \
488: blockSignals; \
489: kill(getpid(), SIGTERM); \
490: unblockSignals; \
491: __VA_ARGS__; \
492: } } while(0)
493:
494: #define onError(...) \
495: __CATCH_SYSTEM_ERROR__; \
496: do { if (((*rpl_arguments).type_erreur == 'E') && \
497: ((*rpl_arguments).erreur != 0)) { __VA_ARGS__; \
498: (*rpl_arguments).erreur = 0; } } while(0)
499:
500: #define onExecution(...) \
501: __CATCH_SYSTEM_ERROR__; \
502: do { if (((*rpl_arguments).type_erreur == 'E') && \
503: ((*rpl_arguments).erreur == 0)) { __VA_ARGS__; } } while(0)
504:
505: /*
506: --------------------------------------------------------------------------------
507: Gestion de la pile opérationnelle
508: --------------------------------------------------------------------------------
509: */
510:
511: #define pushOnStack(rpl_object) do { \
512: __CATCH_SYSTEM_ERROR__; \
513: if (((*rpl_arguments).l_base_pile = \
514: empilement_pile_operationnelle(rpl_arguments, rpl_object)) \
515: == NULL) \
516: systemError("Memory allocation error"); \
517: if ((*rpl_object).nombre_occurrences == 1) rpl_object = NULL; } while(0)
518:
519: #define pullFromStack(rpl_object, ...) do { \
520: __CATCH_SYSTEM_ERROR__; \
521: (*rpl_arguments).l_base_pile = \
522: depilement_pile_operationnelle(rpl_arguments, &rpl_object); \
523: if (rpl_object == NULL) \
524: { \
525: executionError("Too few arguments"); \
526: } \
527: else \
528: { \
529: if (strlen(#__VA_ARGS__) == 0) \
530: { \
531: systemError("Undefined type"); \
532: } \
533: else \
534: { \
535: __type = 0; \
536: if (strstr(#__VA_ARGS__, "integer") != NULL) \
537: if ((*rpl_object).type == INT) __type = 1; \
538: if (strstr(#__VA_ARGS__, "real") != NULL) \
539: if ((*rpl_object).type == REL) __type = 1; \
540: if (strstr(#__VA_ARGS__, "complex") != NULL) \
541: if ((*rpl_object).type == CPL) __type = 1; \
542: if (strstr(#__VA_ARGS__, "string") != NULL) \
543: if ((*rpl_object).type == CHN) __type = 1; \
544: if (strstr(#__VA_ARGS__, "list") != NULL) \
545: if ((*rpl_object).type == LST) __type = 1; \
546: if (strstr(#__VA_ARGS__, "unknown") != NULL) \
547: __type = 1; \
548: if (__type == 0) \
549: { \
550: executionError("Type not allowed"); \
551: } \
552: } \
553: } } while(0)
554:
555: /*
556: --------------------------------------------------------------------------------
557: Gestion des objets
558: --------------------------------------------------------------------------------
559: */
560:
561: #define then {
562: #define endIf __CATCH_SYSTEM_ERROR__; }
563: #define elseIf __CATCH_SYSTEM_ERROR__; } else if
564: #define orElse __CATCH_SYSTEM_ERROR__; } else {
565:
566: // Constantes symboliques
567:
568: #define createSymbolicConstant(rpl_object, type, value) do { \
569: if ((strcmp(#type, "integer") != 0) && (strcmp(#type, "real") != 0)) \
570: systemError("Type not allowed for symbolic constant"); \
571: __taille_bloc = sizeof(t_8_bits) * 8; \
572: __indice_bloc = (35 - 1) / __taille_bloc; \
573: __indice_bit = (35 - 1) % __taille_bloc; \
574: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
575: if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
576: { \
577: createNameObject(rpl_object); \
578: __CATCH_SYSTEM_ERROR__; \
579: { \
580: char *__constant_name; \
581: if ((__constant_name = malloc((strlen(__library_name) + \
582: strlen(__function_name) - 9) * sizeof(char))) == NULL) \
583: systemError("Memory allocation error"); \
584: sprintf(__constant_name, "%s$%s", __library_name, \
585: &(__function_name[11])); \
586: setName(rpl_object, __constant_name); \
587: free(__constant_name); \
588: } \
589: } \
590: else \
591: { \
592: if (strcmp(#type, "integer") == 0) \
593: { \
594: createIntegerObject(rpl_object); \
595: __CATCH_SYSTEM_ERROR__; \
596: setInteger(rpl_object, value); \
597: } \
598: else if (strcmp(#type, "real") == 0) \
599: { \
600: createRealObject(rpl_object); \
601: __CATCH_SYSTEM_ERROR__; \
602: setReal(rpl_object, value); \
603: } \
604: } \
605: __CATCH_SYSTEM_ERROR__; \
606: __constante--; } while(0)
607:
608: #define createSymbolicComplexConstant(rpl_object, rp, ip) do { \
609: __taille_bloc = sizeof(t_8_bits) * 8; \
610: __indice_bloc = (35 - 1) / __taille_bloc; \
611: __indice_bit = (35 - 1) % __taille_bloc; \
612: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
613: if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
614: { \
615: createNameObject(rpl_object); \
616: __CATCH_SYSTEM_ERROR__; \
617: { \
618: char *__constant_name; \
619: if ((__constant_name = malloc((strlen(__library_name) + \
620: strlen(__function_name) + 2) * sizeof(char))) == NULL) \
621: systemError("Memory allocation error"); \
622: sprintf(__constant_name, "%s$%s", __library_name, \
623: __function_name); \
624: setName(rpl_object, __constant_name); \
625: free(__constant_name); \
626: } \
627: } \
628: else \
629: { \
630: createComplexObject(rpl_object); \
631: __CATCH_SYSTEM_ERROR__; \
632: setComplex(rpl_object, rp, im); \
633: } \
634: __CATCH_SYSTEM_ERROR__; \
635: __constante--; } while(0)
636:
637: // Integer
638:
639: #define setInteger(rpl_object, value) do { \
640: ifIsInteger(rpl_object) \
641: { \
642: if ((*rpl_object).nombre_occurrences > 1) \
643: { \
644: struct_objet *__tmp_rpl_object; \
645: if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \
646: systemError("Memory allocation error"); \
647: liberation(rpl_object); \
648: rpl_object = __tmp_rpl_object; \
649: } \
650: (*((integer8 *) (*rpl_object).objet)) = (integer8) value; \
651: } \
652: else executionError("Type mistmatch error"); } while(0)
653:
654: #define isInteger(rpl_object) \
655: ((*rpl_object).type == INT)
656:
657: #define ifIsInteger(rpl_object) if (isInteger(rpl_object))
658: #define elseIfIsInteger(rpl_object) } else ifIsInteger(rpl_object)
659:
660: #define getInteger(rpl_object, value) do { \
661: value = 0; \
662: ifIsInteger(rpl_object) value = (*((integer8 *) (*rpl_object).objet)); \
663: else executionError("Type mismatch error"); } while(0)
664:
665: #define createIntegerObject(rpl_object) do { \
666: if (rpl_object != NULL) \
667: systemError("Reallocated object"); \
668: if ((rpl_object = allocation(INT)) == NULL) \
669: systemError("Memory allocation error"); \
670: setInteger(rpl_object, 0); } while(0)
671:
672: // Real
673:
674: #define setReal(rpl_object, value) do { \
675: ifIsReal(rpl_object) \
676: { \
677: if ((*rpl_object).nombre_occurrences > 1) \
678: { \
679: struct_objet *__tmp_rpl_object; \
680: if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \
681: systemError("Memory allocation error"); \
682: liberation(rpl_object); \
683: rpl_object = __tmp_rpl_object; \
684: } \
685: (*((real8 *) (*rpl_object).objet)) = (real8) value; \
686: } \
687: else executionError("Type mistmatch error"); } while(0)
688:
689: #define isReal(rpl_object) \
690: ((*rpl_object).type == REL)
691:
692: #define ifIsReal(rpl_object) if (isReal(rpl_object))
693: #define elseIfIsReal(rpl_object) } else ifIsReal(rpl_object)
694:
695: #define getReal(rpl_object, value) do { \
696: value = 0; \
697: ifIsReal(rpl_object) value = (*((real8 *) (*rpl_object).objet)); \
698: else executionError("Type mismatch error"); } while(0)
699:
700: #define createRealObject(rpl_object) do { \
701: if (rpl_object != NULL) \
702: systemError("Reallocated object"); \
703: if ((rpl_object = allocation(REL)) == NULL) \
704: systemError("Memory allocation error"); \
705: setReal(rpl_object, 0); } while(0)
706:
707: // Complex
708:
709: #define setComplex(rpl_object, rp, ip) do { \
710: typeof(rp) __rp = rp; \
711: typeof(ip) __ip = ip; \
712: ifIsComplex(rpl_object) \
713: { \
714: if ((*rpl_object).nombre_occurrences > 1) \
715: { \
716: struct_objet *__tmp_rpl_object; \
717: if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \
718: systemError("Memory allocation error"); \
719: liberation(rpl_object); \
720: rpl_object = __tmp_rpl_object; \
721: } \
722: setRealPartOfComplex(rpl_object, __rp); \
723: setImaginaryPartOfComplex(rpl_object, __ip); \
724: } \
725: else executionError("Type mismatch error"); } while(0)
726:
727: #define setRealPartOfComplex(rpl_object, value) do { \
728: if ((*rpl_object).nombre_occurrences > 1) \
729: { \
730: struct_objet *__tmp_rpl_object; \
731: if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \
732: systemError("Memory allocation error"); \
733: liberation(rpl_object); \
734: rpl_object = __tmp_rpl_object; \
735: } \
736: ifIsComplex(rpl_object) (*((complex16 *) (*rpl_object).objet)) \
737: .partie_reelle = value; \
738: else executionError("Type mismatch error"); } while(0)
739:
740: #define setImaginaryPartOfComplex(rpl_object, value) do { \
741: if ((*rpl_object).nombre_occurrences > 1) \
742: { \
743: struct_objet *__tmp_rpl_object; \
744: if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \
745: systemError("Memory allocation error"); \
746: liberation(rpl_object); \
747: rpl_object = __tmp_rpl_object; \
748: } \
749: (*((complex16 *) (*rpl_object).objet)).partie_imaginaire = value; \
750: else executionError("Type mismatch error"); } while(0)
751:
752: #define getRealPartOfComplex(rpl_object, value) \
753: value = (*((complex16 *) (*rpl_object).objet)).partie_reelle
754:
755: #define getImaginaryPartOfComplex(rpl_object, value) \
756: value = (*((complex16 *) (*rpl_object).objet)).partie_imaginaire
757:
758: #define isComplex(rpl_object) \
759: ((*rpl_object).type == CPL)
760:
761: #define ifIsComplex(rpl_object) if (isComplex(rpl_object))
762: #define elseIfIsComplex(rpl_object) } else ifIsComplex(rpl_object)
763:
764: #define getComplex(rpl_object, value) do { \
765: value.partie_reelle = 0; \
766: value.partie_imaginaire = 0; \
767: ifIsComplex(rpl_object) value = (*((complex16 *) (*rpl_object).objet)); \
768: else systemError("Not a complex"); } while(0)
769:
770: #define createComplexObject(rpl_object) do { \
771: if (rpl_object != NULL) \
772: systemError("Reallocated object"); \
773: if ((rpl_object = allocation(CPL)) == NULL) \
774: systemError("Memory allocation error"); \
775: setComplex(rpl_object, 0, 0); } while(0)
776:
777: // Generalized vectors
778:
779: #define createVectorObject(rpl_object, size, otype, structure, cat) do { \
780: integer8 i; \
781: if (rpl_object != NULL) \
782: systemError("Reallocated object"); \
783: if ((rpl_object = allocation(cat)) == NULL) \
784: systemError("Memory allocation error"); \
785: (*((structure *) (*rpl_object).objet)).taille = size; \
786: if (((*((structure *) (*rpl_object).objet)).tableau = \
787: malloc(size * sizeof(otype))) == NULL) \
788: systemError("Memory allocation error"); \
789: if (cat != VCX) \
790: { \
791: if (cat == VIN) \
792: (*((structure *) (*rpl_object).objet)).type = 'I'; \
793: else \
794: (*((structure *) (*rpl_object).objet)).type = 'R'; \
795: for(i = 0; i < size; ((otype *) (*((structure *) (*rpl_object).objet)) \
796: .tableau)[i++] = (otype) 0); \
797: } \
798: else \
799: { \
800: (*((structure *) (*rpl_object).objet)).type = 'C'; \
801: for(i = 0; i < size; i++) \
802: { \
803: ((complex16 *) (*((structure *) (*rpl_object).objet)).tableau)[i] \
804: .partie_reelle = 0; \
805: ((complex16 *) (*((structure *) (*rpl_object).objet)).tableau)[i] \
806: .partie_imaginaire = 0; \
807: } \
808: } } while(0)
809:
810: // Integer vector
811:
812: #define setIntegerIntoVector(rpl_object, value, position) do { \
813: typeof(position) __position = position; \
814: ifIsIntegerVector(rpl_object) \
815: { \
816: if ((*rpl_object).nombre_occurrences > 1) \
817: { \
818: struct_objet *__tmp_rpl_object; \
819: if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \
820: systemError("Memory allocation error"); \
821: liberation(rpl_object); \
822: rpl_object = __tmp_rpl_object; \
823: } \
824: __position--; \
825: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
826: (*rpl_object).objet)).taille)) \
827: { executionError("Element out of range"); } \
828: else \
829: ((integer8 *) (*((struct_vecteur *) (*rpl_object).objet)).tableau) \
830: [__position] = (integer8) value; \
831: } \
832: else executionError("Type mistmatch error"); } while(0)
833:
834: #define isIntegerVector(rpl_object) \
835: ((*rpl_object).type == VIN)
836:
837: #define ifIsIntegerVector(rpl_object) if (isIntegerVector(rpl_object))
838: #define elseIfIsIntegerVector(rpl_object) } else ifIsIntegerVector(rpl_object)
839:
840: #define getIntegerFromVector(rpl_object, value, position) do { \
841: typeof(position) __position = position; \
842: value = 0; \
843: ifIsIntegerVector(rpl_object) \
844: { \
845: __position--; \
846: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
847: (*rpl_object).objet)).taille)) \
848: executionError("Element out of range"); \
849: else \
850: value = ((integer8 *) (*((struct_vecteur *) (*rpl_object).objet)) \
851: .tableau)[__position]; \
852: } \
853: else executionError("Type mismatch error"); } while(0)
854:
855: #define createIntegerVectorObject(rpl_object, size) \
856: createVectorObject(rpl_object, size, integer8, struct_vecteur, VIN)
857:
858: // Real vector
859:
860: #define setRealIntoVector(rpl_object, value, position) do { \
861: typeof(position) __position = position; \
862: ifIsRealVector(rpl_object) \
863: { \
864: if ((*rpl_object).nombre_occurrences > 1) \
865: { \
866: struct_objet *__tmp_rpl_object; \
867: if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \
868: systemError("Memory allocation error"); \
869: liberation(rpl_object); \
870: rpl_object = __tmp_rpl_object; \
871: } \
872: __position--; \
873: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
874: (*rpl_object).objet)).taille)) \
875: { executionError("Element out of range"); } \
876: else \
877: ((real8 *) (*((struct_vecteur *) (*rpl_object).objet)).tableau) \
878: [__position] = (real8) value; \
879: } \
880: else executionError("Type mistmatch error"); } while(0)
881:
882: #define isRealVector(rpl_object) \
883: ((*rpl_object).type == VRL)
884:
885: #define ifIsRealVector(rpl_object) if (isRealVector(rpl_object))
886: #define elseIfIsRealVector(rpl_object) } else ifIsRealVector(rpl_object)
887:
888: #define getRealFromVector(rpl_object, value, position) do { \
889: typeof(position) __position = position; \
890: value = 0; \
891: ifIsRealVector(rpl_object) \
892: { \
893: __position--; \
894: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
895: (*rpl_object).objet)).taille)) \
896: executionError("Element out of range"); \
897: value = ((real8 *) (*((struct_vecteur *) (*rpl_object).objet)) \
898: .tableau)[__position]; \
899: } \
900: else executionError("Type mismatch error"); } while(0)
901:
902: #define createRealVectorObject(rpl_object, size) \
903: createVectorObject(object, size, real8, struct_vecteur, VRL)
904:
905: // A FIXER
906:
907: #define createComplexVectorObject
908:
909: #define createIntegerMatrixObject
910:
911: #define createRealMatrixObject
912:
913: #define createComplexMatrixObject
914:
915: // Binary integer
916:
917: #define setBinaryInteger(rpl_object, value) do { \
918: ifIsBinaryInteger(rpl_object) \
919: { \
920: if ((*rpl_object).nombre_occurrences > 1) \
921: { \
922: struct_objet *__tmp_rpl_object; \
923: if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \
924: systemError("Memory allocation error"); \
925: liberation(rpl_object); \
926: rpl_object = __tmp_rpl_object; \
927: } \
928: (*((integer8 *) (*rpl_object).objet)) = (integer8) value; \
929: } \
930: else executionError("Type mistmatch error"); } while(0)
931:
932: #define isBinaryInteger(rpl_object) \
933: ((*rpl_object).type == BIN)
934:
935: #define ifIsBinaryInteger(rpl_object) if (isBinaryInteger(rpl_object))
936: #define elseIfIsBinaryInteger(rpl_object) } else ifIsBinaryInteger(rpl_object)
937:
938: #define getBinaryInteger(rpl_object, value) do { \
939: value = 0; \
940: ifIsBinaryInteger(rpl_object) value = \
941: (*((integer8 *) (*rpl_object).objet)); \
942: else executionError("Type mismatch error"); } while(0)
943:
944: #define createBinaryIntegerObject(rpl_object) do { \
945: if (rpl_object != NULL) \
946: systemError("Reallocated object"); \
947: if ((rpl_object = allocation(BIN)) == NULL) \
948: systemError("Memory allocation error"); \
949: setBinaryInteger(rpl_object, 0); } while(0)
950:
951: // Name
952:
953: #define isName(rpl_object) \
954: ((*rpl_object).type == NOM)
955:
956: #define ifIsName(rpl_object) if (isName(rpl_object))
957: #define elseIfIsName(rpl_object) } else if (isName(rpl_object))
958:
959: #define setName(rpl_object, value) do { \
960: ifIsName(rpl_object) \
961: { \
962: if ((*rpl_object).nombre_occurrences > 1) \
963: { \
964: struct_objet *__tmp_rpl_object; \
965: if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \
966: systemError("Memory allocation error"); \
967: liberation(rpl_object); \
968: rpl_object = __tmp_rpl_object; \
969: } \
970: free((*((struct_nom *) (*rpl_object).objet)).nom); \
971: (*((struct_nom *) (*rpl_object).objet)).symbole = d_faux; \
972: if (((*((struct_nom *) (*rpl_object).objet)).nom = malloc( \
973: (strlen(value) + 1) * sizeof(unsigned char))) == NULL) \
974: systemError("Memory allocation error"); \
975: strcpy((char *) (*((struct_nom *) (*rpl_object).objet)).nom, \
976: (char *) value); \
977: } \
978: else executionError("Type mistmatch error"); } while(0)
979:
980: #define setSymbolicName(rpl_object, value) do { \
981: setName(rpl_object, value); \
982: (*((struct_nom *) (*rpl_object).objet)).symbole = d_vrai; } while(0)
983:
984: #define createNameObject(rpl_object) do { \
985: if (rpl_object != NULL) \
986: systemError("Reallocated object"); \
987: if ((rpl_object = allocation(NOM)) == NULL) \
988: systemError("Memory allocation error"); \
989: (*((struct_nom *) (*rpl_object).objet)).symbole = d_faux; \
990: if (((*((struct_nom *) (*rpl_object).objet)).nom = malloc( \
991: sizeof(unsigned char))) == NULL) \
992: systemError("Memory allocation error"); \
993: strcpy((char *) (*((struct_nom *) (*rpl_object).objet)).nom, ""); } while(0)
994:
995: // String
996:
997: #define isString(rpl_object) \
998: ((*rpl_object).type == CHN)
999:
1000: #define ifIsString(rpl_object) if (isString(rpl_object))
1001: #define elseIfIsString(rpl_object) else if (isString(rpl_object))
1002:
1003: #define setString(rpl_object, string) do { \
1004: ifIsString(rpl_object) \
1005: { \
1006: if (string == NULL) executionError("Nullified string"); else \
1007: { \
1008: if ((*rpl_object).nombre_occurrences > 1) \
1009: { \
1010: struct_objet *__tmp_rpl_object; \
1011: if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \
1012: systemError("Memory allocation error"); \
1013: liberation(rpl_object); \
1014: rpl_object = __tmp_rpl_object; \
1015: } \
1016: free((unsigned char *) (*rpl_object).objet); \
1017: if (((*rpl_object).objet = malloc((strlen(string) + 1) * \
1018: sizeof(unsigned char))) == NULL) \
1019: systemError("Memory allocation error"); \
1020: strcpy((char *) (*rpl_object).objet, string); \
1021: } \
1022: } \
1023: else executionError("Type mistmatch error"); } while(0)
1024:
1025: #define getString(rpl_object, string) do { \
1026: string = NULL; \
1027: ifIsString(rpl_object) string = (char *) (*rpl_object).objet; \
1028: else executionError("Type mismatch error"); } while(0)
1029:
1030: #define createStringObject(rpl_object) do { \
1031: if (rpl_object != NULL) \
1032: systemError("Reallocated object"); \
1033: if ((rpl_object = allocation(CHN)) == NULL) \
1034: systemError("Memory allocation error"); \
1035: if (((*rpl_object).objet = malloc(sizeof(unsigned char))) == NULL) \
1036: systemError("Memory allocation error"); \
1037: strcpy((char *) (*rpl_object).objet, ""); } while(0)
1038:
1039: // List
1040:
1041: #define isList(rpl_object) \
1042: ((*rpl_object).type == LST)
1043:
1044: #define ifIsList(rpl_object) if (isList(rpl_object))
1045: #define elseIfIsList(rpl_object) else if (isList(rpl_object))
1046:
1047: #define createListObject(rpl_object) do { \
1048: if (rpl_object != NULL) \
1049: systemError("Reallocated object"); \
1050: if ((rpl_object = allocation(LST)) == NULL) \
1051: systemError("Memory allocation error"); \
1052: (*rpl_object).objet = NULL; } while(0)
1053:
1054: #define addObjectToList(list, rpl_object) do { \
1055: ifIsList(list) \
1056: { \
1057: struct_objet *__tmp_rpl_object; \
1058: if ((__tmp_rpl_object = copie_objet(list, 'N')) == NULL) \
1059: systemError("Memory allocation error"); \
1060: liberation(list); \
1061: list = __tmp_rpl_object; \
1062: if ((*list).objet == NULL) \
1063: { \
1064: if (((*list).objet = malloc(sizeof(struct_liste_chainee))) \
1065: == NULL) \
1066: systemError("Memory allocation error"); \
1067: (*((struct_liste_chainee *) (*list).objet)).suivant = NULL; \
1068: (*((struct_liste_chainee *) (*list).objet)).donnee = rpl_object; \
1069: } \
1070: else \
1071: { \
1072: struct_liste_chainee *l_element_courant; \
1073: l_element_courant = (*list).objet; \
1074: while((*l_element_courant).suivant != NULL) \
1075: l_element_courant = (*l_element_courant).suivant; \
1076: if (((*l_element_courant).suivant = \
1077: malloc(sizeof(struct_liste_chainee))) == NULL) \
1078: systemError("Memory allocation error"); \
1079: l_element_courant = (*l_element_courant).suivant; \
1080: (*l_element_courant).suivant = NULL; \
1081: (*l_element_courant).donnee = rpl_object; \
1082: } \
1083: rpl_object = NULL; \
1084: } \
1085: else executionError("Type mistmatch error"); } while(0)
1086:
1087: #define insertObjectIntoList(list, rpl_object) do { \
1088: ifIsList(list) \
1089: { \
1090: struct_objet *__tmp_rpl_object; \
1091: if ((__tmp_rpl_object = copie_objet(list, 'N')) == NULL) \
1092: systemError("Memory allocation error"); \
1093: liberation(list); \
1094: list = __tmp_rpl_object; \
1095: if ((*list).objet == NULL) \
1096: { \
1097: if (((*list).objet = malloc(sizeof(struct_liste_chainee))) \
1098: == NULL) \
1099: systemError("Memory allocation error"); \
1100: (*((struct_liste_chainee *) (*list).objet)).suivant = NULL; \
1101: (*((struct_liste_chainee *) (*list).objet)).donnee = rpl_object; \
1102: } \
1103: else \
1104: { \
1105: struct_liste_chainee *l_element_courant; \
1106: if ((l_element_courant = \
1107: malloc(sizeof(struct_liste_chainee))) == NULL) \
1108: systemError("Memory allocation error"); \
1109: (*l_element_courant).donnee = rpl_object; \
1110: (*l_element_courant).suivant = (*list).objet; \
1111: (*list).objet = l_element_courant; \
1112: } \
1113: rpl_object = NULL; \
1114: } \
1115: else executionError("Type mistmatch error"); } while(0)
1116:
1117: #define removeObjectFromList(list, rpl_object) do { \
1118: ifIsList(list) \
1119: { \
1120: if ((*list).objet != NULL) \
1121: { \
1122: struct_liste_chainee *__current; \
1123: struct_liste_chainee *__previous; \
1124: __current = (*list).objet; \
1125: __previous = NULL; \
1126: if ((*__current).donnee == rpl_object) \
1127: { \
1128: (*list).objet = (*__current).suivant; \
1129: } \
1130: else \
1131: { \
1132: while(__current != NULL) \
1133: { \
1134: if ((*__current).donnee == rpl_object) \
1135: { \
1136: (*__previous).suivant = (*__current).suivant; \
1137: break; \
1138: } \
1139: __previous = __current; \
1140: __current = (*__current).suivant; \
1141: } \
1142: } \
1143: liberation((*__current).donnee); \
1144: free(__current); \
1145: } \
1146: } \
1147: else executionError("Type mistmatch error"); } while(0)
1148:
1149: #define getObjectFromList(list, position, rpl_object)
1150:
1151: #define putObjectIntoList(list, position, rpl_object)
1152:
1153: #define getListFromList(list, position1, position2, rpl_object)
1154:
1155: #define listLength(list, length) do { \
1156: if (list == NULL) executionError("Nullified object"); \
1157: if ((*list).type != LST) \
1158: executionError("Type mistmatch error"); \
1159: { \
1160: struct_liste_chainee *l_element_courant; \
1161: length = 0; \
1162: l_element_courant = (*list).objet; \
1163: while(l_element_courant != NULL) \
1164: { \
1165: l_element_courant = (*l_element_courant).suivant; \
1166: length++; \
1167: } \
1168: } } while(0)
1169:
1170: /*
1171: --------------------------------------------------------------------------------
1172: Allocation mémoire
1173: --------------------------------------------------------------------------------
1174: */
1175:
1176: #define size(a) sizeof(a)
1177:
1178: #define allocate(a) ({ void *ptr; \
1179: if ((ptr = malloc(a)) == NULL) \
1180: systemError("Memory allocation error"); ptr; })
1181:
1182: #define deallocate(a) free(a)
1183:
1184: /*
1185: --------------------------------------------------------------------------------
1186: Récupération des interruptions et des signaux
1187: --------------------------------------------------------------------------------
1188: */
1189:
1190: #define pollSignalsAndInterrupts() \
1191: __CATCH_SYSTEM_ERROR__; \
1192: do { scrutation_injection((*rpl_arguments).s_etat_processus); } while(0)
1193:
1194: /*
1195: --------------------------------------------------------------------------------
1196: Exécution d'une fonction intrinsèque
1197: --------------------------------------------------------------------------------
1198: */
1199:
1200: #define intrinsic(function) do { \
1201: int __status; \
1202: __CATCH_SYSTEM_ERROR__; \
1203: __status = wrapper_instruction_intrinseque( \
1204: instruction_##function, rpl_arguments); \
1205: if (__status == 1) executionError(#function); \
1206: if (__status == 2) systemError(#function); \
1207: } while(0)
1208:
1209: #endif
1210:
1211: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>