--- rpl/src/rplexternals.h 2012/01/05 10:19:06 1.33 +++ rpl/src/rplexternals.h 2023/11/27 08:48:46 1.101 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.5 - Copyright (C) 1989-2012 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.35 + Copyright (C) 1989-2023 Dr. BERTRAND Joël This file is part of RPL/2. @@ -29,8 +29,13 @@ ================================================================================ */ -# define RPLARGS -# define struct_processus void +// Si TYPE_DECLARATION est défini, toutes les structures internes du RPL/2 +// sont exposés pour travailler sur des nouveaux types de données. +# ifndef TYPE_DECLARATION +# define RPLARGS +# define struct_processus void +# endif + # include "rpl.h" /* @@ -39,10 +44,75 @@ ================================================================================ */ -#define allocation(a) librpl_allocation((*rpl_arguments).s_etat_processus, a) -#define copie_objet(a, b) librpl_copie_objet( \ +#define __RPL__ struct_rpl_arguments *rpl_arguments; \ + rpl_arguments = &__static_rpl_arguments; \ + +#define __CATCH_SYSTEM_ERROR__ \ + do { if (((*rpl_arguments).erreur != 0) && \ + ((*rpl_arguments).type_erreur == 'S')) \ + return 0; } while(0) +#define leave do { return(0); } while(0) +#define _allocation(a) librpl_allocation((*rpl_arguments).s_etat_processus, a) +#define _copie_objet(a, b) librpl_copie_objet( \ (*rpl_arguments).s_etat_processus, a, b) -#define liberation(a) librpl_liberation((*rpl_arguments).s_etat_processus, a) +#define _liberation(a) librpl_liberation((*rpl_arguments).s_etat_processus, a) + +#ifdef __RPLC_MAIN + struct_rpl_arguments __static_rpl_arguments; + void *__static_library_descriptor; +# define global +# define initialize(a, b) a = b +# define declarePersistantObject(rpl_object) declareObject(rpl_object) +#else + extern struct_rpl_arguments __static_rpl_arguments; + extern void *__static_library_descriptor; +# define global extern +# define initialize(a, b) a; +# define declarePersistantObject(rpl_object) extern struct_objet *rpl_object +#endif + +#define empty int + +/* +-------------------------------------------------------------------------------- + Gestion des objets +-------------------------------------------------------------------------------- +*/ + +// new, dup, drop, disp, parse +// __type_new(struct_rpl_arguments *rpl_arguments) +#define declareTypeExtension(fct) \ + int __type_##fct(struct_processus *s_etat_processus, void **arg) { \ + char *rptr, *ptr, *iptr; \ + rptr = (char *) ((*s_etat_processus).definitions_chainees + \ + (*s_etat_processus).position_courante); \ + ptr = rptr; \ + iptr = (char *) (*s_etat_processus).instruction_courante; \ + if ((ptr != rptr) && (iptr)) goto __parse_error; +#define parseError { goto __parse_error; } while(0) +#define typeError { return(0); } while(0) +#define typeSystemError { (*s_etat_processus).erreur_systeme = \ + d_es_execution_bibliotheque; return(0); } while(0) +#define typeSuccess { return(1); } while(0) +#define typeFound(a) { return(a); } while(0) +#define endTypeExtension __parse_error: return(0); } +#define sizeOfParse (rptr - ptr) +#define searchType(...) { recherche_type(s_etat_processus); \ + if (((*s_etat_processus).erreur_execution != d_ex) || \ + ((*s_etat_processus).erreur_systeme != d_es)) \ + { __VA_ARGS__; return(0); } } while(0) +#define structObject struct_objet +#define initializeObject(a, b) do { \ + (*a).descripteur_bibliotheque = (*b).descripteur_bibliotheque; \ + (*a).extension_type = (*b).extension_type; } while(0) +#define objectContainer(type, a) ((type *) ((*a).objet)) +#define objectOf(a) ((*a).objet) +#define ifIsExternal(a, b) if (((*a).type == EXT) && ((*a).extension_type == b)) +#define elseIfIsExternal(a, b) } else if (((*a).type == EXT) && \ + ((*a).extension_type == b)) +#define subType(a) ((*a).extension_type) +#define integerFormat(a) formateur_nombre(s_etat_processus, a, 'I') +#define procStatus(a) (*a).s_etat_processus /* -------------------------------------------------------------------------------- @@ -50,35 +120,43 @@ -------------------------------------------------------------------------------- */ -#define declareObject(object) struct_objet *object = NULL +#define declareObject(rpl_object) struct_objet *rpl_object = NULL #define declareInteger(integer) integer8 integer #define declareReal(real) real8 real #define declareComplex(complex) complex16 complex #define declareDaisyChain(daisyChain) struct_liste_chainee *daisyChain = NULL -#define getDaisyChainFromList(list, daisyChain) { \ +#define getDaisyChainFromList(list, daisyChain) \ + __CATCH_SYSTEM_ERROR__; \ + do { \ typeof(list) __list = list; \ daisyChain = NULL; \ ifIsList(__list) { daisyChain = (*__list).objet; } \ else executionError("Type mistmatch error"); } while(0) #define fetchElementFromDaisyChain(daisyChain) \ - ({ typeof(daisyChain) __daisyChain = daisyChain; \ + ({ __CATCH_SYSTEM_ERROR__; typeof(daisyChain) __daisyChain = daisyChain; \ if (__daisyChain == NULL) executionError("End of daisy chain"); \ (__daisyChain == NULL) ? NULL : (*__daisyChain).donnee; }) #define replaceElementIntoDaisyChain(daisyChain, element) \ + __CATCH_SYSTEM_ERROR__; \ do { typeof(daisyChain) __daisyChain = daisyChain; \ if (__daisyChain == NULL) executionError("Nullified daisy chain"); \ + freeObject((*__daisyChain).donnee); \ (*__daisyChain).donnee = element; } while(0) #define nextElementOfDaisyChain(daisyChain) \ - ({ typeof(daisyChain) __daisyChain = daisyChain; \ + ({ __CATCH_SYSTEM_ERROR__; typeof(daisyChain) __daisyChain = daisyChain; \ if (__daisyChain == NULL) executionError("End of daisy chain"); \ (__daisyChain == NULL) ? NULL : (*__daisyChain).suivant; }) + +#define next suivant +#define data donnee +#define daisyChain struct_liste_chainee #define null NULL -#define nullify(ptr) { ptr = NULL; } while(0) +#define nullify(ptr) __CATCH_SYSTEM_ERROR__; do { ptr = NULL; } while(0) #define nullified(ptr) ((ptr) == NULL) #define postIncr(x) (x++) @@ -109,14 +187,27 @@ #define declareUnion typedef union { #define as(name) } name; -#define target(a) (*a) -#define address(a) (&a) +#define target(a) (*(a)) +#define address(a) (&(a)) -#define beginGroup { -#define endGroup } -#define beginMacro beginGroup +#define subroutine(name) int name() +#define beginGroup { __CATCH_SYSTEM_ERROR__; +#define endGroup __CATCH_SYSTEM_ERROR__; } +#define beginMacro do beginGroup #define endMacro endGroup while(0) -#define stopRequest test_arret((*rpl_arguments).s_etat_processus) +#define stopRequest ({ __CATCH_SYSTEM_ERROR__; \ + test_arret((*rpl_arguments).s_etat_processus); }) + +/* +-------------------------------------------------------------------------------- + Signaux +--------------------------------------------------------------------------------*/ + +#define blockSignals \ + { __CATCH_SYSTEM_ERROR__; sigset_t set, oldset; sigfillset(&set); \ + pthread_sigmask(SIG_BLOCK, &set, &oldset); +#define unblockSignals \ + pthread_sigmask(SIG_SETMASK, &oldset, NULL); __CATCH_SYSTEM_ERROR__; } /* -------------------------------------------------------------------------------- @@ -137,6 +228,8 @@ unsigned char __taille_bloc; \ unsigned char __type; \ t_8_bits __masque; \ + void *s_etat_processus = (*rpl_arguments).s_etat_processus; \ + DISABLE_SET_BUT_NOT_USED_WARNING(s_etat_processus); \ { \ (*rpl_arguments).instruction_valide = 'Y'; \ (*rpl_arguments).erreur = 0; \ @@ -150,7 +243,7 @@ DISABLE_SET_BUT_NOT_USED_WARNING(__masque); #define FUNCTION \ - if (__validation_instruction == d_vrai) return; \ + if (__validation_instruction == d_vrai) return 0; \ if (__presence_aide == d_faux) \ { \ systemError("Help string not defined"); \ @@ -170,8 +263,82 @@ strcpy((char *) __function_name, ""); \ if (__constante != 0) \ systemError("Constant definition error"); \ + __CATCH_SYSTEM_ERROR__; \ } } \ - return; + leave; + +/* +-------------------------------------------------------------------------------- + Destruction d'un objet +-------------------------------------------------------------------------------- +*/ + +#define freeObject(rpl_object) \ + __CATCH_SYSTEM_ERROR__; \ + do { \ + if (rpl_object == NULL) \ + systemError("Nullified object"); \ + _liberation(rpl_object); \ + rpl_object = NULL; \ + } while(0) + +/* +-------------------------------------------------------------------------------- + Copie d'un objet +-------------------------------------------------------------------------------- +*/ + +#define dupObject(rpl_object) \ + __CATCH_SYSTEM_ERROR__; \ + do { if (_copie_objet(rpl_object, 'P') != rpl_object) \ + systemError("Memory allocation error"); } while(0) + +/* +-------------------------------------------------------------------------------- + Déclaration des fonctions internes +-------------------------------------------------------------------------------- +*/ + +#define CONCAT(a, b) __RPL_CONCAT(a, b) +#define __RPL_CONCAT(a, b) a##b +#define FIRST(...) FIRST_HELPER(__VA_ARGS__, throwaway) +#define FIRST_HELPER(first, ...) first +#define REST(...) REST_HELPER(NUM(__VA_ARGS__), __VA_ARGS__) +#define REST_HELPER(qty, ...) REST_HELPER2(qty, __VA_ARGS__) +#define REST_HELPER2(qty, ...) REST_HELPER_##qty(__VA_ARGS__) +#define REST_HELPER_ONE(first) +#define REST_HELPER_TWOORMORE(first, ...) , __VA_ARGS__ +#define NUM(...) \ + SELECT_10TH(__VA_ARGS__, TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE,\ + TWOORMORE, TWOORMORE, TWOORMORE, TWOORMORE, ONE, throwaway) +#define SELECT_10TH(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, ...) a10 + +#define declareInternalFunction(type, ...) \ + type CONCAT(__internal_, FIRST(__VA_ARGS__)) \ + (struct_rpl_arguments *rpl_arguments REST(__VA_ARGS__)) { \ + type __internal_return; __internal_return = 0; int __type; \ + DISABLE_SET_BUT_NOT_USED_WARNING(__type); + +#define endInternalFunction return(__internal_return); } + +#define useInternalFunction(type, ...) \ + type CONCAT(__internal_, FIRST(__VA_ARGS__)) \ + (struct_rpl_arguments *rpl_arguments REST(__VA_ARGS__)) + +#define callInternalFunction(...) \ + CONCAT(__internal_, FIRST(__VA_ARGS__))(rpl_arguments REST(__VA_ARGS__)) + +/* +-------------------------------------------------------------------------------- + Déclaration des fonctions C +-------------------------------------------------------------------------------- +*/ + +#define declareCFunction(type, name, ...) \ + type name(__VA_ARGS__) { __RPL__ type __c_return; +#define endCFunction return(__c_return); } + +#define useCFunction(type, name, ...) type name(__VA_ARGS__) /* -------------------------------------------------------------------------------- @@ -180,35 +347,45 @@ */ #define declareExternalFunction(name) \ - void __external_##name(struct_rpl_arguments *rpl_arguments) { \ - char __function_name[] = "__external_"#name; + int __external_##name(struct_rpl_arguments *rpl_arguments) { \ + char __function_name[] = "__external_"#name; \ + __static_rpl_arguments = (*rpl_arguments); #define useExternalFunction(function) \ - void __external_##function(struct_rpl_arguments *rpl_arguments) + int __external_##function(struct_rpl_arguments *rpl_arguments) #define libraryName(name) char __library_name[] = #name; -#define __onLoading void __runOnLoading(struct_rpl_arguments *rpl_arguments) -#define __onClosing void __runOnClosing(struct_rpl_arguments *rpl_arguments) +#define __onLoading int __runOnLoading(struct_rpl_arguments *rpl_arguments, \ + void *descriptor) +#define __onClosing int __runOnClosing(struct_rpl_arguments *rpl_arguments, \ + void *descriptor) #define declareSubroutine(when) __##when { \ char __function_name[] = #when; \ + __static_rpl_arguments = (*rpl_arguments); \ + __static_library_descriptor = descriptor; \ HEADER \ declareHelpString(""); \ numberOfArguments(0); \ FUNCTION #define endSubroutine END } -#define notice(s, ...) do { ufprintf(s, __VA_ARGS__); fflush(s); } while(0) -#define logger(...) do { syslog(LOG_NOTICE, __VA_ARGS__); } while(0) +#define notice(s, ...) __CATCH_SYSTEM_ERROR__; \ + do { ufprintf(s, __VA_ARGS__); fflush(s); } while(0) +#define logger(...) __CATCH_SYSTEM_ERROR__; \ + do { syslog(LOG_NOTICE, __VA_ARGS__); } while(0) #define exportExternalFunctions(...) \ - char **__external_symbols(unsigned long *nb_symbols, \ + char **___external_symbols(struct_rpl_arguments *rpl_arguments, \ + integer8 *nb_symbols, \ const char *version) { \ char arguments[] = #__VA_ARGS__; \ char **tableau; \ char *ptr1, *ptr2; \ int drapeau; \ unsigned long i; \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ if (strcmp(version, _d_version_rpl) != 0) \ { \ notice(stdout, "Versions mismatch : library %s, expected %s\n", \ @@ -250,9 +427,10 @@ return(tableau); \ } -#define endExternalFunction return; } +#define endExternalFunction leave; } -#define callExternalFunction(function) { \ +#define callExternalFunction(function) do { \ + __CATCH_SYSTEM_ERROR__; \ __taille_bloc = sizeof(t_8_bits) * 8; \ __indice_bloc = (35 - 1) / __taille_bloc; \ __indice_bit = (35 - 1) % __taille_bloc; \ @@ -279,20 +457,20 @@ -------------------------------------------------------------------------------- */ -#define declareHelpString(h) { \ +#define declareHelpString(h) do { \ __presence_aide = d_vrai; \ if ((*rpl_arguments).affichage_arguments == 'Y') \ { \ uprintf("%s\n", h); \ - return; \ + return 0; \ } } while(0) -#define declareSymbolicConstant { \ +#define declareSymbolicConstant do { \ numberOfArguments(0); \ (*rpl_arguments).constante_symbolique = 'Y'; \ __constante++; } while(0) -#define numberOfArguments(n) { \ +#define numberOfArguments(n) do { \ __presence_validation = d_vrai; \ if ((*rpl_arguments).test_instruction == 'Y') \ { \ @@ -321,22 +499,22 @@ */ #define loop(b, e, s) for(b; e; s) { -#define endLoop } +#define endLoop __CATCH_SYSTEM_ERROR__; } #define repeatWhile(c) while(c) { -#define endWhile } +#define endWhile __CATCH_SYSTEM_ERROR__; } #define doUntil do { -#define repeatUntil(c) } while(!(c)); +#define repeatUntil(c) __CATCH_SYSTEM_ERROR__; } while(!(c)); #define select(s) switch(s) { -#define endSelect } +#define endSelect __CATCH_SYSTEM_ERROR__; } #define nonExclusiveCase(c) case c: { -#define endNonExclusiveCase } +#define endNonExclusiveCase __CATCH_SYSTEM_ERROR__; } #define exclusiveCase(c) case c: { -#define endExclusiveCase break; } +#define endExclusiveCase break; __CATCH_SYSTEM_ERROR__; } #define defaultCase default: -#define endDefaultCase break; } +#define endDefaultCase break; __CATCH_SYSTEM_ERROR__; } /* -------------------------------------------------------------------------------- @@ -344,30 +522,42 @@ -------------------------------------------------------------------------------- */ -#define returnOnError(...) { \ +#define returnOnError(...) do { \ if ((*rpl_arguments).erreur != 0) \ { \ __VA_ARGS__; \ - return; \ + return 0; \ } } while(0) -#define systemError(message) { \ +#define systemError(message) do { \ (*rpl_arguments).erreur = __LINE__; \ (*rpl_arguments).type_erreur = 'S'; \ (*rpl_arguments).message_erreur = (unsigned char *) message; \ - return; } while(0) + return 0; } while(0) -#define executionError(message) { \ +#define executionError(message) do { \ (*rpl_arguments).erreur = __LINE__; \ (*rpl_arguments).type_erreur = 'E'; \ (*rpl_arguments).message_erreur = (unsigned char *) message; } while(0) +#define onSystemError(...) do { \ + if (((*rpl_arguments).erreur != 0) && \ + ((*rpl_arguments).type_erreur == 'S')) \ + { \ + blockSignals; \ + kill(getpid(), SIGTERM); \ + unblockSignals; \ + __VA_ARGS__; \ + } } while(0) + #define onError(...) \ + __CATCH_SYSTEM_ERROR__; \ do { if (((*rpl_arguments).type_erreur == 'E') && \ ((*rpl_arguments).erreur != 0)) { __VA_ARGS__; \ (*rpl_arguments).erreur = 0; } } while(0) #define onExecution(...) \ + __CATCH_SYSTEM_ERROR__; \ do { if (((*rpl_arguments).type_erreur == 'E') && \ ((*rpl_arguments).erreur == 0)) { __VA_ARGS__; } } while(0) @@ -377,16 +567,19 @@ -------------------------------------------------------------------------------- */ -#define pushOnStack(object) { \ +#define pushOnStack(rpl_object) do { \ + __CATCH_SYSTEM_ERROR__; \ if (((*rpl_arguments).l_base_pile = \ - empilement_pile_operationnelle(rpl_arguments, object)) == NULL) \ + empilement_pile_operationnelle(rpl_arguments, rpl_object)) \ + == NULL) \ systemError("Memory allocation error"); \ - if ((*object).nombre_occurrences == 1) object = NULL; } while(0) + if ((*rpl_object).nombre_occurrences == 1) rpl_object = NULL; } while(0) -#define pullFromStack(object, ...) { \ +#define pullFromStack(rpl_object, ...) do { \ + __CATCH_SYSTEM_ERROR__; \ (*rpl_arguments).l_base_pile = \ - depilement_pile_operationnelle(rpl_arguments, &object); \ - if (object == NULL) \ + depilement_pile_operationnelle(rpl_arguments, &rpl_object); \ + if (rpl_object == NULL) \ { \ executionError("Too few arguments"); \ } \ @@ -399,18 +592,28 @@ else \ { \ __type = 0; \ - if (strstr(#__VA_ARGS__, "integer") != NULL) \ - if ((*object).type == INT) __type = 1; \ - if (strstr(#__VA_ARGS__, "real") != NULL) \ - if ((*object).type == REL) __type = 1; \ - if (strstr(#__VA_ARGS__, "complex") != NULL) \ - if ((*object).type == CPL) __type = 1; \ - if (strstr(#__VA_ARGS__, "string") != NULL) \ - if ((*object).type == CHN) __type = 1; \ - if (strstr(#__VA_ARGS__, "list") != NULL) \ - if ((*object).type == LST) __type = 1; \ - if (strstr(#__VA_ARGS__, "unknown") != NULL) \ - __type = 1; \ + if (strstr(#__VA_ARGS__, "integerVector") != NULL) { \ + if ((*rpl_object).type == VIN) __type = 1; } \ + else if (strstr(#__VA_ARGS__, "realVector") != NULL) { \ + if ((*rpl_object).type == VRL) __type = 1; } \ + else if (strstr(#__VA_ARGS__, "complexVector") != NULL) { \ + if ((*rpl_object).type == VCX) __type = 1; } \ + else if (strstr(#__VA_ARGS__, "integer") != NULL) { \ + if ((*rpl_object).type == INT) __type = 1; } \ + else if (strstr(#__VA_ARGS__, "real") != NULL) { \ + if ((*rpl_object).type == REL) __type = 1; } \ + else if (strstr(#__VA_ARGS__, "complex") != NULL) { \ + if ((*rpl_object).type == CPL) __type = 1; } \ + else if (strstr(#__VA_ARGS__, "string") != NULL) { \ + if ((*rpl_object).type == CHN) __type = 1; } \ + else if (strstr(#__VA_ARGS__, "list") != NULL) { \ + if ((*rpl_object).type == LST) __type = 1; } \ + else if (strstr(#__VA_ARGS__, "external") != NULL) { \ + if ((*rpl_object).type == EXT) { \ + if ((*rpl_object).descripteur_bibliotheque == \ + __static_library_descriptor) __type = 1; } }\ + else if (strstr(#__VA_ARGS__, "unknown") != NULL) { \ + __type = 1; } \ if (__type == 0) \ { \ executionError("Type not allowed"); \ @@ -418,6 +621,8 @@ } \ } } while(0) +#define objectSubtype(a) (*a).extension_type + /* -------------------------------------------------------------------------------- Gestion des objets @@ -425,13 +630,15 @@ */ #define then { -#define endIf } -#define elseIf } else if -#define orElse } else { +#define endIf __CATCH_SYSTEM_ERROR__; } +#define elseIf __CATCH_SYSTEM_ERROR__; } else if +#define orElse __CATCH_SYSTEM_ERROR__; } else { // Constantes symboliques -#define createSymbolicConstant(object, type, value) { \ +#define createSymbolicConstant(rpl_object, type, value) do { \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ if ((strcmp(#type, "integer") != 0) && (strcmp(#type, "real") != 0)) \ systemError("Type not allowed for symbolic constant"); \ __taille_bloc = sizeof(t_8_bits) * 8; \ @@ -440,7 +647,8 @@ __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \ if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \ { \ - createNameObject(object); \ + createNameObject(rpl_object); \ + __CATCH_SYSTEM_ERROR__; \ { \ char *__constant_name; \ if ((__constant_name = malloc((strlen(__library_name) + \ @@ -448,7 +656,7 @@ systemError("Memory allocation error"); \ sprintf(__constant_name, "%s$%s", __library_name, \ &(__function_name[11])); \ - setName(object, __constant_name); \ + setName(rpl_object, __constant_name); \ free(__constant_name); \ } \ } \ @@ -456,25 +664,31 @@ { \ if (strcmp(#type, "integer") == 0) \ { \ - createIntegerObject(object); \ - setInteger(object, value); \ + createIntegerObject(rpl_object); \ + __CATCH_SYSTEM_ERROR__; \ + setInteger(rpl_object, value); \ } \ else if (strcmp(#type, "real") == 0) \ { \ - createRealObject(object); \ - setReal(object, value); \ + createRealObject(rpl_object); \ + __CATCH_SYSTEM_ERROR__; \ + setReal(rpl_object, value); \ } \ } \ + __CATCH_SYSTEM_ERROR__; \ __constante--; } while(0) -#define createSymbolicComplexConstant(object, rp, ip) { \ +#define createSymbolicComplexConstant(rpl_object, rp, ip) do { \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ __taille_bloc = sizeof(t_8_bits) * 8; \ __indice_bloc = (35 - 1) / __taille_bloc; \ __indice_bit = (35 - 1) % __taille_bloc; \ __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \ if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \ { \ - createNameObject(object); \ + createNameObject(rpl_object); \ + __CATCH_SYSTEM_ERROR__; \ { \ char *__constant_name; \ if ((__constant_name = malloc((strlen(__library_name) + \ @@ -482,284 +696,297 @@ systemError("Memory allocation error"); \ sprintf(__constant_name, "%s$%s", __library_name, \ __function_name); \ - setName(object, __constant_name); \ + setName(rpl_object, __constant_name); \ free(__constant_name); \ } \ } \ else \ { \ - createComplexObject(object); \ - setComplex(object, rp, im); \ + createComplexObject(rpl_object); \ + __CATCH_SYSTEM_ERROR__; \ + setComplex(rpl_object, rp, im); \ } \ + __CATCH_SYSTEM_ERROR__; \ __constante--; } while(0) // Integer -#define setInteger(object, value) { \ - ifIsInteger(object) \ +#define setInteger(rpl_object, value) do { \ + ifIsInteger(rpl_object) \ { \ - if ((*object).nombre_occurrences > 1) \ + if ((*rpl_object).nombre_occurrences > 1) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(object, 'O')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ + _liberation(rpl_object); \ + rpl_object = __tmp_rpl_object; \ } \ - (*((integer8 *) (*object).objet)) = (integer8) value; \ + (*((integer8 *) (*rpl_object).objet)) = (integer8) value; \ } \ else executionError("Type mistmatch error"); } while(0) -#define isInteger(object) \ - ((*object).type == INT) +#define isInteger(rpl_object) \ + ((*rpl_object).type == INT) -#define ifIsInteger(object) if (isInteger(object)) -#define elseIfIsInteger(object) } else ifIsInteger(object) +#define ifIsInteger(rpl_object) if (isInteger(rpl_object)) +#define elseIfIsInteger(rpl_object) } else ifIsInteger(rpl_object) -#define getInteger(object, value) { \ +#define getInteger(rpl_object, value) do { \ value = 0; \ - ifIsInteger(object) value = (*((integer8 *) (*object).objet)); \ + ifIsInteger(rpl_object) value = (*((integer8 *) (*rpl_object).objet)); \ else executionError("Type mismatch error"); } while(0) -#define createIntegerObject(object) { \ - if (object != NULL) \ +#define createIntegerObject(rpl_object) do { \ + if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((object = allocation(INT)) == NULL) \ + if ((rpl_object = _allocation(INT)) == NULL) \ systemError("Memory allocation error"); \ - setInteger(object, 0); } while(0) + setInteger(rpl_object, 0); } while(0) // Real -#define setReal(object, value) { \ - ifIsReal(object) \ +#define setReal(rpl_object, value) do { \ + ifIsReal(rpl_object) \ { \ - if ((*object).nombre_occurrences > 1) \ + if ((*rpl_object).nombre_occurrences > 1) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(object, 'O')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ + _liberation(rpl_object); \ + rpl_object = __tmp_rpl_object; \ } \ - (*((real8 *) (*object).objet)) = (real8) value; \ + (*((real8 *) (*rpl_object).objet)) = (real8) value; \ } \ else executionError("Type mistmatch error"); } while(0) -#define isReal(object) \ - ((*object).type == REL) +#define isReal(rpl_object) \ + ((*rpl_object).type == REL) -#define ifIsReal(object) if (isReal(object)) -#define elseIfIsReal(object) } else ifIsReal(object) +#define ifIsReal(rpl_object) if (isReal(rpl_object)) +#define elseIfIsReal(rpl_object) } else ifIsReal(rpl_object) -#define getReal(object, value) { \ +#define getReal(rpl_object, value) do { \ value = 0; \ - ifIsReal(object) value = (*((real8 *) (*object).objet)); \ + ifIsReal(rpl_object) value = (*((real8 *) (*rpl_object).objet)); \ else executionError("Type mismatch error"); } while(0) -#define createRealObject(object) { \ - if (object != NULL) \ +#define createRealObject(rpl_object) do { \ + if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((object = allocation(REL)) == NULL) \ + if ((rpl_object = _allocation(REL)) == NULL) \ systemError("Memory allocation error"); \ - setReal(object, 0); } while(0) + setReal(rpl_object, 0); } while(0) // Complex -#define setComplex(object, rp, ip) { \ +#define setComplex(rpl_object, rp, ip) do { \ typeof(rp) __rp = rp; \ typeof(ip) __ip = ip; \ - ifIsComplex(object) \ + ifIsComplex(rpl_object) \ { \ - if ((*object).nombre_occurrences > 1) \ + if ((*rpl_object).nombre_occurrences > 1) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(object, 'O')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ + _liberation(rpl_object); \ + rpl_object = __tmp_rpl_object; \ } \ - setRealPartOfComplex(object, __rp); \ - setImaginaryPartOfComplex(object, __ip); \ + setRealPartOfComplex(rpl_object, __rp); \ + setImaginaryPartOfComplex(rpl_object, __ip); \ } \ else executionError("Type mismatch error"); } while(0) -#define setRealPartOfComplex(object, value) { \ - if ((*object).nombre_occurrences > 1) \ +#define setRealPartOfComplex(rpl_object, value) do { \ + if ((*rpl_object).nombre_occurrences > 1) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(object, 'O')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ + _liberation(rpl_object); \ + rpl_object = __tmp_rpl_object; \ } \ - ifIsComplex(object) (*((complex16 *) (*object).objet)).partie_reelle = \ - value; \ + ifIsComplex(rpl_object) (*((complex16 *) (*rpl_object).objet)) \ + .partie_reelle = value; \ else executionError("Type mismatch error"); } while(0) -#define setImaginaryPartOfComplex(object, value) { \ - if ((*object).nombre_occurrences > 1) \ +#define setImaginaryPartOfComplex(rpl_object, value) do { \ + if ((*rpl_object).nombre_occurrences > 1) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(object, 'O')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ + _liberation(rpl_object); \ + rpl_object = __tmp_rpl_object; \ } \ - (*((complex16 *) (*object).objet)).partie_imaginaire = value; \ + (*((complex16 *) (*rpl_object).objet)).partie_imaginaire = value; \ else executionError("Type mismatch error"); } while(0) -#define getRealPartOfComplex(object, value) \ - value = (*((complex16 *) (*object).objet)).partie_reelle +#define getRealPartOfComplex(rpl_object, value) \ + value = (*((complex16 *) (*rpl_object).objet)).partie_reelle -#define getImaginaryPartOfComplex(object, value) \ - value = (*((complex16 *) (*object).objet)).partie_imaginaire +#define getImaginaryPartOfComplex(rpl_object, value) \ + value = (*((complex16 *) (*rpl_object).objet)).partie_imaginaire -#define isComplex(object) \ - ((*object).type == CPL) +#define isComplex(rpl_object) \ + ((*rpl_object).type == CPL) -#define ifIsComplex(object) if (isComplex(object)) -#define elseIfIsComplex(object) } else ifIsComplex(object) +#define ifIsComplex(rpl_object) if (isComplex(rpl_object)) +#define elseIfIsComplex(rpl_object) } else ifIsComplex(rpl_object) -#define getComplex(object, value) { \ +#define getComplex(rpl_object, value) do { \ value.partie_reelle = 0; \ value.partie_imaginaire = 0; \ - ifIsComplex(object) value = (*((complex16 *) (*object).objet)); \ + ifIsComplex(rpl_object) value = (*((complex16 *) (*rpl_object).objet)); \ else systemError("Not a complex"); } while(0) -#define createComplexObject(object) { \ - if (object != NULL) \ +#define createComplexObject(rpl_object) do { \ + if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((object = allocation(CPL)) == NULL) \ + if ((rpl_object = _allocation(CPL)) == NULL) \ systemError("Memory allocation error"); \ - setComplex(object, 0, 0); } while(0) + setComplex(rpl_object, 0, 0); } while(0) // Generalized vectors -#define createVectorObject(object, size, otype, structure, cat) { \ +#define createVectorObject(rpl_object, size, otype, structure, cat) do { \ integer8 i; \ - if (object != NULL) \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ + if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((object = allocation(cat)) == NULL) \ + if ((rpl_object = _allocation(cat)) == NULL) \ systemError("Memory allocation error"); \ - (*((structure *) (*object).objet)).taille = size; \ - if (((*((structure *) (*object).objet)).tableau = \ + (*((structure *) (*rpl_object).objet)).taille = size; \ + if (((*((structure *) (*rpl_object).objet)).tableau = \ malloc(size * sizeof(otype))) == NULL) \ systemError("Memory allocation error"); \ if (cat != VCX) \ { \ if (cat == VIN) \ - (*((structure *) (*object).objet)).type = 'I'; \ + (*((structure *) (*rpl_object).objet)).type = 'I'; \ else \ - (*((structure *) (*object).objet)).type = 'R'; \ - for(i = 0; i < size; ((otype *) (*((structure *) (*object).objet)) \ + (*((structure *) (*rpl_object).objet)).type = 'R'; \ + for(i = 0; i < size; ((otype *) (*((structure *) (*rpl_object).objet)) \ .tableau)[i++] = (otype) 0); \ } \ else \ { \ - (*((structure *) (*object).objet)).type = 'C'; \ + (*((structure *) (*rpl_object).objet)).type = 'C'; \ for(i = 0; i < size; i++) \ { \ - ((complex16 *) (*((structure *) (*object).objet)).tableau)[i] \ + ((complex16 *) (*((structure *) (*rpl_object).objet)).tableau)[i] \ .partie_reelle = 0; \ - ((complex16 *) (*((structure *) (*object).objet)).tableau)[i] \ + ((complex16 *) (*((structure *) (*rpl_object).objet)).tableau)[i] \ .partie_imaginaire = 0; \ } \ } } while(0) +#define vectorSize(rpl_object) \ + ({ if ((*rpl_object).type == VIN) \ + (*((integer8 *) (*rpl_object).objet)).taille; \ + else if ((*rpl_object).type == VRL) \ + (*((real8 *) (*rpl_object).objet)).taille; \ + else if ((*rpl_object).type == VCX)) \ + (*((complex16 *) (*rpl_object).objet)).taille; \ + else { executionError("Type mistmatch error"); 0; } }) + // Integer vector -#define setIntegerIntoVector(object, value, position) { \ +#define setIntegerIntoVector(rpl_object, value, position) do { \ typeof(position) __position = position; \ - ifIsIntegerVector(object) \ + ifIsIntegerVector(rpl_object) \ { \ - if ((*object).nombre_occurrences > 1) \ + if ((*rpl_object).nombre_occurrences > 1) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(object, 'O')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ + _liberation(rpl_object); \ + rpl_object = __tmp_rpl_object; \ } \ __position--; \ if ((__position < 0) || (__position >= (*((struct_vecteur *) \ - (*object).objet)).taille)) \ + (*rpl_object).objet)).taille)) \ { executionError("Element out of range"); } \ else \ - ((integer8 *) (*((struct_vecteur *) (*object).objet)).tableau) \ + ((integer8 *) (*((struct_vecteur *) (*rpl_object).objet)).tableau) \ [__position] = (integer8) value; \ } \ else executionError("Type mistmatch error"); } while(0) -#define isIntegerVector(object) \ - ((*object).type == VIN) +#define isIntegerVector(rpl_object) \ + ((*rpl_object).type == VIN) -#define ifIsIntegerVector(object) if (isIntegerVector(object)) -#define elseIfIsIntegerVector(object) } else ifIsIntegerVector(object) +#define ifIsIntegerVector(rpl_object) if (isIntegerVector(rpl_object)) +#define elseIfIsIntegerVector(rpl_object) } else ifIsIntegerVector(rpl_object) -#define getIntegerFromVector(object, value, position) { \ +#define getIntegerFromVector(rpl_object, value, position) do { \ typeof(position) __position = position; \ value = 0; \ - ifIsIntegerVector(object) \ + ifIsIntegerVector(rpl_object) \ { \ __position--; \ if ((__position < 0) || (__position >= (*((struct_vecteur *) \ - (*object).objet)).taille)) \ + (*rpl_object).objet)).taille)) \ executionError("Element out of range"); \ else \ - value = ((integer8 *) (*((struct_vecteur *) (*object).objet)) \ + value = ((integer8 *) (*((struct_vecteur *) (*rpl_object).objet)) \ .tableau)[__position]; \ } \ else executionError("Type mismatch error"); } while(0) -#define createIntegerVectorObject(object, size) \ - createVectorObject(object, size, integer8, struct_vecteur, VIN) +#define createIntegerVectorObject(rpl_object, size) \ + createVectorObject(rpl_object, size, integer8, struct_vecteur, VIN) // Real vector -#define setRealIntoVector(object, value, position) { \ +#define setRealIntoVector(rpl_object, value, position) do { \ typeof(position) __position = position; \ - ifIsRealVector(object) \ + ifIsRealVector(rpl_object) \ { \ - if ((*object).nombre_occurrences > 1) \ + if ((*rpl_object).nombre_occurrences > 1) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(object, 'O')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ + _liberation(rpl_object); \ + rpl_object = __tmp_rpl_object; \ } \ __position--; \ if ((__position < 0) || (__position >= (*((struct_vecteur *) \ - (*object).objet)).taille)) \ + (*rpl_object).objet)).taille)) \ { executionError("Element out of range"); } \ else \ - ((real8 *) (*((struct_vecteur *) (*object).objet)).tableau) \ + ((real8 *) (*((struct_vecteur *) (*rpl_object).objet)).tableau) \ [__position] = (real8) value; \ } \ else executionError("Type mistmatch error"); } while(0) -#define isRealVector(object) \ - ((*object).type == VRL) +#define isRealVector(rpl_object) \ + ((*rpl_object).type == VRL) -#define ifIsRealVector(object) if (isRealVector(object)) -#define elseIfIsRealVector(object) } else ifIsRealVector(object) +#define ifIsRealVector(rpl_object) if (isRealVector(rpl_object)) +#define elseIfIsRealVector(rpl_object) } else ifIsRealVector(rpl_object) -#define getRealFromVector(object, value, position) { \ +#define getRealFromVector(rpl_object, value, position) do { \ typeof(position) __position = position; \ value = 0; \ - ifIsRealVector(object) \ + ifIsRealVector(rpl_object) \ { \ __position--; \ if ((__position < 0) || (__position >= (*((struct_vecteur *) \ - (*object).objet)).taille)) \ + (*rpl_object).objet)).taille)) \ executionError("Element out of range"); \ - value = ((real8 *) (*((struct_vecteur *) (*object).objet)).tableau) \ - [__position]; \ + value = ((real8 *) (*((struct_vecteur *) (*rpl_object).objet)) \ + .tableau)[__position]; \ } \ else executionError("Type mismatch error"); } while(0) -#define createRealVectorObject(object, size) \ - createVectorObject(object, size, real8, struct_vecteur, VRL) +#define createRealVectorObject(rpl_object, size) \ + createVectorObject(rpl_object, size, real8, struct_vecteur, VRL) // A FIXER @@ -771,152 +998,235 @@ #define createComplexMatrixObject +// Array + +#define isArray(rpl_object) \ + ((*rpl_object).type == TBL) + +#define ifIsArray(rpl_object) if (isArray(rpl_object)) +#define elseIfIsArray(rpl_object) } else if (isArray(rpl_object)) + +#define createArray(rpl_object, size) do { \ + int __i; \ + if (rpl_object != NULL) systemError("Reallocated object"); \ + if ((rpl_object = _allocation(TBL)) == NULL) \ + systemError("Memory allocation error"); \ + (*((struct_tableau *) (*rpl_object).objet)).nombre_elements = size; \ + if (((*((struct_tableau *) (*rpl_object).objet)).elements = malloc( \ + size * sizeof(struct_objet *))) == NULL) \ + systemError("Memory allocation error"); \ + for(__i = 0; __i < size; __i++) { \ + nullify((*((struct_tableau *) (*rpl_object).objet)).elements[__i]); \ + createIntegerObject((*((struct_tableau *) (*rpl_object).objet)) \ + .elements[__i]); } \ + } while(0) + +#define setObjectIntoArray(rpl_array, pos, rpl_object) do { \ + typeof(pos) __position = pos; __position--; \ + ifIsArray(rpl_array) { \ + if ((__position < 0) || (__position >= (*((struct_tableau *) \ + (*rpl_array).objet)).nombre_elements)) \ + executionError("Element out of range"); \ + if ((*rpl_array).nombre_occurrences > 1) \ + { \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_array, 'O')) == NULL) \ + systemError("Memory allocation error"); \ + _liberation(rpl_array); \ + rpl_array = __tmp_rpl_object; \ + } \ + _liberation((*((struct_tableau *) (*rpl_array).objet)) \ + .elements[__position]); \ + (*((struct_tableau *) (*rpl_array).objet)).elements[__position] = \ + rpl_object; \ + } \ + else executionError("Type mistmatch error"); \ + nullify(rpl_object); \ + } while(0) + +#define getObjectFromArray() + // Binary integer -#define setBinaryInteger(object, value) { \ - ifIsBinaryInteger(object) \ +#define setBinaryInteger(rpl_object, value) do { \ + ifIsBinaryInteger(rpl_object) \ { \ - if ((*object).nombre_occurrences > 1) \ + if ((*rpl_object).nombre_occurrences > 1) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(object, 'O')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ + _liberation(rpl_object); \ + rpl_object = __tmp_rpl_object; \ } \ - (*((integer8 *) (*object).objet)) = (integer8) value; \ + (*((integer8 *) (*rpl_object).objet)) = (integer8) value; \ } \ else executionError("Type mistmatch error"); } while(0) -#define isBinaryInteger(object) \ - ((*object).type == BIN) +#define isBinaryInteger(rpl_object) \ + ((*rpl_object).type == BIN) -#define ifIsBinaryInteger(object) if (isBinaryInteger(object)) -#define elseIfIsBinaryInteger(object) } else ifIsBinaryInteger(object) +#define ifIsBinaryInteger(rpl_object) if (isBinaryInteger(rpl_object)) +#define elseIfIsBinaryInteger(rpl_object) } else ifIsBinaryInteger(rpl_object) -#define getBinaryInteger(object, value) { \ +#define getBinaryInteger(rpl_object, value) do { \ value = 0; \ - ifIsBinaryInteger(object) value = (*((integer8 *) (*object).objet)); \ + ifIsBinaryInteger(rpl_object) value = \ + (*((integer8 *) (*rpl_object).objet)); \ else executionError("Type mismatch error"); } while(0) -#define createBinaryIntegerObject(object) { \ - if (object != NULL) \ +#define createBinaryIntegerObject(rpl_object) do { \ + if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((object = allocation(BIN)) == NULL) \ + if ((rpl_object = _allocation(BIN)) == NULL) \ systemError("Memory allocation error"); \ - setBinaryInteger(object, 0); } while(0) + setBinaryInteger(rpl_object, 0); } while(0) // Name -#define isName(object) \ - ((*object).type == NOM) +#define isName(rpl_object) \ + ((*rpl_object).type == NOM) -#define ifIsName(object) if (isName(object)) -#define elseIfIsName(object) } else if (isName(object)) +#define ifIsName(rpl_object) if (isName(rpl_object)) +#define elseIfIsName(rpl_object) } else if (isName(rpl_object)) -#define setName(object, value) { \ - ifIsName(object) \ +#define setName(rpl_object, value) do { \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ + ifIsName(rpl_object) \ { \ - if ((*object).nombre_occurrences > 1) \ + if ((*rpl_object).nombre_occurrences > 1) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(object, 'O')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ + _liberation(rpl_object); \ + rpl_object = __tmp_rpl_object; \ } \ - free((*((struct_nom *) (*object).objet)).nom); \ - (*((struct_nom *) (*object).objet)).symbole = d_faux; \ - if (((*((struct_nom *) (*object).objet)).nom = malloc( \ + free((*((struct_nom *) (*rpl_object).objet)).nom); \ + (*((struct_nom *) (*rpl_object).objet)).symbole = d_faux; \ + if (((*((struct_nom *) (*rpl_object).objet)).nom = malloc( \ (strlen(value) + 1) * sizeof(unsigned char))) == NULL) \ systemError("Memory allocation error"); \ - strcpy((char *) (*((struct_nom *) (*object).objet)).nom, \ + strcpy((char *) (*((struct_nom *) (*rpl_object).objet)).nom, \ (char *) value); \ } \ else executionError("Type mistmatch error"); } while(0) -#define createNameObject(object) { \ - if (object != NULL) \ +#define setSymbolicName(rpl_object, value) do { \ + setName(rpl_object, value); \ + (*((struct_nom *) (*rpl_object).objet)).symbole = d_vrai; } while(0) + +#define createNameObject(rpl_object) do { \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ + if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((object = allocation(NOM)) == NULL) \ + if ((rpl_object = _allocation(NOM)) == NULL) \ systemError("Memory allocation error"); \ - (*((struct_nom *) (*object).objet)).symbole = d_faux; \ - if (((*((struct_nom *) (*object).objet)).nom = malloc( \ + (*((struct_nom *) (*rpl_object).objet)).symbole = d_faux; \ + if (((*((struct_nom *) (*rpl_object).objet)).nom = malloc( \ sizeof(unsigned char))) == NULL) \ systemError("Memory allocation error"); \ - strcpy((char *) (*((struct_nom *) (*object).objet)).nom, ""); } while(0) + strcpy((char *) (*((struct_nom *) (*rpl_object).objet)).nom, ""); } while(0) // String -#define isString(object) \ - ((*object).type == CHN) +#define isString(rpl_object) \ + ((*rpl_object).type == CHN) -#define ifIsString(object) if (isString(object)) -#define elseIfIsString(object) else if (isString(objet)) +#define ifIsString(rpl_object) if (isString(rpl_object)) +#define elseIfIsString(rpl_object) } else if (isString(rpl_object)) -#define setString(object, string) { \ - ifIsString(object) \ +#define setString(rpl_object, string) do { \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ + ifIsString(rpl_object) \ { \ - if ((*object).nombre_occurrences > 1) \ + if (string == NULL) executionError("Nullified string"); else \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(object, 'O')) == NULL) \ + if ((*rpl_object).nombre_occurrences > 1) \ + { \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) \ + == NULL) \ + systemError("Memory allocation error"); \ + _liberation(rpl_object); \ + rpl_object = __tmp_rpl_object; \ + } \ + free((unsigned char *) (*rpl_object).objet); \ + if (((*rpl_object).objet = malloc((strlen(string) + 1) * \ + sizeof(unsigned char))) == NULL) \ systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ + strcpy((char *) (*rpl_object).objet, string); \ } \ - free((unsigned char *) (*object).objet); \ - if (((*object).objet = malloc((strlen(string) + 1) * \ - sizeof(unsigned char))) == NULL) \ - systemError("Memory allocation error"); \ - strcpy((char *) (*object).objet, string); \ } \ else executionError("Type mistmatch error"); } while(0) -#define getString(object, string) { \ +#define getString(rpl_object, string) do { \ string = NULL; \ - ifIsString(object) string = (char *) (*object).objet; \ + ifIsString(rpl_object) string = (char *) (*rpl_object).objet; \ else executionError("Type mismatch error"); } while(0) -#define createStringObject(object) { \ - if (object != NULL) \ +#define unEscString(s) ({ \ + unsigned char *__a; integer8 __l; \ + __a = formateur_flux((*rpl_arguments).s_etat_processus, \ + (unsigned char *) s, &__l); \ + if (nullified(__a)) systemError("Memory allocation error"); \ + (string) __a; \ + }) + +#define escString(rpl_object) ({ \ + unsigned char *__a; integer8 __l; \ + __a = analyse_flux((*rpl_arguments).s_etat_processus, \ + (unsigned char *) s, strlen(s)); \ + if (nullified(__a)) systemError("Memory allocation error"); \ + (string) __a; \ + }) + +#define createStringObject(rpl_object) do { \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ + if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((object = allocation(CHN)) == NULL) \ + if ((rpl_object = _allocation(CHN)) == NULL) \ systemError("Memory allocation error"); \ - if (((*object).objet = malloc(sizeof(unsigned char))) == NULL) \ + if (((*rpl_object).objet = malloc(sizeof(unsigned char))) == NULL) \ systemError("Memory allocation error"); \ - strcpy((char *) (*object).objet, ""); } while(0) + strcpy((char *) (*rpl_object).objet, ""); } while(0) // List -#define isList(object) \ - ((*object).type == LST) +#define isList(rpl_object) \ + ((*rpl_object).type == LST) -#define ifIsList(object) if (isList(object)) -#define elseIfIsList(object) else if (isList(object)) +#define ifIsList(rpl_object) if (isList(rpl_object)) +#define elseIfIsList(rpl_object) else if (isList(rpl_object)) -#define createListObject(object) { \ - if (object != NULL) \ +#define createListObject(rpl_object) do { \ + if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((object = allocation(LST)) == NULL) \ + if ((rpl_object = _allocation(LST)) == NULL) \ systemError("Memory allocation error"); \ - (*object).objet = NULL; } while(0) + (*rpl_object).objet = NULL; } while(0) -#define addObjectToList(list, object) { \ +#define addObjectToList(list, rpl_object) do { \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ ifIsList(list) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(list, 'N')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(list, 'N')) == NULL) \ systemError("Memory allocation error"); \ - liberation(list); \ - list = __tmp_object; \ + _liberation(list); \ + list = __tmp_rpl_object; \ if ((*list).objet == NULL) \ { \ if (((*list).objet = malloc(sizeof(struct_liste_chainee))) \ == NULL) \ systemError("Memory allocation error"); \ (*((struct_liste_chainee *) (*list).objet)).suivant = NULL; \ - (*((struct_liste_chainee *) (*list).objet)).donnee = object; \ + (*((struct_liste_chainee *) (*list).objet)).donnee = rpl_object; \ } \ else \ { \ @@ -929,27 +1239,29 @@ systemError("Memory allocation error"); \ l_element_courant = (*l_element_courant).suivant; \ (*l_element_courant).suivant = NULL; \ - (*l_element_courant).donnee = object; \ + (*l_element_courant).donnee = rpl_object; \ } \ - object = NULL; \ + rpl_object = NULL; \ } \ else executionError("Type mistmatch error"); } while(0) -#define insertObjectIntoList(list, object) { \ +#define insertObjectIntoList(list, rpl_object) do { \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ ifIsList(list) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(list, 'N')) == NULL) \ + struct_objet *__tmp_rpl_object; \ + if ((__tmp_rpl_object = _copie_objet(list, 'N')) == NULL) \ systemError("Memory allocation error"); \ - liberation(list); \ - list = __tmp_object; \ + _liberation(list); \ + list = __tmp_rpl_object; \ if ((*list).objet == NULL) \ { \ if (((*list).objet = malloc(sizeof(struct_liste_chainee))) \ == NULL) \ systemError("Memory allocation error"); \ (*((struct_liste_chainee *) (*list).objet)).suivant = NULL; \ - (*((struct_liste_chainee *) (*list).objet)).donnee = object; \ + (*((struct_liste_chainee *) (*list).objet)).donnee = rpl_object; \ } \ else \ { \ @@ -957,39 +1269,55 @@ if ((l_element_courant = \ malloc(sizeof(struct_liste_chainee))) == NULL) \ systemError("Memory allocation error"); \ - (*l_element_courant).donnee = object; \ + (*l_element_courant).donnee = rpl_object; \ (*l_element_courant).suivant = (*list).objet; \ (*list).objet = l_element_courant; \ } \ - object = NULL; \ + rpl_object = NULL; \ } \ else executionError("Type mistmatch error"); } while(0) -#define removeObjectFromList(list, object) \ +#define removeObjectFromList(list, rpl_object) do { \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ ifIsList(list) \ { \ - if ((*object).objet == NULL) \ + if ((*list).objet != NULL) \ { \ - struct_objet *__tmp_object; \ - if ((__tmp_object = copie_objet(list, 'N')) == NULL) \ - systemError("Memory allocation error"); \ - liberation(object); \ - object = __tmp_object; \ - \ - \ - \ - \ - } \ + struct_liste_chainee *__current; \ + struct_liste_chainee *__previous; \ + __current = (*list).objet; \ + __previous = NULL; \ + if ((*__current).donnee == rpl_object) \ + { \ + (*list).objet = (*__current).suivant; \ + } \ + else \ + { \ + while(__current != NULL) \ + { \ + if ((*__current).donnee == rpl_object) \ + { \ + (*__previous).suivant = (*__current).suivant; \ + break; \ + } \ + __previous = __current; \ + __current = (*__current).suivant; \ + } \ + } \ + _liberation((*__current).donnee); \ + free(__current); \ + } \ } \ else executionError("Type mistmatch error"); } while(0) -#define getObjectFromList(list, position, object) +#define getObjectFromList(list, position, rpl_object) -#define putObjectIntoList(list, position, object) +#define putObjectIntoList(list, position, rpl_object) -#define getListFromList(list, position1, position2, object) +#define getListFromList(list, position1, position2, rpl_object) -#define listLength(list, length) { \ +#define listLength(list, length) do { \ if (list == NULL) executionError("Nullified object"); \ if ((*list).type != LST) \ executionError("Type mistmatch error"); \ @@ -1004,30 +1332,25 @@ } \ } } while(0) - -/* --------------------------------------------------------------------------------- - Destruction d'un objet --------------------------------------------------------------------------------- -*/ - -#define freeObject(object) \ - { \ - if (object == NULL) \ - systemError("Nullified object"); \ - liberation(object); \ - object = NULL; \ +// NON +#define createObject(rpl_object) do { \ + if (rpl_object != NULL) \ + systemError("Reallocated object"); \ + if ((rpl_object = _allocation(NON)) == NULL) \ + systemError("Memory allocation error"); \ + (*rpl_object).objet = NULL; \ } while(0) -/* --------------------------------------------------------------------------------- - Copie d'un objet --------------------------------------------------------------------------------- -*/ - -#define dupObject(object) \ - { if (copie_objet(object, 'P') != object) \ - systemError("Memory allocation error"); } while(0) +// EXT +#define createExternalObject(rpl_object, subtype) do { \ + if (rpl_object != NULL) \ + systemError("Reallocated object"); \ + if ((rpl_object = _allocation(EXT)) == NULL) \ + systemError("Memory allocation error"); \ + (*rpl_object).objet = NULL; \ + (*rpl_object).extension_type = subtype; \ + (*rpl_object).descripteur_bibliotheque = __static_library_descriptor; \ + } while(0) /* -------------------------------------------------------------------------------- @@ -1038,10 +1361,23 @@ #define size(a) sizeof(a) #define allocate(a) ({ void *ptr; \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ if ((ptr = malloc(a)) == NULL) \ - systemError("Memory allocation error"); ptr; }) + { systemError("Memory allocation error"); \ + __CATCH_SYSTEM_ERROR__; } ptr; }) \ -#define deallocate(a) free(a) +#define reallocate(a, s) ({ void *ptr; \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ + if ((ptr = realloc(a, s)) == NULL) \ + { systemError("Memory allocation error"); \ + __CATCH_SYSTEM_ERROR__; } ptr; }) \ + +#define deallocate(a) do { \ + struct_processus *s_etat_processus; \ + s_etat_processus = (*rpl_arguments).s_etat_processus; \ + free(a); } while(0) /* -------------------------------------------------------------------------------- @@ -1050,7 +1386,8 @@ */ #define pollSignalsAndInterrupts() \ - { scrutation_injection((*rpl_arguments).s_etat_processus); } while(0) + __CATCH_SYSTEM_ERROR__; \ + do { scrutation_injection((*rpl_arguments).s_etat_processus); } while(0) /* -------------------------------------------------------------------------------- @@ -1058,8 +1395,9 @@ -------------------------------------------------------------------------------- */ -#define intrinsic(function) { \ +#define intrinsic(function) do { \ int __status; \ + __CATCH_SYSTEM_ERROR__; \ __status = wrapper_instruction_intrinseque( \ instruction_##function, rpl_arguments); \ if (__status == 1) executionError(#function); \