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