File:  [local] / rpl / src / optimisation.c
Revision 1.84: download - view: text, annotated - select for diffs - revision graph
Fri Jan 10 11:15:50 2020 UTC (4 years, 3 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_32, HEAD
Modification du copyright.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.32
    4:   Copyright (C) 1989-2020 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: #include "rpl-conv.h"
   24: 
   25: 
   26: /*
   27: ================================================================================
   28:   Boucle principale optimisée de l'interprète RPL/2
   29: ================================================================================
   30:   Entrées : structure sur l'état du processus
   31: --------------------------------------------------------------------------------
   32:   Sorties : Néant
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: logical1
   39: sequenceur_optimise(struct_processus *s_etat_processus, struct_liste_chainee
   40:         *l_bibliotheques)
   41: {
   42:     integer8                    adresse_point_entree;
   43:     integer8                    i;
   44:     integer8                    j;
   45:     integer8                    nb_variables;
   46:     integer8                    point_entree;
   47: 
   48:     logical1                    erreur;
   49: 
   50:     struct_objet                *programme_principal;
   51: 
   52:     struct_tableau_variables    *tableau;
   53: 
   54:     unsigned char               *message;
   55:     unsigned char               registre;
   56: 
   57:     if ((*s_etat_processus).debug == d_vrai)
   58:         if (((*s_etat_processus).type_debug &
   59:                 d_debug_analyse) != 0)
   60:     {
   61:         if ((*s_etat_processus).langue == 'F')
   62:         {
   63:             printf("+++Compilation [%d]\n", (int) getpid());
   64:         }
   65:         else
   66:         {
   67:             printf("+++Compilation [%d]\n", (int) getpid());
   68:         }
   69: 
   70:         printf("\n");
   71:         fflush(stdout);
   72:     }
   73: 
   74:     point_entree = -1;
   75:     adresse_point_entree = 0;
   76:     programme_principal = NULL;
   77: 
   78:     empilement_pile_systeme(s_etat_processus);
   79:     (*(*s_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
   80:     (*s_etat_processus).autorisation_empilement_programme = 'Y';
   81:     (*s_etat_processus).mode_execution_programme = 'N';
   82: 
   83:     nb_variables = nombre_variables(s_etat_processus);
   84: 
   85:     if ((tableau = malloc(((size_t) nb_variables) *
   86:             sizeof(struct_tableau_variables))) == NULL)
   87:     {
   88:         if ((*s_etat_processus).langue == 'F')
   89:         {
   90:             printf("+++Système : Mémoire insuffisante\n");
   91:         }
   92:         else
   93:         {
   94:             printf("+++System : Not enough memory\n");
   95:         }
   96: 
   97:         liberation_mutexes_arbre_variables_partagees(s_etat_processus,
   98:                 (*(*s_etat_processus).s_arbre_variables_partagees));
   99:         return(d_erreur);
  100:     }
  101: 
  102:     nb_variables = liste_variables(s_etat_processus, tableau);
  103: 
  104:     for(i = 0; i < nb_variables; i++)
  105:     {
  106:         if (tableau[i].niveau == 0)
  107:         {
  108:             // Variables qui contiennent les points d'entrée des définitions.
  109: 
  110:             (*s_etat_processus).position_courante = (*((integer8 *)
  111:                     (*(tableau[i].objet)).objet));
  112: 
  113:             if (point_entree == -1)
  114:             {
  115:                 adresse_point_entree = (*s_etat_processus).position_courante;
  116:                 point_entree = i;
  117:             }
  118:             else
  119:             {
  120:                 if ((*s_etat_processus).position_courante <
  121:                         adresse_point_entree)
  122:                 {
  123:                     adresse_point_entree = (*s_etat_processus)
  124:                             .position_courante;
  125:                     point_entree = i;
  126:                 }
  127:             }
  128: 
  129:             if ((erreur = recherche_instruction_suivante(s_etat_processus))
  130:                     == d_erreur)
  131:             {
  132:                 if ((*s_etat_processus).langue == 'F')
  133:                 {
  134:                     printf("+++Fatal : Compilation impossible\n");
  135:                 }
  136:                 else
  137:                 {
  138:                     printf("+++Fatal : Compilation failed\n");
  139:                 }
  140: 
  141:                 for(j = 0; j < nb_variables; j++)
  142:                 {
  143:                     if (tableau[j].mutex != NULL)
  144:                     {
  145:                         pthread_mutex_unlock(tableau[j].mutex);
  146:                     }
  147:                 }
  148: 
  149:                 free(tableau);
  150:                 return(d_erreur);
  151:             }
  152: 
  153:             // Il faut désactiver la vérification des variables
  154:             // implicites car aucune variable de niveau strictement
  155:             // positif étant créée, la fonction recherche_type() pourrait
  156:             // échouer.
  157: 
  158:             registre = (*s_etat_processus).autorisation_nom_implicite;
  159:             (*s_etat_processus).autorisation_nom_implicite = 'Y';
  160:             (*s_etat_processus).type_en_cours = NON;
  161:             recherche_type(s_etat_processus);
  162:             (*s_etat_processus).autorisation_nom_implicite = registre;
  163: 
  164:             if (((*s_etat_processus).erreur_execution != d_ex) ||
  165:                     ((*s_etat_processus).erreur_systeme != d_es))
  166:             {
  167:                 if ((*s_etat_processus).core == d_vrai)
  168:                 {
  169:                     if ((*s_etat_processus).langue == 'F')
  170:                     {
  171:                         printf("+++Information : "
  172:                                 "Génération du fichier rpl-core "
  173:                                 "[%d]\n", (int) getpid());
  174:                     }
  175:                     else
  176:                     {
  177:                         printf("+++Information : "
  178:                                 "Writing rpl-core file [%d]\n",
  179:                                 (int) getpid());
  180:                     }
  181: 
  182:                     rplcore(s_etat_processus);
  183: 
  184:                     if ((*s_etat_processus).langue == 'F')
  185:                     {
  186:                         printf("+++Information : "
  187:                                 "Processus tracé [%d]\n",
  188:                                 (int) getpid());
  189:                     }
  190:                     else
  191:                     {
  192:                         printf("+++Information : Done [%d]\n",
  193:                                 (int) getpid());
  194:                     }
  195: 
  196:                     fflush(stdout);
  197:                 }
  198: 
  199:                 if ((*s_etat_processus).langue == 'F')
  200:                 {
  201:                     printf("+++Fatal : Compilation impossible\n");
  202:                 }
  203:                 else
  204:                 {
  205:                     printf("+++Fatal : Compilation failed\n");
  206:                 }
  207: 
  208:                 for(j = 0; j < nb_variables; j++)
  209:                 {
  210:                     if (tableau[j].mutex != NULL)
  211:                     {
  212:                         pthread_mutex_unlock(tableau[j].mutex);
  213:                     }
  214:                 }
  215: 
  216:                 free(tableau);
  217:                 return(d_erreur);
  218:             }
  219: 
  220:             // Modification de la variable. Il n'existe à cet instant
  221:             // que des variables de niveau 0.
  222: 
  223:             if (recherche_variable(s_etat_processus, tableau[i].nom) ==
  224:                     d_faux)
  225:             {
  226:                 if ((*s_etat_processus).langue == 'F')
  227:                 {
  228:                     printf("+++Fatal : Compilation impossible\n");
  229:                 }
  230:                 else
  231:                 {
  232:                     printf("+++Fatal : Compilation failed\n");
  233:                 }
  234: 
  235:                 for(j = 0; j < nb_variables; j++)
  236:                 {
  237:                     if (tableau[j].mutex != NULL)
  238:                     {
  239:                         pthread_mutex_unlock(tableau[j].mutex);
  240:                     }
  241:                 }
  242: 
  243:                 free(tableau);
  244:                 return(d_erreur);
  245:             }
  246: 
  247:             liberation(s_etat_processus, tableau[i].objet);
  248: 
  249:             if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  250:                     &((*(*s_etat_processus).pointeur_variable_courante).objet))
  251:                     == d_erreur)
  252:             {
  253:                 if ((*s_etat_processus).langue == 'F')
  254:                 {
  255:                     printf("+++Fatal : Compilation impossible\n");
  256:                 }
  257:                 else
  258:                 {
  259:                     printf("+++Fatal : Compilation failed\n");
  260:                 }
  261: 
  262:                 for(j = 0; j < nb_variables; j++)
  263:                 {
  264:                     if (tableau[j].mutex != NULL)
  265:                     {
  266:                         pthread_mutex_unlock(tableau[j].mutex);
  267:                     }
  268:                 }
  269: 
  270:                 free(tableau);
  271:                 return(d_erreur);
  272:             }
  273: 
  274:             (*(*s_etat_processus).pointeur_variable_courante).origine = 'E';
  275:             free((*s_etat_processus).instruction_courante);
  276: 
  277:             if (point_entree == i)
  278:             {
  279:                 programme_principal = (*(*s_etat_processus)
  280:                         .pointeur_variable_courante).objet;
  281:             }
  282:         }
  283:     }
  284: 
  285:     if (point_entree == -1)
  286:     {
  287:         if ((*s_etat_processus).langue == 'F')
  288:         {
  289:             printf("+++Fatal : Compilation impossible\n");
  290:         }
  291:         else
  292:         {
  293:             printf("+++Fatal : Compilation failed\n");
  294:         }
  295: 
  296:         for(j = 0; j < nb_variables; j++)
  297:         {
  298:             if (tableau[j].mutex != NULL)
  299:             {
  300:                 pthread_mutex_unlock(tableau[j].mutex);
  301:             }
  302:         }
  303: 
  304:         free(tableau);
  305:         return(d_erreur);
  306:     }
  307: 
  308:     if ((*s_etat_processus).debug == d_vrai)
  309:     {
  310:         if (((*s_etat_processus).type_debug &
  311:                 d_debug_analyse) != 0)
  312:         {
  313:             printf("\n");
  314: 
  315:             if ((*s_etat_processus).langue == 'F')
  316:             {
  317:                 printf("[%d] Compilation achevée\n", (int) getpid());
  318:             }
  319:             else
  320:             {
  321:                 printf("[%d] Compilation done\n", (int) getpid());
  322:             }
  323: 
  324:             printf("\n");
  325:             fflush(stdout);
  326:         }
  327:     }
  328: 
  329:     (*s_etat_processus).retour_routine_evaluation = 'Y';
  330: 
  331:     free((*s_etat_processus).definitions_chainees);
  332: 
  333:     if (((*s_etat_processus).definitions_chainees =
  334:             malloc(sizeof(unsigned char))) == NULL)
  335:     {
  336:         if ((*s_etat_processus).langue == 'F')
  337:         {
  338:             printf("+++Fatal : Compilation impossible\n");
  339:         }
  340:         else
  341:         {
  342:             printf("+++Fatal : Compilation failed\n");
  343:         }
  344: 
  345:         for(j = 0; j < nb_variables; j++)
  346:         {
  347:             if (tableau[j].mutex != NULL)
  348:             {
  349:                 pthread_mutex_unlock(tableau[j].mutex);
  350:             }
  351:         }
  352: 
  353:         free(tableau);
  354:         return(d_erreur);
  355:     }
  356: 
  357:     (*s_etat_processus).definitions_chainees[0] = d_code_fin_chaine;
  358:     (*s_etat_processus).longueur_definitions_chainees = 0;
  359:     (*s_etat_processus).evaluation_expression_compilee = 'Y';
  360: 
  361:     if ((*s_etat_processus).profilage == d_vrai)
  362:     {
  363:         profilage(s_etat_processus, tableau[point_entree].nom);
  364:     }
  365: 
  366:     if ((*s_etat_processus).erreur_systeme != d_es)
  367:     {
  368:         if ((*s_etat_processus).langue == 'F')
  369:         {
  370:             printf("+++Système : Mémoire insuffisante\n");
  371:         }
  372:         else
  373:         {
  374:             printf("+++System : Not enough memory\n");
  375:         }
  376: 
  377:         for(j = 0; j < nb_variables; j++)
  378:         {
  379:             if (tableau[j].mutex != NULL)
  380:             {
  381:                 pthread_mutex_unlock(tableau[j].mutex);
  382:             }
  383:         }
  384: 
  385:         free(tableau);
  386:         return(d_erreur);
  387:     }
  388: 
  389:     for(j = 0; j < nb_variables; j++)
  390:     {
  391:         if (tableau[j].mutex != NULL)
  392:         {
  393:             pthread_mutex_unlock(tableau[j].mutex);
  394:         }
  395:     }
  396: 
  397:     free(tableau);
  398: 
  399:     erreur = evaluation(s_etat_processus, programme_principal, 'E');
  400: 
  401:     if ((*s_etat_processus).profilage == d_vrai)
  402:     {
  403:         profilage(s_etat_processus, NULL);
  404:     }
  405: 
  406:     (*s_etat_processus).mode_execution_programme = 'N';
  407: 
  408:     if (((*s_etat_processus).erreur_execution != d_ex) ||
  409:             ((*s_etat_processus).exception != d_ep) ||
  410:             ((*s_etat_processus).erreur_systeme != d_es))
  411:     {
  412:         printf("%s [%d]\n", message = messages(s_etat_processus),
  413:                 (int) getpid());
  414: 
  415:         if (test_cfsf(s_etat_processus, 51) == d_faux)
  416:         {
  417:             printf("%s", ds_beep);
  418:         }
  419: 
  420:         free(message);
  421:     }
  422: 
  423:     return(erreur);
  424: }
  425: 
  426: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>