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