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

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

CVSweb interface <joel.bertrand@systella.fr>