Annotation of rpl/src/rplexternals.h, revision 1.80

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

CVSweb interface <joel.bertrand@systella.fr>