1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.27
4: Copyright (C) 1989-2017 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, struct_liste_chainee
40: *l_bibliotheques)
41: {
42: integer8 adresse_point_entree;
43: integer8 i;
44: integer8 j;
45: integer8 nb_variables;
46: integer8 point_entree;
47:
48: logical1 erreur;
49:
50: struct_liste_chainee *l_bibliotheque_courante;
51: struct_liste_chainee *l_nouvelle_bibliotheque;
52:
53: struct_objet *programme_principal;
54:
55: struct_tableau_variables *tableau;
56:
57: unsigned char *message;
58: unsigned char registre;
59:
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: {
66: printf("+++Compilation [%d]\n", (int) getpid());
67: }
68: else
69: {
70: printf("+++Compilation [%d]\n", (int) getpid());
71: }
72:
73: printf("\n");
74: fflush(stdout);
75: }
76:
77: point_entree = -1;
78: adresse_point_entree = 0;
79: programme_principal = NULL;
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:
86: nb_variables = nombre_variables(s_etat_processus);
87:
88: if ((tableau = malloc(((size_t) nb_variables) *
89: sizeof(struct_tableau_variables))) == NULL)
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:
100: liberation_mutexes_arbre_variables_partagees(s_etat_processus,
101: (*(*s_etat_processus).s_arbre_variables_partagees));
102: return(d_erreur);
103: }
104:
105: nb_variables = liste_variables(s_etat_processus, tableau);
106:
107: for(i = 0; i < nb_variables; i++)
108: {
109: if (tableau[i].niveau == 0)
110: {
111: // Variables qui contiennent les points d'entrée des définitions.
112:
113: (*s_etat_processus).position_courante = (*((integer8 *)
114: (*(tableau[i].objet)).objet));
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: {
137: printf("+++Fatal : Compilation impossible\n");
138: }
139: else
140: {
141: printf("+++Fatal : Compilation failed\n");
142: }
143:
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:
152: free(tableau);
153: return(d_erreur);
154: }
155:
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';
163: (*s_etat_processus).type_en_cours = NON;
164: recherche_type(s_etat_processus);
165: (*s_etat_processus).autorisation_nom_implicite = registre;
166:
167: if (((*s_etat_processus).erreur_execution != d_ex) ||
168: ((*s_etat_processus).erreur_systeme != d_es))
169: {
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:
202: if ((*s_etat_processus).langue == 'F')
203: {
204: printf("+++Fatal : Compilation impossible\n");
205: }
206: else
207: {
208: printf("+++Fatal : Compilation failed\n");
209: }
210:
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:
219: free(tableau);
220: return(d_erreur);
221: }
222:
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: {
231: printf("+++Fatal : Compilation impossible\n");
232: }
233: else
234: {
235: printf("+++Fatal : Compilation failed\n");
236: }
237:
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:
246: free(tableau);
247: return(d_erreur);
248: }
249:
250: liberation(s_etat_processus, tableau[i].objet);
251:
252: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
253: &((*(*s_etat_processus).pointeur_variable_courante).objet))
254: == d_erreur)
255: {
256: if ((*s_etat_processus).langue == 'F')
257: {
258: printf("+++Fatal : Compilation impossible\n");
259: }
260: else
261: {
262: printf("+++Fatal : Compilation failed\n");
263: }
264:
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:
273: free(tableau);
274: return(d_erreur);
275: }
276:
277: (*(*s_etat_processus).pointeur_variable_courante).origine = 'E';
278: free((*s_etat_processus).instruction_courante);
279:
280: if (point_entree == i)
281: {
282: programme_principal = (*(*s_etat_processus)
283: .pointeur_variable_courante).objet;
284: }
285: }
286: }
287:
288: if (point_entree == -1)
289: {
290: if ((*s_etat_processus).langue == 'F')
291: {
292: printf("+++Fatal : Compilation impossible\n");
293: }
294: else
295: {
296: printf("+++Fatal : Compilation failed\n");
297: }
298:
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:
307: free(tableau);
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: {
320: printf("[%d] Compilation achevée\n", (int) getpid());
321: }
322: else
323: {
324: printf("[%d] Compilation done\n", (int) getpid());
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: {
341: printf("+++Fatal : Compilation impossible\n");
342: }
343: else
344: {
345: printf("+++Fatal : Compilation failed\n");
346: }
347:
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:
356: free(tableau);
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: {
366: profilage(s_etat_processus, tableau[point_entree].nom);
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:
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:
388: free(tableau);
389: return(d_erreur);
390: }
391:
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:
400: free(tableau);
401:
402: erreur = evaluation(s_etat_processus, programme_principal, 'E');
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>