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