File:  [local] / rpl / src / optimisation.c
Revision 1.37: download - view: text, annotated - select for diffs - revision graph
Thu Jan 5 10:19:05 2012 UTC (12 years, 4 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_5, HEAD
Mise à jour du copyright.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.5
    4:   Copyright (C) 1989-2012 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)
   40: {
   41:     int                         i;
   42:     int                         nb_variables;
   43:     int                         point_entree;
   44: 
   45:     logical1                    erreur;
   46: 
   47:     struct_objet                *programme_principal;
   48: 
   49:     struct_tableau_variables    *tableau;
   50: 
   51:     unsigned char               *message;
   52:     unsigned char               registre;
   53: 
   54:     unsigned long               adresse_point_entree;
   55: 
   56:     if ((*s_etat_processus).debug == d_vrai)
   57:         if (((*s_etat_processus).type_debug &
   58:                 d_debug_analyse) != 0)
   59:     {
   60:         if ((*s_etat_processus).langue == 'F')
   61:         {
   62:             printf("+++Compilation [%d]\n", (int) getpid());
   63:         }
   64:         else
   65:         {
   66:             printf("+++Compilation [%d]\n", (int) getpid());
   67:         }
   68: 
   69:         printf("\n");
   70:         fflush(stdout);
   71:     }
   72: 
   73:     point_entree = -1;
   74:     adresse_point_entree = 0;
   75:     programme_principal = NULL;
   76: 
   77:     empilement_pile_systeme(s_etat_processus);
   78:     (*(*s_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
   79:     (*s_etat_processus).autorisation_empilement_programme = 'Y';
   80:     (*s_etat_processus).mode_execution_programme = 'N';
   81: 
   82:     nb_variables = nombre_variables(s_etat_processus,
   83:             (*s_etat_processus).s_arbre_variables);
   84: 
   85:     if ((tableau = malloc(nb_variables * sizeof(struct_tableau_variables)))
   86:             == 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:         return(d_erreur);
   98:     }
   99: 
  100:     liste_variables(s_etat_processus, tableau, 0,
  101:             (*s_etat_processus).s_arbre_variables);
  102: 
  103:     for(i = 0; i < nb_variables; i++)
  104:     {
  105:         if (tableau[i].niveau == 0)
  106:         {
  107:             // Variables qui contiennent les points d'entrée des définitions.
  108: 
  109:             (*s_etat_processus).position_courante = (*((unsigned long *)
  110:                     (*(tableau[i].objet)).objet));
  111: 
  112:             if (point_entree == -1)
  113:             {
  114:                 adresse_point_entree = (*s_etat_processus).position_courante;
  115:                 point_entree = i;
  116:             }
  117:             else
  118:             {
  119:                 if ((*s_etat_processus).position_courante <
  120:                         adresse_point_entree)
  121:                 {
  122:                     adresse_point_entree = (*s_etat_processus)
  123:                             .position_courante;
  124:                     point_entree = i;
  125:                 }
  126:             }
  127: 
  128:             if ((erreur = recherche_instruction_suivante(s_etat_processus))
  129:                     == d_erreur)
  130:             {
  131:                 if ((*s_etat_processus).langue == 'F')
  132:                 {
  133:                     printf("+++Fatal : Compilation impossible\n");
  134:                 }
  135:                 else
  136:                 {
  137:                     printf("+++Fatal : Compilation failed\n");
  138:                 }
  139: 
  140:                 free(tableau);
  141:                 return(d_erreur);
  142:             }
  143: 
  144:             // Il faut désactiver la vérification des variables
  145:             // implicites car aucune variable de niveau strictement
  146:             // positif étant créée, la fonction recherche_type() pourrait
  147:             // échouer.
  148: 
  149:             registre = (*s_etat_processus).autorisation_nom_implicite;
  150:             (*s_etat_processus).autorisation_nom_implicite = 'Y';
  151:             recherche_type(s_etat_processus);
  152:             (*s_etat_processus).autorisation_nom_implicite = registre;
  153: 
  154:             if (((*s_etat_processus).erreur_execution != d_ex) ||
  155:                     ((*s_etat_processus).erreur_systeme != d_es))
  156:             {
  157:                 if ((*s_etat_processus).core == d_vrai)
  158:                 {
  159:                     if ((*s_etat_processus).langue == 'F')
  160:                     {
  161:                         printf("+++Information : "
  162:                                 "Génération du fichier rpl-core "
  163:                                 "[%d]\n", (int) getpid());
  164:                     }
  165:                     else
  166:                     {
  167:                         printf("+++Information : "
  168:                                 "Writing rpl-core file [%d]\n",
  169:                                 (int) getpid());
  170:                     }
  171: 
  172:                     rplcore(s_etat_processus);
  173: 
  174:                     if ((*s_etat_processus).langue == 'F')
  175:                     {
  176:                         printf("+++Information : "
  177:                                 "Processus tracé [%d]\n",
  178:                                 (int) getpid());
  179:                     }
  180:                     else
  181:                     {
  182:                         printf("+++Information : Done [%d]\n",
  183:                                 (int) getpid());
  184:                     }
  185: 
  186:                     fflush(stdout);
  187:                 }
  188: 
  189:                 if ((*s_etat_processus).langue == 'F')
  190:                 {
  191:                     printf("+++Fatal : Compilation impossible\n");
  192:                 }
  193:                 else
  194:                 {
  195:                     printf("+++Fatal : Compilation failed\n");
  196:                 }
  197: 
  198:                 free(tableau);
  199:                 return(d_erreur);
  200:             }
  201: 
  202:             // Modification de la variable. Il n'existe à cet instant
  203:             // que des variables de niveau 0.
  204: 
  205:             if (recherche_variable(s_etat_processus, tableau[i].nom) ==
  206:                     d_faux)
  207:             {
  208:                 if ((*s_etat_processus).langue == 'F')
  209:                 {
  210:                     printf("+++Fatal : Compilation impossible\n");
  211:                 }
  212:                 else
  213:                 {
  214:                     printf("+++Fatal : Compilation failed\n");
  215:                 }
  216: 
  217:                 free(tableau);
  218:                 return(d_erreur);
  219:             }
  220: 
  221:             liberation(s_etat_processus, tableau[i].objet);
  222: 
  223:             if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  224:                     &((*(*s_etat_processus).pointeur_variable_courante).objet))
  225:                     == d_erreur)
  226:             {
  227:                 if ((*s_etat_processus).langue == 'F')
  228:                 {
  229:                     printf("+++Fatal : Compilation impossible\n");
  230:                 }
  231:                 else
  232:                 {
  233:                     printf("+++Fatal : Compilation failed\n");
  234:                 }
  235: 
  236:                 free(tableau);
  237:                 return(d_erreur);
  238:             }
  239: 
  240:             (*(*s_etat_processus).pointeur_variable_courante).origine = 'E';
  241:             free((*s_etat_processus).instruction_courante);
  242: 
  243:             if (point_entree == i)
  244:             {
  245:                 programme_principal = (*(*s_etat_processus)
  246:                         .pointeur_variable_courante).objet;
  247:             }
  248:         }
  249:     }
  250: 
  251:     if (point_entree == -1)
  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:         free(tableau);
  263:         return(d_erreur);
  264:     }
  265: 
  266:     if ((*s_etat_processus).debug == d_vrai)
  267:     {
  268:         if (((*s_etat_processus).type_debug &
  269:                 d_debug_analyse) != 0)
  270:         {
  271:             printf("\n");
  272: 
  273:             if ((*s_etat_processus).langue == 'F')
  274:             {
  275:                 printf("[%d] Compilation achevée\n", (int) getpid());
  276:             }
  277:             else
  278:             {
  279:                 printf("[%d] Compilation done\n", (int) getpid());
  280:             }
  281: 
  282:             printf("\n");
  283:             fflush(stdout);
  284:         }
  285:     }
  286: 
  287:     (*s_etat_processus).retour_routine_evaluation = 'Y';
  288: 
  289:     free((*s_etat_processus).definitions_chainees);
  290: 
  291:     if (((*s_etat_processus).definitions_chainees =
  292:             malloc(sizeof(unsigned char))) == NULL)
  293:     {
  294:         if ((*s_etat_processus).langue == 'F')
  295:         {
  296:             printf("+++Fatal : Compilation impossible\n");
  297:         }
  298:         else
  299:         {
  300:             printf("+++Fatal : Compilation failed\n");
  301:         }
  302: 
  303:         free(tableau);
  304:         return(d_erreur);
  305:     }
  306: 
  307:     (*s_etat_processus).definitions_chainees[0] = d_code_fin_chaine;
  308:     (*s_etat_processus).longueur_definitions_chainees = 0;
  309:     (*s_etat_processus).evaluation_expression_compilee = 'Y';
  310: 
  311:     if ((*s_etat_processus).profilage == d_vrai)
  312:     {
  313:         profilage(s_etat_processus, tableau[point_entree].nom);
  314:     }
  315: 
  316:     if ((*s_etat_processus).erreur_systeme != d_es)
  317:     {
  318:         if ((*s_etat_processus).langue == 'F')
  319:         {
  320:             printf("+++Système : Mémoire insuffisante\n");
  321:         }
  322:         else
  323:         {
  324:             printf("+++System : Not enough memory\n");
  325:         }
  326: 
  327:         free(tableau);
  328:         return(d_erreur);
  329:     }
  330: 
  331:     free(tableau);
  332: 
  333:     erreur = evaluation(s_etat_processus, programme_principal, 'E');
  334: 
  335:     if ((*s_etat_processus).profilage == d_vrai)
  336:     {
  337:         profilage(s_etat_processus, NULL);
  338:     }
  339: 
  340:     (*s_etat_processus).mode_execution_programme = 'N';
  341: 
  342:     if (((*s_etat_processus).erreur_execution != d_ex) ||
  343:             ((*s_etat_processus).exception != d_ep) ||
  344:             ((*s_etat_processus).erreur_systeme != d_es))
  345:     {
  346:         printf("%s [%d]\n", message = messages(s_etat_processus),
  347:                 (int) getpid());
  348: 
  349:         if (test_cfsf(s_etat_processus, 51) == d_faux)
  350:         {
  351:             printf("%s", ds_beep);
  352:         }
  353: 
  354:         free(message);
  355:     }
  356: 
  357:     return(erreur);
  358: }
  359: 
  360: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>