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