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

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

CVSweb interface <joel.bertrand@systella.fr>