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

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

CVSweb interface <joel.bertrand@systella.fr>