File:
[local] /
rpl /
src /
optimisation.c
Revision
1.51:
download - view:
text,
annotated -
select for diffs -
revision graph
Sun Mar 24 22:06:10 2013 UTC (12 years, 1 month ago) by
bertrand
Branches:
MAIN
CVS tags:
rpl-4_1_13,
HEAD
Correction d'un certain nombre de bugs touchant à l'initialisation des threads
par SPAWN (possibilité de récupérer un segfault ou une erreur système de type
d_es_processus). Correction de petits problèmes sur les variables partagées.
Attention, la fonction VARS peut encore bloquer.
1: /*
2: ================================================================================
3: RPL/2 (R) version 4.1.13
4: Copyright (C) 1989-2013 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: recherche_type(s_etat_processus);
160: (*s_etat_processus).autorisation_nom_implicite = registre;
161:
162: if (((*s_etat_processus).erreur_execution != d_ex) ||
163: ((*s_etat_processus).erreur_systeme != d_es))
164: {
165: if ((*s_etat_processus).core == d_vrai)
166: {
167: if ((*s_etat_processus).langue == 'F')
168: {
169: printf("+++Information : "
170: "Génération du fichier rpl-core "
171: "[%d]\n", (int) getpid());
172: }
173: else
174: {
175: printf("+++Information : "
176: "Writing rpl-core file [%d]\n",
177: (int) getpid());
178: }
179:
180: rplcore(s_etat_processus);
181:
182: if ((*s_etat_processus).langue == 'F')
183: {
184: printf("+++Information : "
185: "Processus tracé [%d]\n",
186: (int) getpid());
187: }
188: else
189: {
190: printf("+++Information : Done [%d]\n",
191: (int) getpid());
192: }
193:
194: fflush(stdout);
195: }
196:
197: if ((*s_etat_processus).langue == 'F')
198: {
199: printf("+++Fatal : Compilation impossible\n");
200: }
201: else
202: {
203: printf("+++Fatal : Compilation failed\n");
204: }
205:
206: for(j = 0; j < nb_variables; j++)
207: {
208: if (tableau[j].mutex != NULL)
209: {
210: pthread_mutex_unlock(tableau[j].mutex);
211: }
212: }
213:
214: free(tableau);
215: return(d_erreur);
216: }
217:
218: // Modification de la variable. Il n'existe à cet instant
219: // que des variables de niveau 0.
220:
221: if (recherche_variable(s_etat_processus, tableau[i].nom) ==
222: d_faux)
223: {
224: if ((*s_etat_processus).langue == 'F')
225: {
226: printf("+++Fatal : Compilation impossible\n");
227: }
228: else
229: {
230: printf("+++Fatal : Compilation failed\n");
231: }
232:
233: for(j = 0; j < nb_variables; j++)
234: {
235: if (tableau[j].mutex != NULL)
236: {
237: pthread_mutex_unlock(tableau[j].mutex);
238: }
239: }
240:
241: free(tableau);
242: return(d_erreur);
243: }
244:
245: liberation(s_etat_processus, tableau[i].objet);
246:
247: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
248: &((*(*s_etat_processus).pointeur_variable_courante).objet))
249: == d_erreur)
250: {
251: if ((*s_etat_processus).langue == 'F')
252: {
253: printf("+++Fatal : Compilation impossible\n");
254: }
255: else
256: {
257: printf("+++Fatal : Compilation failed\n");
258: }
259:
260: for(j = 0; j < nb_variables; j++)
261: {
262: if (tableau[j].mutex != NULL)
263: {
264: pthread_mutex_unlock(tableau[j].mutex);
265: }
266: }
267:
268: free(tableau);
269: return(d_erreur);
270: }
271:
272: (*(*s_etat_processus).pointeur_variable_courante).origine = 'E';
273: free((*s_etat_processus).instruction_courante);
274:
275: if (point_entree == i)
276: {
277: programme_principal = (*(*s_etat_processus)
278: .pointeur_variable_courante).objet;
279: }
280: }
281: }
282:
283: if (point_entree == -1)
284: {
285: if ((*s_etat_processus).langue == 'F')
286: {
287: printf("+++Fatal : Compilation impossible\n");
288: }
289: else
290: {
291: printf("+++Fatal : Compilation failed\n");
292: }
293:
294: for(j = 0; j < nb_variables; j++)
295: {
296: if (tableau[j].mutex != NULL)
297: {
298: pthread_mutex_unlock(tableau[j].mutex);
299: }
300: }
301:
302: free(tableau);
303: return(d_erreur);
304: }
305:
306: if ((*s_etat_processus).debug == d_vrai)
307: {
308: if (((*s_etat_processus).type_debug &
309: d_debug_analyse) != 0)
310: {
311: printf("\n");
312:
313: if ((*s_etat_processus).langue == 'F')
314: {
315: printf("[%d] Compilation achevée\n", (int) getpid());
316: }
317: else
318: {
319: printf("[%d] Compilation done\n", (int) getpid());
320: }
321:
322: printf("\n");
323: fflush(stdout);
324: }
325: }
326:
327: (*s_etat_processus).retour_routine_evaluation = 'Y';
328:
329: free((*s_etat_processus).definitions_chainees);
330:
331: if (((*s_etat_processus).definitions_chainees =
332: malloc(sizeof(unsigned char))) == NULL)
333: {
334: if ((*s_etat_processus).langue == 'F')
335: {
336: printf("+++Fatal : Compilation impossible\n");
337: }
338: else
339: {
340: printf("+++Fatal : Compilation failed\n");
341: }
342:
343: for(j = 0; j < nb_variables; j++)
344: {
345: if (tableau[j].mutex != NULL)
346: {
347: pthread_mutex_unlock(tableau[j].mutex);
348: }
349: }
350:
351: free(tableau);
352: return(d_erreur);
353: }
354:
355: (*s_etat_processus).definitions_chainees[0] = d_code_fin_chaine;
356: (*s_etat_processus).longueur_definitions_chainees = 0;
357: (*s_etat_processus).evaluation_expression_compilee = 'Y';
358:
359: if ((*s_etat_processus).profilage == d_vrai)
360: {
361: profilage(s_etat_processus, tableau[point_entree].nom);
362: }
363:
364: if ((*s_etat_processus).erreur_systeme != d_es)
365: {
366: if ((*s_etat_processus).langue == 'F')
367: {
368: printf("+++Système : Mémoire insuffisante\n");
369: }
370: else
371: {
372: printf("+++System : Not enough memory\n");
373: }
374:
375: for(j = 0; j < nb_variables; j++)
376: {
377: if (tableau[j].mutex != NULL)
378: {
379: pthread_mutex_unlock(tableau[j].mutex);
380: }
381: }
382:
383: free(tableau);
384: return(d_erreur);
385: }
386:
387: for(j = 0; j < nb_variables; j++)
388: {
389: if (tableau[j].mutex != NULL)
390: {
391: pthread_mutex_unlock(tableau[j].mutex);
392: }
393: }
394:
395: free(tableau);
396:
397: erreur = evaluation(s_etat_processus, programme_principal, 'E');
398:
399: if ((*s_etat_processus).profilage == d_vrai)
400: {
401: profilage(s_etat_processus, NULL);
402: }
403:
404: (*s_etat_processus).mode_execution_programme = 'N';
405:
406: if (((*s_etat_processus).erreur_execution != d_ex) ||
407: ((*s_etat_processus).exception != d_ep) ||
408: ((*s_etat_processus).erreur_systeme != d_es))
409: {
410: printf("%s [%d]\n", message = messages(s_etat_processus),
411: (int) getpid());
412:
413: if (test_cfsf(s_etat_processus, 51) == d_faux)
414: {
415: printf("%s", ds_beep);
416: }
417:
418: free(message);
419: }
420:
421: return(erreur);
422: }
423:
424: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>