File:  [local] / rpl / src / rplexternals.h
Revision 1.77: download - view: text, annotated - select for diffs - revision graph
Sun Jul 2 22:28:20 2017 UTC (6 years, 10 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Dernière série de patches pour gérer les types externes dans les
bibliothèques. Voir pour cela modules/sets. Fonctionne.

Attention, ne permet pas encore de compiler un code utilisant des types
externes (la compilation se fait avant l'exécution de l'instruction USE).

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

CVSweb interface <joel.bertrand@systella.fr>