1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.15
4: Copyright (C) 1989-2013 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(object) declareObject(object)
60: #else
61: extern struct_rpl_arguments __static_rpl_arguments;
62: # define global extern
63: # define initialize(a, b) a;
64: # define declarePersistantObject(object) extern struct_objet *object;
65: #endif
66:
67: #define empty int
68:
69: /*
70: --------------------------------------------------------------------------------
71: Types
72: --------------------------------------------------------------------------------
73: */
74:
75: #define declareObject(object) struct_objet *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(object) \
223: __CATCH_SYSTEM_ERROR__; \
224: do { \
225: if (object == NULL) \
226: systemError("Nullified object"); \
227: liberation(object); \
228: object = NULL; \
229: } while(0)
230:
231: /*
232: --------------------------------------------------------------------------------
233: Copie d'un objet
234: --------------------------------------------------------------------------------
235: */
236:
237: #define dupObject(object) \
238: __CATCH_SYSTEM_ERROR__; \
239: do { if (copie_objet(object, 'P') != 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(object) do { \
512: __CATCH_SYSTEM_ERROR__; \
513: if (((*rpl_arguments).l_base_pile = \
514: empilement_pile_operationnelle(rpl_arguments, object)) == NULL) \
515: systemError("Memory allocation error"); \
516: if ((*object).nombre_occurrences == 1) object = NULL; } while(0)
517:
518: #define pullFromStack(object, ...) do { \
519: __CATCH_SYSTEM_ERROR__; \
520: (*rpl_arguments).l_base_pile = \
521: depilement_pile_operationnelle(rpl_arguments, &object); \
522: if (object == NULL) \
523: { \
524: executionError("Too few arguments"); \
525: } \
526: else \
527: { \
528: if (strlen(#__VA_ARGS__) == 0) \
529: { \
530: systemError("Undefined type"); \
531: } \
532: else \
533: { \
534: __type = 0; \
535: if (strstr(#__VA_ARGS__, "integer") != NULL) \
536: if ((*object).type == INT) __type = 1; \
537: if (strstr(#__VA_ARGS__, "real") != NULL) \
538: if ((*object).type == REL) __type = 1; \
539: if (strstr(#__VA_ARGS__, "complex") != NULL) \
540: if ((*object).type == CPL) __type = 1; \
541: if (strstr(#__VA_ARGS__, "string") != NULL) \
542: if ((*object).type == CHN) __type = 1; \
543: if (strstr(#__VA_ARGS__, "list") != NULL) \
544: if ((*object).type == LST) __type = 1; \
545: if (strstr(#__VA_ARGS__, "unknown") != NULL) \
546: __type = 1; \
547: if (__type == 0) \
548: { \
549: executionError("Type not allowed"); \
550: } \
551: } \
552: } } while(0)
553:
554: /*
555: --------------------------------------------------------------------------------
556: Gestion des objets
557: --------------------------------------------------------------------------------
558: */
559:
560: #define then {
561: #define endIf __CATCH_SYSTEM_ERROR__; }
562: #define elseIf __CATCH_SYSTEM_ERROR__; } else if
563: #define orElse __CATCH_SYSTEM_ERROR__; } else {
564:
565: // Constantes symboliques
566:
567: #define createSymbolicConstant(object, type, value) do { \
568: if ((strcmp(#type, "integer") != 0) && (strcmp(#type, "real") != 0)) \
569: systemError("Type not allowed for symbolic constant"); \
570: __taille_bloc = sizeof(t_8_bits) * 8; \
571: __indice_bloc = (35 - 1) / __taille_bloc; \
572: __indice_bit = (35 - 1) % __taille_bloc; \
573: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
574: if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
575: { \
576: createNameObject(object); \
577: __CATCH_SYSTEM_ERROR__; \
578: { \
579: char *__constant_name; \
580: if ((__constant_name = malloc((strlen(__library_name) + \
581: strlen(__function_name) - 9) * sizeof(char))) == NULL) \
582: systemError("Memory allocation error"); \
583: sprintf(__constant_name, "%s$%s", __library_name, \
584: &(__function_name[11])); \
585: setName(object, __constant_name); \
586: free(__constant_name); \
587: } \
588: } \
589: else \
590: { \
591: if (strcmp(#type, "integer") == 0) \
592: { \
593: createIntegerObject(object); \
594: __CATCH_SYSTEM_ERROR__; \
595: setInteger(object, value); \
596: } \
597: else if (strcmp(#type, "real") == 0) \
598: { \
599: createRealObject(object); \
600: __CATCH_SYSTEM_ERROR__; \
601: setReal(object, value); \
602: } \
603: } \
604: __CATCH_SYSTEM_ERROR__; \
605: __constante--; } while(0)
606:
607: #define createSymbolicComplexConstant(object, rp, ip) do { \
608: __taille_bloc = sizeof(t_8_bits) * 8; \
609: __indice_bloc = (35 - 1) / __taille_bloc; \
610: __indice_bit = (35 - 1) % __taille_bloc; \
611: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
612: if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
613: { \
614: createNameObject(object); \
615: __CATCH_SYSTEM_ERROR__; \
616: { \
617: char *__constant_name; \
618: if ((__constant_name = malloc((strlen(__library_name) + \
619: strlen(__function_name) + 2) * sizeof(char))) == NULL) \
620: systemError("Memory allocation error"); \
621: sprintf(__constant_name, "%s$%s", __library_name, \
622: __function_name); \
623: setName(object, __constant_name); \
624: free(__constant_name); \
625: } \
626: } \
627: else \
628: { \
629: createComplexObject(object); \
630: __CATCH_SYSTEM_ERROR__; \
631: setComplex(object, rp, im); \
632: } \
633: __CATCH_SYSTEM_ERROR__; \
634: __constante--; } while(0)
635:
636: // Integer
637:
638: #define setInteger(object, value) do { \
639: ifIsInteger(object) \
640: { \
641: if ((*object).nombre_occurrences > 1) \
642: { \
643: struct_objet *__tmp_object; \
644: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
645: systemError("Memory allocation error"); \
646: liberation(object); \
647: object = __tmp_object; \
648: } \
649: (*((integer8 *) (*object).objet)) = (integer8) value; \
650: } \
651: else executionError("Type mistmatch error"); } while(0)
652:
653: #define isInteger(object) \
654: ((*object).type == INT)
655:
656: #define ifIsInteger(object) if (isInteger(object))
657: #define elseIfIsInteger(object) } else ifIsInteger(object)
658:
659: #define getInteger(object, value) do { \
660: value = 0; \
661: ifIsInteger(object) value = (*((integer8 *) (*object).objet)); \
662: else executionError("Type mismatch error"); } while(0)
663:
664: #define createIntegerObject(object) do { \
665: if (object != NULL) \
666: systemError("Reallocated object"); \
667: if ((object = allocation(INT)) == NULL) \
668: systemError("Memory allocation error"); \
669: setInteger(object, 0); } while(0)
670:
671: // Real
672:
673: #define setReal(object, value) do { \
674: ifIsReal(object) \
675: { \
676: if ((*object).nombre_occurrences > 1) \
677: { \
678: struct_objet *__tmp_object; \
679: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
680: systemError("Memory allocation error"); \
681: liberation(object); \
682: object = __tmp_object; \
683: } \
684: (*((real8 *) (*object).objet)) = (real8) value; \
685: } \
686: else executionError("Type mistmatch error"); } while(0)
687:
688: #define isReal(object) \
689: ((*object).type == REL)
690:
691: #define ifIsReal(object) if (isReal(object))
692: #define elseIfIsReal(object) } else ifIsReal(object)
693:
694: #define getReal(object, value) do { \
695: value = 0; \
696: ifIsReal(object) value = (*((real8 *) (*object).objet)); \
697: else executionError("Type mismatch error"); } while(0)
698:
699: #define createRealObject(object) do { \
700: if (object != NULL) \
701: systemError("Reallocated object"); \
702: if ((object = allocation(REL)) == NULL) \
703: systemError("Memory allocation error"); \
704: setReal(object, 0); } while(0)
705:
706: // Complex
707:
708: #define setComplex(object, rp, ip) do { \
709: typeof(rp) __rp = rp; \
710: typeof(ip) __ip = ip; \
711: ifIsComplex(object) \
712: { \
713: if ((*object).nombre_occurrences > 1) \
714: { \
715: struct_objet *__tmp_object; \
716: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
717: systemError("Memory allocation error"); \
718: liberation(object); \
719: object = __tmp_object; \
720: } \
721: setRealPartOfComplex(object, __rp); \
722: setImaginaryPartOfComplex(object, __ip); \
723: } \
724: else executionError("Type mismatch error"); } while(0)
725:
726: #define setRealPartOfComplex(object, value) do { \
727: if ((*object).nombre_occurrences > 1) \
728: { \
729: struct_objet *__tmp_object; \
730: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
731: systemError("Memory allocation error"); \
732: liberation(object); \
733: object = __tmp_object; \
734: } \
735: ifIsComplex(object) (*((complex16 *) (*object).objet)).partie_reelle = \
736: value; \
737: else executionError("Type mismatch error"); } while(0)
738:
739: #define setImaginaryPartOfComplex(object, value) do { \
740: if ((*object).nombre_occurrences > 1) \
741: { \
742: struct_objet *__tmp_object; \
743: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
744: systemError("Memory allocation error"); \
745: liberation(object); \
746: object = __tmp_object; \
747: } \
748: (*((complex16 *) (*object).objet)).partie_imaginaire = value; \
749: else executionError("Type mismatch error"); } while(0)
750:
751: #define getRealPartOfComplex(object, value) \
752: value = (*((complex16 *) (*object).objet)).partie_reelle
753:
754: #define getImaginaryPartOfComplex(object, value) \
755: value = (*((complex16 *) (*object).objet)).partie_imaginaire
756:
757: #define isComplex(object) \
758: ((*object).type == CPL)
759:
760: #define ifIsComplex(object) if (isComplex(object))
761: #define elseIfIsComplex(object) } else ifIsComplex(object)
762:
763: #define getComplex(object, value) do { \
764: value.partie_reelle = 0; \
765: value.partie_imaginaire = 0; \
766: ifIsComplex(object) value = (*((complex16 *) (*object).objet)); \
767: else systemError("Not a complex"); } while(0)
768:
769: #define createComplexObject(object) do { \
770: if (object != NULL) \
771: systemError("Reallocated object"); \
772: if ((object = allocation(CPL)) == NULL) \
773: systemError("Memory allocation error"); \
774: setComplex(object, 0, 0); } while(0)
775:
776: // Generalized vectors
777:
778: #define createVectorObject(object, size, otype, structure, cat) do { \
779: integer8 i; \
780: if (object != NULL) \
781: systemError("Reallocated object"); \
782: if ((object = allocation(cat)) == NULL) \
783: systemError("Memory allocation error"); \
784: (*((structure *) (*object).objet)).taille = size; \
785: if (((*((structure *) (*object).objet)).tableau = \
786: malloc(size * sizeof(otype))) == NULL) \
787: systemError("Memory allocation error"); \
788: if (cat != VCX) \
789: { \
790: if (cat == VIN) \
791: (*((structure *) (*object).objet)).type = 'I'; \
792: else \
793: (*((structure *) (*object).objet)).type = 'R'; \
794: for(i = 0; i < size; ((otype *) (*((structure *) (*object).objet)) \
795: .tableau)[i++] = (otype) 0); \
796: } \
797: else \
798: { \
799: (*((structure *) (*object).objet)).type = 'C'; \
800: for(i = 0; i < size; i++) \
801: { \
802: ((complex16 *) (*((structure *) (*object).objet)).tableau)[i] \
803: .partie_reelle = 0; \
804: ((complex16 *) (*((structure *) (*object).objet)).tableau)[i] \
805: .partie_imaginaire = 0; \
806: } \
807: } } while(0)
808:
809: // Integer vector
810:
811: #define setIntegerIntoVector(object, value, position) do { \
812: typeof(position) __position = position; \
813: ifIsIntegerVector(object) \
814: { \
815: if ((*object).nombre_occurrences > 1) \
816: { \
817: struct_objet *__tmp_object; \
818: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
819: systemError("Memory allocation error"); \
820: liberation(object); \
821: object = __tmp_object; \
822: } \
823: __position--; \
824: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
825: (*object).objet)).taille)) \
826: { executionError("Element out of range"); } \
827: else \
828: ((integer8 *) (*((struct_vecteur *) (*object).objet)).tableau) \
829: [__position] = (integer8) value; \
830: } \
831: else executionError("Type mistmatch error"); } while(0)
832:
833: #define isIntegerVector(object) \
834: ((*object).type == VIN)
835:
836: #define ifIsIntegerVector(object) if (isIntegerVector(object))
837: #define elseIfIsIntegerVector(object) } else ifIsIntegerVector(object)
838:
839: #define getIntegerFromVector(object, value, position) do { \
840: typeof(position) __position = position; \
841: value = 0; \
842: ifIsIntegerVector(object) \
843: { \
844: __position--; \
845: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
846: (*object).objet)).taille)) \
847: executionError("Element out of range"); \
848: else \
849: value = ((integer8 *) (*((struct_vecteur *) (*object).objet)) \
850: .tableau)[__position]; \
851: } \
852: else executionError("Type mismatch error"); } while(0)
853:
854: #define createIntegerVectorObject(object, size) \
855: createVectorObject(object, size, integer8, struct_vecteur, VIN)
856:
857: // Real vector
858:
859: #define setRealIntoVector(object, value, position) do { \
860: typeof(position) __position = position; \
861: ifIsRealVector(object) \
862: { \
863: if ((*object).nombre_occurrences > 1) \
864: { \
865: struct_objet *__tmp_object; \
866: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
867: systemError("Memory allocation error"); \
868: liberation(object); \
869: object = __tmp_object; \
870: } \
871: __position--; \
872: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
873: (*object).objet)).taille)) \
874: { executionError("Element out of range"); } \
875: else \
876: ((real8 *) (*((struct_vecteur *) (*object).objet)).tableau) \
877: [__position] = (real8) value; \
878: } \
879: else executionError("Type mistmatch error"); } while(0)
880:
881: #define isRealVector(object) \
882: ((*object).type == VRL)
883:
884: #define ifIsRealVector(object) if (isRealVector(object))
885: #define elseIfIsRealVector(object) } else ifIsRealVector(object)
886:
887: #define getRealFromVector(object, value, position) do { \
888: typeof(position) __position = position; \
889: value = 0; \
890: ifIsRealVector(object) \
891: { \
892: __position--; \
893: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
894: (*object).objet)).taille)) \
895: executionError("Element out of range"); \
896: value = ((real8 *) (*((struct_vecteur *) (*object).objet)).tableau) \
897: [__position]; \
898: } \
899: else executionError("Type mismatch error"); } while(0)
900:
901: #define createRealVectorObject(object, size) \
902: createVectorObject(object, size, real8, struct_vecteur, VRL)
903:
904: // A FIXER
905:
906: #define createComplexVectorObject
907:
908: #define createIntegerMatrixObject
909:
910: #define createRealMatrixObject
911:
912: #define createComplexMatrixObject
913:
914: // Binary integer
915:
916: #define setBinaryInteger(object, value) do { \
917: ifIsBinaryInteger(object) \
918: { \
919: if ((*object).nombre_occurrences > 1) \
920: { \
921: struct_objet *__tmp_object; \
922: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
923: systemError("Memory allocation error"); \
924: liberation(object); \
925: object = __tmp_object; \
926: } \
927: (*((integer8 *) (*object).objet)) = (integer8) value; \
928: } \
929: else executionError("Type mistmatch error"); } while(0)
930:
931: #define isBinaryInteger(object) \
932: ((*object).type == BIN)
933:
934: #define ifIsBinaryInteger(object) if (isBinaryInteger(object))
935: #define elseIfIsBinaryInteger(object) } else ifIsBinaryInteger(object)
936:
937: #define getBinaryInteger(object, value) do { \
938: value = 0; \
939: ifIsBinaryInteger(object) value = (*((integer8 *) (*object).objet)); \
940: else executionError("Type mismatch error"); } while(0)
941:
942: #define createBinaryIntegerObject(object) do { \
943: if (object != NULL) \
944: systemError("Reallocated object"); \
945: if ((object = allocation(BIN)) == NULL) \
946: systemError("Memory allocation error"); \
947: setBinaryInteger(object, 0); } while(0)
948:
949: // Name
950:
951: #define isName(object) \
952: ((*object).type == NOM)
953:
954: #define ifIsName(object) if (isName(object))
955: #define elseIfIsName(object) } else if (isName(object))
956:
957: #define setName(object, value) do { \
958: ifIsName(object) \
959: { \
960: if ((*object).nombre_occurrences > 1) \
961: { \
962: struct_objet *__tmp_object; \
963: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
964: systemError("Memory allocation error"); \
965: liberation(object); \
966: object = __tmp_object; \
967: } \
968: free((*((struct_nom *) (*object).objet)).nom); \
969: (*((struct_nom *) (*object).objet)).symbole = d_faux; \
970: if (((*((struct_nom *) (*object).objet)).nom = malloc( \
971: (strlen(value) + 1) * sizeof(unsigned char))) == NULL) \
972: systemError("Memory allocation error"); \
973: strcpy((char *) (*((struct_nom *) (*object).objet)).nom, \
974: (char *) value); \
975: } \
976: else executionError("Type mistmatch error"); } while(0)
977:
978: #define createNameObject(object) do { \
979: if (object != NULL) \
980: systemError("Reallocated object"); \
981: if ((object = allocation(NOM)) == NULL) \
982: systemError("Memory allocation error"); \
983: (*((struct_nom *) (*object).objet)).symbole = d_faux; \
984: if (((*((struct_nom *) (*object).objet)).nom = malloc( \
985: sizeof(unsigned char))) == NULL) \
986: systemError("Memory allocation error"); \
987: strcpy((char *) (*((struct_nom *) (*object).objet)).nom, ""); } while(0)
988:
989: // String
990:
991: #define isString(object) \
992: ((*object).type == CHN)
993:
994: #define ifIsString(object) if (isString(object))
995: #define elseIfIsString(object) else if (isString(objet))
996:
997: #define setString(object, string) do { \
998: ifIsString(object) \
999: { \
1000: if (string == NULL) executionError("Nullified string"); else \
1001: { \
1002: if ((*object).nombre_occurrences > 1) \
1003: { \
1004: struct_objet *__tmp_object; \
1005: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
1006: systemError("Memory allocation error"); \
1007: liberation(object); \
1008: object = __tmp_object; \
1009: } \
1010: free((unsigned char *) (*object).objet); \
1011: if (((*object).objet = malloc((strlen(string) + 1) * \
1012: sizeof(unsigned char))) == NULL) \
1013: systemError("Memory allocation error"); \
1014: strcpy((char *) (*object).objet, string); \
1015: } \
1016: } \
1017: else executionError("Type mistmatch error"); } while(0)
1018:
1019: #define getString(object, string) do { \
1020: string = NULL; \
1021: ifIsString(object) string = (char *) (*object).objet; \
1022: else executionError("Type mismatch error"); } while(0)
1023:
1024: #define createStringObject(object) do { \
1025: if (object != NULL) \
1026: systemError("Reallocated object"); \
1027: if ((object = allocation(CHN)) == NULL) \
1028: systemError("Memory allocation error"); \
1029: if (((*object).objet = malloc(sizeof(unsigned char))) == NULL) \
1030: systemError("Memory allocation error"); \
1031: strcpy((char *) (*object).objet, ""); } while(0)
1032:
1033: // List
1034:
1035: #define isList(object) \
1036: ((*object).type == LST)
1037:
1038: #define ifIsList(object) if (isList(object))
1039: #define elseIfIsList(object) else if (isList(object))
1040:
1041: #define createListObject(object) do { \
1042: if (object != NULL) \
1043: systemError("Reallocated object"); \
1044: if ((object = allocation(LST)) == NULL) \
1045: systemError("Memory allocation error"); \
1046: (*object).objet = NULL; } while(0)
1047:
1048: #define addObjectToList(list, object) do { \
1049: ifIsList(list) \
1050: { \
1051: struct_objet *__tmp_object; \
1052: if ((__tmp_object = copie_objet(list, 'N')) == NULL) \
1053: systemError("Memory allocation error"); \
1054: liberation(list); \
1055: list = __tmp_object; \
1056: if ((*list).objet == NULL) \
1057: { \
1058: if (((*list).objet = malloc(sizeof(struct_liste_chainee))) \
1059: == NULL) \
1060: systemError("Memory allocation error"); \
1061: (*((struct_liste_chainee *) (*list).objet)).suivant = NULL; \
1062: (*((struct_liste_chainee *) (*list).objet)).donnee = object; \
1063: } \
1064: else \
1065: { \
1066: struct_liste_chainee *l_element_courant; \
1067: l_element_courant = (*list).objet; \
1068: while((*l_element_courant).suivant != NULL) \
1069: l_element_courant = (*l_element_courant).suivant; \
1070: if (((*l_element_courant).suivant = \
1071: malloc(sizeof(struct_liste_chainee))) == NULL) \
1072: systemError("Memory allocation error"); \
1073: l_element_courant = (*l_element_courant).suivant; \
1074: (*l_element_courant).suivant = NULL; \
1075: (*l_element_courant).donnee = object; \
1076: } \
1077: object = NULL; \
1078: } \
1079: else executionError("Type mistmatch error"); } while(0)
1080:
1081: #define insertObjectIntoList(list, object) do { \
1082: ifIsList(list) \
1083: { \
1084: struct_objet *__tmp_object; \
1085: if ((__tmp_object = copie_objet(list, 'N')) == NULL) \
1086: systemError("Memory allocation error"); \
1087: liberation(list); \
1088: list = __tmp_object; \
1089: if ((*list).objet == NULL) \
1090: { \
1091: if (((*list).objet = malloc(sizeof(struct_liste_chainee))) \
1092: == NULL) \
1093: systemError("Memory allocation error"); \
1094: (*((struct_liste_chainee *) (*list).objet)).suivant = NULL; \
1095: (*((struct_liste_chainee *) (*list).objet)).donnee = object; \
1096: } \
1097: else \
1098: { \
1099: struct_liste_chainee *l_element_courant; \
1100: if ((l_element_courant = \
1101: malloc(sizeof(struct_liste_chainee))) == NULL) \
1102: systemError("Memory allocation error"); \
1103: (*l_element_courant).donnee = object; \
1104: (*l_element_courant).suivant = (*list).objet; \
1105: (*list).objet = l_element_courant; \
1106: } \
1107: object = NULL; \
1108: } \
1109: else executionError("Type mistmatch error"); } while(0)
1110:
1111: #define removeObjectFromList(list, object) do { \
1112: ifIsList(list) \
1113: { \
1114: if ((*list).objet != NULL) \
1115: { \
1116: struct_liste_chainee *__current; \
1117: struct_liste_chainee *__previous; \
1118: __current = (*list).objet; \
1119: __previous = NULL; \
1120: if ((*__current).donnee == object) \
1121: { \
1122: (*list).objet = (*__current).suivant; \
1123: } \
1124: else \
1125: { \
1126: while(__current != NULL) \
1127: { \
1128: if ((*__current).donnee == object) \
1129: { \
1130: (*__previous).suivant = (*__current).suivant; \
1131: break; \
1132: } \
1133: __previous = __current; \
1134: __current = (*__current).suivant; \
1135: } \
1136: } \
1137: liberation((*__current).donnee); \
1138: free(__current); \
1139: } \
1140: } \
1141: else executionError("Type mistmatch error"); } while(0)
1142:
1143: #define getObjectFromList(list, position, object)
1144:
1145: #define putObjectIntoList(list, position, object)
1146:
1147: #define getListFromList(list, position1, position2, object)
1148:
1149: #define listLength(list, length) do { \
1150: if (list == NULL) executionError("Nullified object"); \
1151: if ((*list).type != LST) \
1152: executionError("Type mistmatch error"); \
1153: { \
1154: struct_liste_chainee *l_element_courant; \
1155: length = 0; \
1156: l_element_courant = (*list).objet; \
1157: while(l_element_courant != NULL) \
1158: { \
1159: l_element_courant = (*l_element_courant).suivant; \
1160: length++; \
1161: } \
1162: } } while(0)
1163:
1164: /*
1165: --------------------------------------------------------------------------------
1166: Allocation mémoire
1167: --------------------------------------------------------------------------------
1168: */
1169:
1170: #define size(a) sizeof(a)
1171:
1172: #define allocate(a) ({ void *ptr; \
1173: if ((ptr = malloc(a)) == NULL) \
1174: systemError("Memory allocation error"); ptr; })
1175:
1176: #define deallocate(a) free(a)
1177:
1178: /*
1179: --------------------------------------------------------------------------------
1180: Récupération des interruptions et des signaux
1181: --------------------------------------------------------------------------------
1182: */
1183:
1184: #define pollSignalsAndInterrupts() \
1185: __CATCH_SYSTEM_ERROR__; \
1186: do { scrutation_injection((*rpl_arguments).s_etat_processus); } while(0)
1187:
1188: /*
1189: --------------------------------------------------------------------------------
1190: Exécution d'une fonction intrinsèque
1191: --------------------------------------------------------------------------------
1192: */
1193:
1194: #define intrinsic(function) do { \
1195: int __status; \
1196: __CATCH_SYSTEM_ERROR__; \
1197: __status = wrapper_instruction_intrinseque( \
1198: instruction_##function, rpl_arguments); \
1199: if (__status == 1) executionError(#function); \
1200: if (__status == 2) systemError(#function); \
1201: } while(0)
1202:
1203: #endif
1204:
1205: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>