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

1.1       bertrand    1: /*
                      2: ================================================================================
1.83      bertrand    3:   RPL/2 (R) version 4.1.32
1.84    ! bertrand    4:   Copyright (C) 1989-2020 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
1.74      bertrand   39: sequenceur_optimise(struct_processus *s_etat_processus, struct_liste_chainee
                     40:        *l_bibliotheques)
1.1       bertrand   41: {
1.49      bertrand   42:    integer8                    adresse_point_entree;
                     43:    integer8                    i;
1.50      bertrand   44:    integer8                    j;
1.49      bertrand   45:    integer8                    nb_variables;
                     46:    integer8                    point_entree;
1.1       bertrand   47: 
1.24      bertrand   48:    logical1                    erreur;
1.1       bertrand   49: 
1.24      bertrand   50:    struct_objet                *programme_principal;
1.1       bertrand   51: 
1.24      bertrand   52:    struct_tableau_variables    *tableau;
                     53: 
                     54:    unsigned char               *message;
1.28      bertrand   55:    unsigned char               registre;
1.24      bertrand   56: 
1.1       bertrand   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:        {
1.28      bertrand   63:            printf("+++Compilation [%d]\n", (int) getpid());
1.1       bertrand   64:        }
                     65:        else
                     66:        {
1.28      bertrand   67:            printf("+++Compilation [%d]\n", (int) getpid());
1.1       bertrand   68:        }
                     69: 
                     70:        printf("\n");
                     71:        fflush(stdout);
                     72:    }
                     73: 
                     74:    point_entree = -1;
                     75:    adresse_point_entree = 0;
1.34      bertrand   76:    programme_principal = NULL;
1.1       bertrand   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: 
1.44      bertrand   83:    nb_variables = nombre_variables(s_etat_processus);
1.24      bertrand   84: 
1.49      bertrand   85:    if ((tableau = malloc(((size_t) nb_variables) *
                     86:            sizeof(struct_tableau_variables))) == NULL)
1.24      bertrand   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: 
1.44      bertrand   97:        liberation_mutexes_arbre_variables_partagees(s_etat_processus,
                     98:                (*(*s_etat_processus).s_arbre_variables_partagees));
1.24      bertrand   99:        return(d_erreur);
                    100:    }
                    101: 
1.50      bertrand  102:    nb_variables = liste_variables(s_etat_processus, tableau);
                    103: 
1.24      bertrand  104:    for(i = 0; i < nb_variables; i++)
1.1       bertrand  105:    {
1.24      bertrand  106:        if (tableau[i].niveau == 0)
1.1       bertrand  107:        {
                    108:            // Variables qui contiennent les points d'entrée des définitions.
                    109: 
1.49      bertrand  110:            (*s_etat_processus).position_courante = (*((integer8 *)
1.24      bertrand  111:                    (*(tableau[i].objet)).objet));
1.1       bertrand  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:                {
1.28      bertrand  134:                    printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  135:                }
                    136:                else
                    137:                {
1.28      bertrand  138:                    printf("+++Fatal : Compilation failed\n");
1.1       bertrand  139:                }
                    140: 
1.50      bertrand  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: 
1.24      bertrand  149:                free(tableau);
1.1       bertrand  150:                return(d_erreur);
                    151:            }
                    152: 
1.28      bertrand  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';
1.60      bertrand  160:            (*s_etat_processus).type_en_cours = NON;
1.1       bertrand  161:            recherche_type(s_etat_processus);
1.28      bertrand  162:            (*s_etat_processus).autorisation_nom_implicite = registre;
1.1       bertrand  163: 
                    164:            if (((*s_etat_processus).erreur_execution != d_ex) ||
                    165:                    ((*s_etat_processus).erreur_systeme != d_es))
                    166:            {
1.28      bertrand  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: 
1.1       bertrand  199:                if ((*s_etat_processus).langue == 'F')
                    200:                {
1.28      bertrand  201:                    printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  202:                }
                    203:                else
                    204:                {
1.28      bertrand  205:                    printf("+++Fatal : Compilation failed\n");
1.1       bertrand  206:                }
                    207: 
1.50      bertrand  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: 
1.24      bertrand  216:                free(tableau);
1.1       bertrand  217:                return(d_erreur);
                    218:            }
                    219: 
1.24      bertrand  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:                {
1.28      bertrand  228:                    printf("+++Fatal : Compilation impossible\n");
1.24      bertrand  229:                }
                    230:                else
                    231:                {
1.28      bertrand  232:                    printf("+++Fatal : Compilation failed\n");
1.24      bertrand  233:                }
                    234: 
1.50      bertrand  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: 
1.24      bertrand  243:                free(tableau);
                    244:                return(d_erreur);
                    245:            }
                    246: 
                    247:            liberation(s_etat_processus, tableau[i].objet);
1.1       bertrand  248: 
                    249:            if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
1.24      bertrand  250:                    &((*(*s_etat_processus).pointeur_variable_courante).objet))
1.1       bertrand  251:                    == d_erreur)
                    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.50      bertrand  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: 
1.24      bertrand  270:                free(tableau);
1.1       bertrand  271:                return(d_erreur);
                    272:            }
                    273: 
1.24      bertrand  274:            (*(*s_etat_processus).pointeur_variable_courante).origine = 'E';
1.1       bertrand  275:            free((*s_etat_processus).instruction_courante);
1.24      bertrand  276: 
                    277:            if (point_entree == i)
                    278:            {
                    279:                programme_principal = (*(*s_etat_processus)
                    280:                        .pointeur_variable_courante).objet;
                    281:            }
1.1       bertrand  282:        }
                    283:    }
                    284: 
                    285:    if (point_entree == -1)
                    286:    {
                    287:        if ((*s_etat_processus).langue == 'F')
                    288:        {
1.28      bertrand  289:            printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  290:        }
                    291:        else
                    292:        {
1.28      bertrand  293:            printf("+++Fatal : Compilation failed\n");
1.1       bertrand  294:        }
                    295: 
1.50      bertrand  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: 
1.24      bertrand  304:        free(tableau);
1.1       bertrand  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:            {
1.28      bertrand  317:                printf("[%d] Compilation achevée\n", (int) getpid());
1.1       bertrand  318:            }
                    319:            else
                    320:            {
1.28      bertrand  321:                printf("[%d] Compilation done\n", (int) getpid());
1.1       bertrand  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:        {
1.28      bertrand  338:            printf("+++Fatal : Compilation impossible\n");
1.1       bertrand  339:        }
                    340:        else
                    341:        {
1.28      bertrand  342:            printf("+++Fatal : Compilation failed\n");
1.1       bertrand  343:        }
                    344: 
1.50      bertrand  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: 
1.24      bertrand  353:        free(tableau);
1.1       bertrand  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:    {
1.24      bertrand  363:        profilage(s_etat_processus, tableau[point_entree].nom);
1.1       bertrand  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: 
1.50      bertrand  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: 
1.24      bertrand  385:        free(tableau);
1.1       bertrand  386:        return(d_erreur);
                    387:    }
                    388: 
1.50      bertrand  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: 
1.24      bertrand  397:    free(tableau);
                    398: 
                    399:    erreur = evaluation(s_etat_processus, programme_principal, 'E');
1.1       bertrand  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>