Annotation of rpl/src/optimisation.c, revision 1.49

1.1       bertrand    1: /*
                      2: ================================================================================
1.48      bertrand    3:   RPL/2 (R) version 4.1.13
1.47      bertrand    4:   Copyright (C) 1989-2013 Dr. BERTRAND Joël
1.1       bertrand    5: 
                      6:   This file is part of RPL/2.
                      7: 
                      8:   RPL/2 is free software; you can redistribute it and/or modify it
                      9:   under the terms of the CeCILL V2 License as published by the french
                     10:   CEA, CNRS and INRIA.
                     11:  
                     12:   RPL/2 is distributed in the hope that it will be useful, but WITHOUT
                     13:   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
                     14:   FITNESS FOR A PARTICULAR PURPOSE.  See the CeCILL V2 License
                     15:   for more details.
                     16:  
                     17:   You should have received a copy of the CeCILL License
                     18:   along with RPL/2. If not, write to info@cecill.info.
                     19: ================================================================================
                     20: */
                     21: 
                     22: 
1.13      bertrand   23: #include "rpl-conv.h"
1.1       bertrand   24: 
                     25: 
                     26: /*
                     27: ================================================================================
1.28      bertrand   28:   Boucle principale optimisée de l'interprète RPL/2
1.1       bertrand   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: {
1.49    ! bertrand   41:    integer8                    adresse_point_entree;
        !            42:    integer8                    i;
        !            43:    integer8                    nb_variables;
        !            44:    integer8                    point_entree;
1.1       bertrand   45: 
1.24      bertrand   46:    logical1                    erreur;
1.1       bertrand   47: 
1.24      bertrand   48:    struct_objet                *programme_principal;
1.1       bertrand   49: 
1.24      bertrand   50:    struct_tableau_variables    *tableau;
                     51: 
                     52:    unsigned char               *message;
1.28      bertrand   53:    unsigned char               registre;
1.24      bertrand   54: 
1.1       bertrand   55:    if ((*s_etat_processus).debug == d_vrai)
                     56:        if (((*s_etat_processus).type_debug &
                     57:                d_debug_analyse) != 0)
                     58:    {
                     59:        if ((*s_etat_processus).langue == 'F')
                     60:        {
1.28      bertrand   61:            printf("+++Compilation [%d]\n", (int) getpid());
1.1       bertrand   62:        }
                     63:        else
                     64:        {
1.28      bertrand   65:            printf("+++Compilation [%d]\n", (int) getpid());
1.1       bertrand   66:        }
                     67: 
                     68:        printf("\n");
                     69:        fflush(stdout);
                     70:    }
                     71: 
                     72:    point_entree = -1;
                     73:    adresse_point_entree = 0;
1.34      bertrand   74:    programme_principal = NULL;
1.1       bertrand   75: 
                     76:    empilement_pile_systeme(s_etat_processus);
                     77:    (*(*s_etat_processus).l_base_pile_systeme).retour_definition = 'Y';
                     78:    (*s_etat_processus).autorisation_empilement_programme = 'Y';
                     79:    (*s_etat_processus).mode_execution_programme = 'N';
                     80: 
1.44      bertrand   81:    nb_variables = nombre_variables(s_etat_processus);
1.24      bertrand   82: 
1.49    ! bertrand   83:    if ((tableau = malloc(((size_t) nb_variables) *
        !            84:            sizeof(struct_tableau_variables))) == NULL)
1.24      bertrand   85:    {
                     86:        if ((*s_etat_processus).langue == 'F')
                     87:        {
                     88:            printf("+++Système : Mémoire insuffisante\n");
                     89:        }
                     90:        else
                     91:        {
                     92:            printf("+++System : Not enough memory\n");
                     93:        }
                     94: 
1.44      bertrand   95:        liberation_mutexes_arbre_variables_partagees(s_etat_processus,
                     96:                (*(*s_etat_processus).s_arbre_variables_partagees));
1.24      bertrand   97:        return(d_erreur);
                     98:    }
                     99: 
1.44      bertrand  100:    liste_variables(s_etat_processus, tableau);
1.24      bertrand  101: 
                    102:    for(i = 0; i < nb_variables; i++)
1.1       bertrand  103:    {
1.24      bertrand  104:        if (tableau[i].niveau == 0)
1.1       bertrand  105:        {
                    106:            // Variables qui contiennent les points d'entrée des définitions.
                    107: 
1.49    ! bertrand  108:            (*s_etat_processus).position_courante = (*((integer8 *)
1.24      bertrand  109:                    (*(tableau[i].objet)).objet));
1.1       bertrand  110: 
                    111:            if (point_entree == -1)
                    112:            {
                    113:                adresse_point_entree = (*s_etat_processus).position_courante;
                    114:                point_entree = i;
                    115:            }
                    116:            else
                    117:            {
                    118:                if ((*s_etat_processus).position_courante <
                    119:                        adresse_point_entree)
                    120:                {
                    121:                    adresse_point_entree = (*s_etat_processus)
                    122:                            .position_courante;
                    123:                    point_entree = i;
                    124:                }
                    125:            }
                    126: 
                    127:            if ((erreur = recherche_instruction_suivante(s_etat_processus))
                    128:                    == d_erreur)
                    129:            {
                    130:                if ((*s_etat_processus).langue == 'F')
                    131:                {
1.28      bertrand  132:                    printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  133:                }
                    134:                else
                    135:                {
1.28      bertrand  136:                    printf("+++Fatal : Compilation failed\n");
1.1       bertrand  137:                }
                    138: 
1.24      bertrand  139:                free(tableau);
1.1       bertrand  140:                return(d_erreur);
                    141:            }
                    142: 
1.28      bertrand  143:            // Il faut désactiver la vérification des variables
                    144:            // implicites car aucune variable de niveau strictement
                    145:            // positif étant créée, la fonction recherche_type() pourrait
                    146:            // échouer.
                    147: 
                    148:            registre = (*s_etat_processus).autorisation_nom_implicite;
                    149:            (*s_etat_processus).autorisation_nom_implicite = 'Y';
1.1       bertrand  150:            recherche_type(s_etat_processus);
1.28      bertrand  151:            (*s_etat_processus).autorisation_nom_implicite = registre;
1.1       bertrand  152: 
                    153:            if (((*s_etat_processus).erreur_execution != d_ex) ||
                    154:                    ((*s_etat_processus).erreur_systeme != d_es))
                    155:            {
1.28      bertrand  156:                if ((*s_etat_processus).core == d_vrai)
                    157:                {
                    158:                    if ((*s_etat_processus).langue == 'F')
                    159:                    {
                    160:                        printf("+++Information : "
                    161:                                "Génération du fichier rpl-core "
                    162:                                "[%d]\n", (int) getpid());
                    163:                    }
                    164:                    else
                    165:                    {
                    166:                        printf("+++Information : "
                    167:                                "Writing rpl-core file [%d]\n",
                    168:                                (int) getpid());
                    169:                    }
                    170: 
                    171:                    rplcore(s_etat_processus);
                    172: 
                    173:                    if ((*s_etat_processus).langue == 'F')
                    174:                    {
                    175:                        printf("+++Information : "
                    176:                                "Processus tracé [%d]\n",
                    177:                                (int) getpid());
                    178:                    }
                    179:                    else
                    180:                    {
                    181:                        printf("+++Information : Done [%d]\n",
                    182:                                (int) getpid());
                    183:                    }
                    184: 
                    185:                    fflush(stdout);
                    186:                }
                    187: 
1.1       bertrand  188:                if ((*s_etat_processus).langue == 'F')
                    189:                {
1.28      bertrand  190:                    printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  191:                }
                    192:                else
                    193:                {
1.28      bertrand  194:                    printf("+++Fatal : Compilation failed\n");
1.1       bertrand  195:                }
                    196: 
1.24      bertrand  197:                free(tableau);
1.1       bertrand  198:                return(d_erreur);
                    199:            }
                    200: 
1.24      bertrand  201:            // Modification de la variable. Il n'existe à cet instant
                    202:            // que des variables de niveau 0.
                    203: 
                    204:            if (recherche_variable(s_etat_processus, tableau[i].nom) ==
                    205:                    d_faux)
                    206:            {
                    207:                if ((*s_etat_processus).langue == 'F')
                    208:                {
1.28      bertrand  209:                    printf("+++Fatal : Compilation impossible\n");
1.24      bertrand  210:                }
                    211:                else
                    212:                {
1.28      bertrand  213:                    printf("+++Fatal : Compilation failed\n");
1.24      bertrand  214:                }
                    215: 
                    216:                free(tableau);
                    217:                return(d_erreur);
                    218:            }
                    219: 
                    220:            liberation(s_etat_processus, tableau[i].objet);
1.1       bertrand  221: 
                    222:            if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1.24      bertrand  223:                    &((*(*s_etat_processus).pointeur_variable_courante).objet))
1.1       bertrand  224:                    == d_erreur)
                    225:            {
                    226:                if ((*s_etat_processus).langue == 'F')
                    227:                {
1.28      bertrand  228:                    printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  229:                }
                    230:                else
                    231:                {
1.28      bertrand  232:                    printf("+++Fatal : Compilation failed\n");
1.1       bertrand  233:                }
                    234: 
1.24      bertrand  235:                free(tableau);
1.1       bertrand  236:                return(d_erreur);
                    237:            }
                    238: 
1.24      bertrand  239:            (*(*s_etat_processus).pointeur_variable_courante).origine = 'E';
1.1       bertrand  240:            free((*s_etat_processus).instruction_courante);
1.24      bertrand  241: 
                    242:            if (point_entree == i)
                    243:            {
                    244:                programme_principal = (*(*s_etat_processus)
                    245:                        .pointeur_variable_courante).objet;
                    246:            }
1.1       bertrand  247:        }
                    248:    }
                    249: 
                    250:    if (point_entree == -1)
                    251:    {
                    252:        if ((*s_etat_processus).langue == 'F')
                    253:        {
1.28      bertrand  254:            printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  255:        }
                    256:        else
                    257:        {
1.28      bertrand  258:            printf("+++Fatal : Compilation failed\n");
1.1       bertrand  259:        }
                    260: 
1.24      bertrand  261:        free(tableau);
1.1       bertrand  262:        return(d_erreur);
                    263:    }
                    264: 
                    265:    if ((*s_etat_processus).debug == d_vrai)
                    266:    {
                    267:        if (((*s_etat_processus).type_debug &
                    268:                d_debug_analyse) != 0)
                    269:        {
                    270:            printf("\n");
                    271: 
                    272:            if ((*s_etat_processus).langue == 'F')
                    273:            {
1.28      bertrand  274:                printf("[%d] Compilation achevée\n", (int) getpid());
1.1       bertrand  275:            }
                    276:            else
                    277:            {
1.28      bertrand  278:                printf("[%d] Compilation done\n", (int) getpid());
1.1       bertrand  279:            }
                    280: 
                    281:            printf("\n");
                    282:            fflush(stdout);
                    283:        }
                    284:    }
                    285: 
                    286:    (*s_etat_processus).retour_routine_evaluation = 'Y';
                    287: 
                    288:    free((*s_etat_processus).definitions_chainees);
                    289: 
                    290:    if (((*s_etat_processus).definitions_chainees =
                    291:            malloc(sizeof(unsigned char))) == NULL)
                    292:    {
                    293:        if ((*s_etat_processus).langue == 'F')
                    294:        {
1.28      bertrand  295:            printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  296:        }
                    297:        else
                    298:        {
1.28      bertrand  299:            printf("+++Fatal : Compilation failed\n");
1.1       bertrand  300:        }
                    301: 
1.24      bertrand  302:        free(tableau);
1.1       bertrand  303:        return(d_erreur);
                    304:    }
                    305: 
                    306:    (*s_etat_processus).definitions_chainees[0] = d_code_fin_chaine;
                    307:    (*s_etat_processus).longueur_definitions_chainees = 0;
                    308:    (*s_etat_processus).evaluation_expression_compilee = 'Y';
                    309: 
                    310:    if ((*s_etat_processus).profilage == d_vrai)
                    311:    {
1.24      bertrand  312:        profilage(s_etat_processus, tableau[point_entree].nom);
1.1       bertrand  313:    }
                    314: 
                    315:    if ((*s_etat_processus).erreur_systeme != d_es)
                    316:    {
                    317:        if ((*s_etat_processus).langue == 'F')
                    318:        {
                    319:            printf("+++Système : Mémoire insuffisante\n");
                    320:        }
                    321:        else
                    322:        {
                    323:            printf("+++System : Not enough memory\n");
                    324:        }
                    325: 
1.24      bertrand  326:        free(tableau);
1.1       bertrand  327:        return(d_erreur);
                    328:    }
                    329: 
1.24      bertrand  330:    free(tableau);
                    331: 
                    332:    erreur = evaluation(s_etat_processus, programme_principal, 'E');
1.1       bertrand  333: 
                    334:    if ((*s_etat_processus).profilage == d_vrai)
                    335:    {
                    336:        profilage(s_etat_processus, NULL);
                    337:    }
                    338: 
                    339:    (*s_etat_processus).mode_execution_programme = 'N';
                    340: 
                    341:    if (((*s_etat_processus).erreur_execution != d_ex) ||
                    342:            ((*s_etat_processus).exception != d_ep) ||
                    343:            ((*s_etat_processus).erreur_systeme != d_es))
                    344:    {
                    345:        printf("%s [%d]\n", message = messages(s_etat_processus),
                    346:                (int) getpid());
                    347: 
                    348:        if (test_cfsf(s_etat_processus, 51) == d_faux)
                    349:        {
                    350:            printf("%s", ds_beep);
                    351:        }
                    352: 
                    353:        free(message);
                    354:    }
                    355: 
                    356:    return(erreur);
                    357: }
                    358: 
                    359: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>