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

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

CVSweb interface <joel.bertrand@systella.fr>