--- rpl/src/rplexternals.h 2015/10/26 15:14:43 1.67 +++ rpl/src/rplexternals.h 2017/06/30 13:11:26 1.76 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.23 - Copyright (C) 1989-2015 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.27 + Copyright (C) 1989-2017 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" /* @@ -47,10 +52,10 @@ ((*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( \ +#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; @@ -68,6 +73,33 @@ /* -------------------------------------------------------------------------------- + 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 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) + +/* +-------------------------------------------------------------------------------- Types -------------------------------------------------------------------------------- */ @@ -224,7 +256,7 @@ do { \ if (rpl_object == NULL) \ systemError("Nullified object"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = NULL; \ } while(0) @@ -236,7 +268,7 @@ #define dupObject(rpl_object) \ __CATCH_SYSTEM_ERROR__; \ - do { if (copie_objet(rpl_object, 'P') != rpl_object) \ + do { if (_copie_objet(rpl_object, 'P') != rpl_object) \ systemError("Memory allocation error"); } while(0) /* @@ -245,8 +277,8 @@ -------------------------------------------------------------------------------- */ -#define CONCAT(a, b) __CONCAT(a, b) -#define __CONCAT(a, b) a##b +#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__) @@ -648,9 +680,9 @@ if ((*rpl_object).nombre_occurrences > 1) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = __tmp_rpl_object; \ } \ (*((integer8 *) (*rpl_object).objet)) = (integer8) value; \ @@ -671,7 +703,7 @@ #define createIntegerObject(rpl_object) do { \ if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((rpl_object = allocation(INT)) == NULL) \ + if ((rpl_object = _allocation(INT)) == NULL) \ systemError("Memory allocation error"); \ setInteger(rpl_object, 0); } while(0) @@ -683,9 +715,9 @@ if ((*rpl_object).nombre_occurrences > 1) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = __tmp_rpl_object; \ } \ (*((real8 *) (*rpl_object).objet)) = (real8) value; \ @@ -706,7 +738,7 @@ #define createRealObject(rpl_object) do { \ if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((rpl_object = allocation(REL)) == NULL) \ + if ((rpl_object = _allocation(REL)) == NULL) \ systemError("Memory allocation error"); \ setReal(rpl_object, 0); } while(0) @@ -720,9 +752,9 @@ if ((*rpl_object).nombre_occurrences > 1) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = __tmp_rpl_object; \ } \ setRealPartOfComplex(rpl_object, __rp); \ @@ -734,9 +766,9 @@ if ((*rpl_object).nombre_occurrences > 1) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = __tmp_rpl_object; \ } \ ifIsComplex(rpl_object) (*((complex16 *) (*rpl_object).objet)) \ @@ -747,9 +779,9 @@ if ((*rpl_object).nombre_occurrences > 1) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = __tmp_rpl_object; \ } \ (*((complex16 *) (*rpl_object).objet)).partie_imaginaire = value; \ @@ -776,7 +808,7 @@ #define createComplexObject(rpl_object) do { \ if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((rpl_object = allocation(CPL)) == NULL) \ + if ((rpl_object = _allocation(CPL)) == NULL) \ systemError("Memory allocation error"); \ setComplex(rpl_object, 0, 0); } while(0) @@ -788,7 +820,7 @@ s_etat_processus = (*rpl_arguments).s_etat_processus; \ if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((rpl_object = allocation(cat)) == NULL) \ + if ((rpl_object = _allocation(cat)) == NULL) \ systemError("Memory allocation error"); \ (*((structure *) (*rpl_object).objet)).taille = size; \ if (((*((structure *) (*rpl_object).objet)).tableau = \ @@ -824,9 +856,9 @@ if ((*rpl_object).nombre_occurrences > 1) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = __tmp_rpl_object; \ } \ __position--; \ @@ -872,9 +904,9 @@ if ((*rpl_object).nombre_occurrences > 1) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = __tmp_rpl_object; \ } \ __position--; \ @@ -928,9 +960,9 @@ if ((*rpl_object).nombre_occurrences > 1) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = __tmp_rpl_object; \ } \ (*((integer8 *) (*rpl_object).objet)) = (integer8) value; \ @@ -952,7 +984,7 @@ #define createBinaryIntegerObject(rpl_object) do { \ if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((rpl_object = allocation(BIN)) == NULL) \ + if ((rpl_object = _allocation(BIN)) == NULL) \ systemError("Memory allocation error"); \ setBinaryInteger(rpl_object, 0); } while(0) @@ -972,9 +1004,9 @@ if ((*rpl_object).nombre_occurrences > 1) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) == NULL) \ systemError("Memory allocation error"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = __tmp_rpl_object; \ } \ free((*((struct_nom *) (*rpl_object).objet)).nom); \ @@ -996,7 +1028,7 @@ s_etat_processus = (*rpl_arguments).s_etat_processus; \ if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((rpl_object = allocation(NOM)) == NULL) \ + if ((rpl_object = _allocation(NOM)) == NULL) \ systemError("Memory allocation error"); \ (*((struct_nom *) (*rpl_object).objet)).symbole = d_faux; \ if (((*((struct_nom *) (*rpl_object).objet)).nom = malloc( \ @@ -1022,9 +1054,10 @@ if ((*rpl_object).nombre_occurrences > 1) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(rpl_object, 'O')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(rpl_object, 'O')) \ + == NULL) \ systemError("Memory allocation error"); \ - liberation(rpl_object); \ + _liberation(rpl_object); \ rpl_object = __tmp_rpl_object; \ } \ free((unsigned char *) (*rpl_object).objet); \ @@ -1046,7 +1079,7 @@ s_etat_processus = (*rpl_arguments).s_etat_processus; \ if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((rpl_object = allocation(CHN)) == NULL) \ + if ((rpl_object = _allocation(CHN)) == NULL) \ systemError("Memory allocation error"); \ if (((*rpl_object).objet = malloc(sizeof(unsigned char))) == NULL) \ systemError("Memory allocation error"); \ @@ -1063,7 +1096,7 @@ #define createListObject(rpl_object) do { \ if (rpl_object != NULL) \ systemError("Reallocated object"); \ - if ((rpl_object = allocation(LST)) == NULL) \ + if ((rpl_object = _allocation(LST)) == NULL) \ systemError("Memory allocation error"); \ (*rpl_object).objet = NULL; } while(0) @@ -1073,9 +1106,9 @@ ifIsList(list) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(list, 'N')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(list, 'N')) == NULL) \ systemError("Memory allocation error"); \ - liberation(list); \ + _liberation(list); \ list = __tmp_rpl_object; \ if ((*list).objet == NULL) \ { \ @@ -1108,9 +1141,9 @@ ifIsList(list) \ { \ struct_objet *__tmp_rpl_object; \ - if ((__tmp_rpl_object = copie_objet(list, 'N')) == NULL) \ + if ((__tmp_rpl_object = _copie_objet(list, 'N')) == NULL) \ systemError("Memory allocation error"); \ - liberation(list); \ + _liberation(list); \ list = __tmp_rpl_object; \ if ((*list).objet == NULL) \ { \ @@ -1162,7 +1195,7 @@ __current = (*__current).suivant; \ } \ } \ - liberation((*__current).donnee); \ + _liberation((*__current).donnee); \ free(__current); \ } \ } \ @@ -1203,6 +1236,12 @@ if ((ptr = malloc(a)) == NULL) \ systemError("Memory allocation error"); ptr; }) +#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"); ptr; }) + #define deallocate(a) do { \ struct_processus *s_etat_processus; \ s_etat_processus = (*rpl_arguments).s_etat_processus; \