Annotation of rpl/src/optimisation.c, revision 1.32
1.1 bertrand 1: /*
2: ================================================================================
1.32 ! bertrand 3: RPL/2 (R) version 4.1.2
1.18 bertrand 4: Copyright (C) 1989-2011 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;
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.24 bertrand 81: nb_variables = nombre_variables(s_etat_processus,
82: (*s_etat_processus).s_arbre_variables);
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:
96: return(d_erreur);
97: }
98:
99: liste_variables(s_etat_processus, tableau, 0,
100: (*s_etat_processus).s_arbre_variables);
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:
108: (*s_etat_processus).position_courante = (*((unsigned long *)
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>