File:  [local] / rpl / src / rplexternals.h
Revision 1.78: download - view: text, annotated - select for diffs - revision graph
Mon Jul 3 11:47:05 2017 UTC (6 years, 9 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Création des instructions UNION et INTERSECTION dans le module SETS.

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

CVSweb interface <joel.bertrand@systella.fr>