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