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

1.1       bertrand    1: /*
                      2: ================================================================================
1.43      bertrand    3:   RPL/2 (R) version 4.1.11
1.37      bertrand    4:   Copyright (C) 1989-2012 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.24      bertrand   41:    int                         i;
                     42:    int                         nb_variables;
                     43:    int                         point_entree;
1.1       bertrand   44: 
1.24      bertrand   45:    logical1                    erreur;
1.1       bertrand   46: 
1.24      bertrand   47:    struct_objet                *programme_principal;
1.1       bertrand   48: 
1.24      bertrand   49:    struct_tableau_variables    *tableau;
                     50: 
                     51:    unsigned char               *message;
1.28      bertrand   52:    unsigned char               registre;
1.24      bertrand   53: 
                     54:    unsigned long               adresse_point_entree;
1.1       bertrand   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:        {
1.28      bertrand   62:            printf("+++Compilation [%d]\n", (int) getpid());
1.1       bertrand   63:        }
                     64:        else
                     65:        {
1.28      bertrand   66:            printf("+++Compilation [%d]\n", (int) getpid());
1.1       bertrand   67:        }
                     68: 
                     69:        printf("\n");
                     70:        fflush(stdout);
                     71:    }
                     72: 
                     73:    point_entree = -1;
                     74:    adresse_point_entree = 0;
1.34      bertrand   75:    programme_principal = NULL;
1.1       bertrand   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: 
1.44    ! bertrand   82:    nb_variables = nombre_variables(s_etat_processus);
1.24      bertrand   83: 
                     84:    if ((tableau = malloc(nb_variables * sizeof(struct_tableau_variables)))
                     85:            == NULL)
                     86:    {
                     87:        if ((*s_etat_processus).langue == 'F')
                     88:        {
                     89:            printf("+++Système : Mémoire insuffisante\n");
                     90:        }
                     91:        else
                     92:        {
                     93:            printf("+++System : Not enough memory\n");
                     94:        }
                     95: 
1.44    ! bertrand   96:        liberation_mutexes_arbre_variables_partagees(s_etat_processus,
        !            97:                (*(*s_etat_processus).s_arbre_variables_partagees));
1.24      bertrand   98:        return(d_erreur);
                     99:    }
                    100: 
1.44    ! bertrand  101:    liste_variables(s_etat_processus, tableau);
1.24      bertrand  102: 
                    103:    for(i = 0; i < nb_variables; i++)
1.1       bertrand  104:    {
1.24      bertrand  105:        if (tableau[i].niveau == 0)
1.1       bertrand  106:        {
                    107:            // Variables qui contiennent les points d'entrée des définitions.
                    108: 
                    109:            (*s_etat_processus).position_courante = (*((unsigned long *)
1.24      bertrand  110:                    (*(tableau[i].objet)).objet));
1.1       bertrand  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:                {
1.28      bertrand  133:                    printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  134:                }
                    135:                else
                    136:                {
1.28      bertrand  137:                    printf("+++Fatal : Compilation failed\n");
1.1       bertrand  138:                }
                    139: 
1.24      bertrand  140:                free(tableau);
1.1       bertrand  141:                return(d_erreur);
                    142:            }
                    143: 
1.28      bertrand  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';
1.1       bertrand  151:            recherche_type(s_etat_processus);
1.28      bertrand  152:            (*s_etat_processus).autorisation_nom_implicite = registre;
1.1       bertrand  153: 
                    154:            if (((*s_etat_processus).erreur_execution != d_ex) ||
                    155:                    ((*s_etat_processus).erreur_systeme != d_es))
                    156:            {
1.28      bertrand  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: 
1.1       bertrand  189:                if ((*s_etat_processus).langue == 'F')
                    190:                {
1.28      bertrand  191:                    printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  192:                }
                    193:                else
                    194:                {
1.28      bertrand  195:                    printf("+++Fatal : Compilation failed\n");
1.1       bertrand  196:                }
                    197: 
1.24      bertrand  198:                free(tableau);
1.1       bertrand  199:                return(d_erreur);
                    200:            }
                    201: 
1.24      bertrand  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:                {
1.28      bertrand  210:                    printf("+++Fatal : Compilation impossible\n");
1.24      bertrand  211:                }
                    212:                else
                    213:                {
1.28      bertrand  214:                    printf("+++Fatal : Compilation failed\n");
1.24      bertrand  215:                }
                    216: 
                    217:                free(tableau);
                    218:                return(d_erreur);
                    219:            }
                    220: 
                    221:            liberation(s_etat_processus, tableau[i].objet);
1.1       bertrand  222: 
                    223:            if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1.24      bertrand  224:                    &((*(*s_etat_processus).pointeur_variable_courante).objet))
1.1       bertrand  225:                    == d_erreur)
                    226:            {
                    227:                if ((*s_etat_processus).langue == 'F')
                    228:                {
1.28      bertrand  229:                    printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  230:                }
                    231:                else
                    232:                {
1.28      bertrand  233:                    printf("+++Fatal : Compilation failed\n");
1.1       bertrand  234:                }
                    235: 
1.24      bertrand  236:                free(tableau);
1.1       bertrand  237:                return(d_erreur);
                    238:            }
                    239: 
1.24      bertrand  240:            (*(*s_etat_processus).pointeur_variable_courante).origine = 'E';
1.1       bertrand  241:            free((*s_etat_processus).instruction_courante);
1.24      bertrand  242: 
                    243:            if (point_entree == i)
                    244:            {
                    245:                programme_principal = (*(*s_etat_processus)
                    246:                        .pointeur_variable_courante).objet;
                    247:            }
1.1       bertrand  248:        }
                    249:    }
                    250: 
                    251:    if (point_entree == -1)
                    252:    {
                    253:        if ((*s_etat_processus).langue == 'F')
                    254:        {
1.28      bertrand  255:            printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  256:        }
                    257:        else
                    258:        {
1.28      bertrand  259:            printf("+++Fatal : Compilation failed\n");
1.1       bertrand  260:        }
                    261: 
1.24      bertrand  262:        free(tableau);
1.1       bertrand  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:            {
1.28      bertrand  275:                printf("[%d] Compilation achevée\n", (int) getpid());
1.1       bertrand  276:            }
                    277:            else
                    278:            {
1.28      bertrand  279:                printf("[%d] Compilation done\n", (int) getpid());
1.1       bertrand  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:        {
1.28      bertrand  296:            printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  297:        }
                    298:        else
                    299:        {
1.28      bertrand  300:            printf("+++Fatal : Compilation failed\n");
1.1       bertrand  301:        }
                    302: 
1.24      bertrand  303:        free(tableau);
1.1       bertrand  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:    {
1.24      bertrand  313:        profilage(s_etat_processus, tableau[point_entree].nom);
1.1       bertrand  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: 
1.24      bertrand  327:        free(tableau);
1.1       bertrand  328:        return(d_erreur);
                    329:    }
                    330: 
1.24      bertrand  331:    free(tableau);
                    332: 
                    333:    erreur = evaluation(s_etat_processus, programme_principal, 'E');
1.1       bertrand  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>