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