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

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

CVSweb interface <joel.bertrand@systella.fr>