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