Annotation of rpl/src/analyse.c, revision 1.65
1.1 bertrand 1: /*
2: ================================================================================
1.63 bertrand 3: RPL/2 (R) version 4.1.5
1.35 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.25 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 24:
25:
26: /*
27: ================================================================================
1.3 bertrand 28: Analyseur syntaxique de l'interprète RPL/2
1.1 bertrand 29: ================================================================================
30: Entrées :
31: --------------------------------------------------------------------------------
32: Sorties :
33: --------------------------------------------------------------------------------
34: Effets de bord : néant
35: ================================================================================
36: */
37:
38: static void
39: creation_instruction(struct_processus *s_etat_processus,
40: unsigned char *instruction, void (*routine)())
41: {
42: int i;
43:
44: struct_instruction *l_instruction_courante;
45:
46: unsigned char *ptr;
47:
1.14 bertrand 48: BUG(strlen(instruction) >= d_longueur_maximale_instruction,
49: printf("%s -> %d >= %d\n", instruction, (int) strlen(instruction),
50: d_longueur_maximale_instruction));
51:
1.1 bertrand 52: if ((*s_etat_processus).arbre_instructions == NULL)
53: {
54: if (((*s_etat_processus).arbre_instructions =
55: malloc(sizeof(struct_instruction))) == NULL)
56: {
57: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
58: return;
59: }
60:
61: (*(*s_etat_processus).arbre_instructions).feuille = NULL;
62:
1.41 bertrand 63: if (((*(*s_etat_processus).arbre_instructions).noeuds =
1.1 bertrand 64: malloc((*s_etat_processus).nombre_caracteres
65: * sizeof(struct_instruction))) == NULL)
66: {
67: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
68: return;
69: }
70:
71: for(i = 0; i < (*s_etat_processus).nombre_caracteres; i++)
72: {
1.41 bertrand 73: (*(*s_etat_processus).arbre_instructions).noeuds[i] = NULL;
1.1 bertrand 74: }
75: }
76:
77: l_instruction_courante = (*s_etat_processus).arbre_instructions;
78: ptr = instruction;
79:
80: while((*ptr) != d_code_fin_chaine)
81: {
82: BUG((*s_etat_processus).pointeurs_caracteres[*ptr] < 0,
83: printf("Instruction=\"%s\", (*ptr)='%c'\n",
84: instruction, *ptr));
85:
1.41 bertrand 86: if ((*l_instruction_courante).noeuds[(*s_etat_processus)
1.1 bertrand 87: .pointeurs_caracteres[*ptr]] == NULL)
88: {
89: // Le noeud suivant n'existe pas, on le crée.
90:
1.41 bertrand 91: if (((*l_instruction_courante).noeuds[(*s_etat_processus)
1.1 bertrand 92: .pointeurs_caracteres[*ptr]] =
93: malloc(sizeof(struct_instruction))) == NULL)
94: {
95: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
96: return;
97: }
98:
1.41 bertrand 99: (*(*l_instruction_courante).noeuds[(*s_etat_processus)
1.1 bertrand 100: .pointeurs_caracteres[*ptr]]).feuille = NULL;
101:
1.41 bertrand 102: if (((*(*l_instruction_courante).noeuds[(*s_etat_processus)
103: .pointeurs_caracteres[*ptr]]).noeuds =
1.1 bertrand 104: malloc((*s_etat_processus).nombre_caracteres
105: * sizeof(struct_instruction))) == NULL)
106: {
107: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
108: return;
109: }
110:
111: for(i = 0; i < (*s_etat_processus).nombre_caracteres; i++)
112: {
1.41 bertrand 113: (*(*l_instruction_courante).noeuds[(*s_etat_processus)
114: .pointeurs_caracteres[*ptr]]).noeuds[i] = NULL;
1.1 bertrand 115: }
116: }
117:
1.41 bertrand 118: l_instruction_courante = (*l_instruction_courante).noeuds
1.1 bertrand 119: [(*s_etat_processus).pointeurs_caracteres[*ptr]];
120: ptr++;
121: }
122:
123: BUG((*l_instruction_courante).feuille != NULL,
124: printf("Instruction=\"%s\"\n", instruction));
125:
126: (*l_instruction_courante).feuille = routine;
127:
128: return;
129: }
130:
131:
132: void
133: liberation_arbre_instructions(struct_processus *s_etat_processus,
134: struct_instruction *arbre)
135: {
136: int i;
137:
138: for(i = 0; i < (*s_etat_processus).nombre_caracteres; i++)
139: {
1.41 bertrand 140: if ((*arbre).noeuds[i] != NULL)
1.1 bertrand 141: {
1.41 bertrand 142: liberation_arbre_instructions(s_etat_processus, (*arbre).noeuds[i]);
1.1 bertrand 143: }
144: }
145:
1.41 bertrand 146: free((*arbre).noeuds);
1.1 bertrand 147: free(arbre);
148:
149: return;
150: }
151:
152:
153: /*
154: * Caractères autorisés dans les instructions
155: *
156: * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
157: * e i (mais traités comme des majuscules grâce à 'instruction_*_sensible()'
158: * + - * / % ^ < > = ? 1 2
159: */
160:
161: void
162: initialisation_instructions(struct_processus *s_etat_processus)
163: {
164: int decalage;
165: int i;
166: int longueur_tableau;
167:
168: unsigned char caractere;
169:
170: // Récupération de la longueur d'un unsigned char
171:
172: longueur_tableau = 1;
173: decalage = 0;
174: caractere = 1;
175:
176: while((1L << decalage) == (long) ((unsigned char) (caractere << decalage)))
177: {
178: decalage++;
179: longueur_tableau *= 2;
180: }
181:
182: if (((*s_etat_processus).pointeurs_caracteres =
183: malloc(longueur_tableau * sizeof(int))) == NULL)
184: {
185: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
186: return;
187: }
188:
189: for(i = 0; i < longueur_tableau; i++)
190: {
191: (*s_etat_processus).pointeurs_caracteres[i] = -1;
192: }
193:
194: (*s_etat_processus).nombre_caracteres = 0;
195:
196: #define DECLARATION_CARACTERE(c) \
197: do { (*s_etat_processus).pointeurs_caracteres[c] = \
198: (*s_etat_processus).nombre_caracteres++; } while(0)
199:
200: DECLARATION_CARACTERE('A');
201: DECLARATION_CARACTERE('B');
202: DECLARATION_CARACTERE('C');
203: DECLARATION_CARACTERE('D');
204: DECLARATION_CARACTERE('E');
205: DECLARATION_CARACTERE('F');
206: DECLARATION_CARACTERE('G');
207: DECLARATION_CARACTERE('H');
208: DECLARATION_CARACTERE('I');
209: DECLARATION_CARACTERE('J');
210: DECLARATION_CARACTERE('K');
211: DECLARATION_CARACTERE('L');
212: DECLARATION_CARACTERE('M');
213: DECLARATION_CARACTERE('N');
214: DECLARATION_CARACTERE('O');
215: DECLARATION_CARACTERE('P');
216: DECLARATION_CARACTERE('Q');
217: DECLARATION_CARACTERE('R');
218: DECLARATION_CARACTERE('S');
219: DECLARATION_CARACTERE('T');
220: DECLARATION_CARACTERE('U');
221: DECLARATION_CARACTERE('V');
222: DECLARATION_CARACTERE('W');
223: DECLARATION_CARACTERE('X');
224: DECLARATION_CARACTERE('Y');
225: DECLARATION_CARACTERE('Z');
226: DECLARATION_CARACTERE('+');
227: DECLARATION_CARACTERE('-');
228: DECLARATION_CARACTERE('/');
229: DECLARATION_CARACTERE('*');
230: DECLARATION_CARACTERE('%');
231: DECLARATION_CARACTERE('^');
232: DECLARATION_CARACTERE('<');
233: DECLARATION_CARACTERE('>');
234: DECLARATION_CARACTERE('=');
235: DECLARATION_CARACTERE('?');
236: DECLARATION_CARACTERE('1');
237: DECLARATION_CARACTERE('2');
238:
239: #undef DECLARATION_CARACTERE
240:
241: #define INSTRUCTION(chaine, fonction) \
242: creation_instruction(s_etat_processus, chaine, fonction)
243:
244: INSTRUCTION("E", instruction_sensible_e);
245: INSTRUCTION("I", instruction_sensible_i);
246: INSTRUCTION("+", instruction_plus);
247: INSTRUCTION("-", instruction_moins);
248: INSTRUCTION("*", instruction_multiplication);
249: INSTRUCTION("/", instruction_division);
250: INSTRUCTION("%", instruction_pourcent);
251: INSTRUCTION("^", instruction_puissance);
252: INSTRUCTION("<", instruction_lt);
253: INSTRUCTION("=", instruction_egalite);
254: INSTRUCTION(">", instruction_gt);
255:
256: INSTRUCTION("CF", instruction_cf);
257: INSTRUCTION("CR", instruction_cr);
258: INSTRUCTION("DO", instruction_do);
259: INSTRUCTION("FP", instruction_fp);
260: INSTRUCTION("IF", instruction_if);
261: INSTRUCTION("IM", instruction_im);
262: INSTRUCTION("IN", instruction_in);
263: INSTRUCTION("IP", instruction_ip);
264: INSTRUCTION("LN", instruction_ln);
265: INSTRUCTION("LQ", instruction_lq);
266: INSTRUCTION("LU", instruction_lu);
267: INSTRUCTION("NS", instruction_ns);
268: INSTRUCTION("OR", instruction_or);
269: INSTRUCTION("PI", instruction_pi);
270: INSTRUCTION("QR", instruction_qr);
271: INSTRUCTION("RE", instruction_re);
272: INSTRUCTION("RL", instruction_rl);
273: INSTRUCTION("RR", instruction_rr);
274: INSTRUCTION("SF", instruction_sf);
275: INSTRUCTION("SL", instruction_sl);
276: INSTRUCTION("SQ", instruction_sq);
277: INSTRUCTION("SR", instruction_sr);
278: INSTRUCTION("SX", instruction_sx);
279: INSTRUCTION("SY", instruction_sy);
280: INSTRUCTION("S+", instruction_s_plus);
281: INSTRUCTION("S-", instruction_s_moins);
282: INSTRUCTION("->", instruction_fleche);
283: INSTRUCTION("*D", instruction_star_d);
284: INSTRUCTION("*H", instruction_star_h);
285: INSTRUCTION("*S", instruction_star_s);
286: INSTRUCTION("*W", instruction_star_w);
287: INSTRUCTION("**", instruction_puissance);
288: INSTRUCTION("%T", instruction_pourcent_t);
289: INSTRUCTION("<=", instruction_le);
290: INSTRUCTION("<<", instruction_vers_niveau_superieur);
291: INSTRUCTION("<>", instruction_ne);
292: INSTRUCTION("==", instruction_same);
293: INSTRUCTION("=>", instruction_ge);
294: INSTRUCTION("=<", instruction_le);
295: INSTRUCTION(">=", instruction_ge);
296: INSTRUCTION(">>", instruction_vers_niveau_inferieur);
297:
298: INSTRUCTION("ABS", instruction_abs);
299: INSTRUCTION("AND", instruction_and);
300: //INSTRUCTION("ARC")
301: //(centre, rayon, theta1, theta2 dans le sens trigonométrique)
302: INSTRUCTION("ARG", instruction_arg);
303: INSTRUCTION("ASL", instruction_asl);
304: INSTRUCTION("ASR", instruction_asr);
305: //INSTRUCTION("BAR")
306: //Instruction HP48 (sélectionne le type de graphique à barres)
307: //Chaque point est représenté par une barre verticale.
308: INSTRUCTION("BIN", instruction_bin);
309: //INSTRUCTION("BOX")
310: //(point 1, point 2)
311: INSTRUCTION("CHR", instruction_chr);
312: INSTRUCTION("CLS", instruction_cls);
313: INSTRUCTION("CON", instruction_con);
314: INSTRUCTION("COS", instruction_cos);
315: INSTRUCTION("COV", instruction_cov);
316: INSTRUCTION("DEC", instruction_dec);
317: INSTRUCTION("DEG", instruction_deg);
318: INSTRUCTION("DER", instruction_der);
319: INSTRUCTION("DET", instruction_det);
320: INSTRUCTION("DFT", instruction_dft);
321: INSTRUCTION("DOT", instruction_dot);
322: INSTRUCTION("DUP", instruction_dup);
323: INSTRUCTION("EGV", instruction_egv);
324: INSTRUCTION("END", instruction_end);
325: INSTRUCTION("ENG", instruction_eng);
326: INSTRUCTION("EXP", instruction_exp);
327: INSTRUCTION("FC?", instruction_fc_test);
328: INSTRUCTION("FFT", instruction_fft);
329: //INSTRUCTION("FIT")
330: //Extension RPL/2 (choix de la méthode de régression, par défaut, 'LINEAR'.
331: //Les types sont
332: //'LINEAR' => y = b + mx
333: //'LOGARITHMIC' => y = b + m ln(x)
334: //'EXPONENTIAL' => y = be^(mx) ou ln(y) = ln(b) + mx
335: //'POWER' => y = bx^m ou ln(y) = ln(b) + m ln(x)
336: INSTRUCTION("FIX", instruction_fix);
337: INSTRUCTION("FOR", instruction_for);
338: INSTRUCTION("FS?", instruction_fs_test);
339: INSTRUCTION("GET", instruction_get);
340: INSTRUCTION("HEX", instruction_hex);
341: INSTRUCTION("IDN", instruction_idn);
342: INSTRUCTION("IFT", instruction_ift);
343: INSTRUCTION("INT", instruction_int);
344: INSTRUCTION("INV", instruction_inv);
345: INSTRUCTION("KEY", instruction_key);
346: INSTRUCTION("LOG", instruction_log);
347: INSTRUCTION("LSQ", instruction_lsq);
348: INSTRUCTION("MAX", instruction_max);
349: INSTRUCTION("MEM", instruction_mem);
350: INSTRUCTION("MIN", instruction_min);
351: INSTRUCTION("MOD", instruction_mod);
352: INSTRUCTION("NEG", instruction_neg);
353: INSTRUCTION("NOT", instruction_not);
354: INSTRUCTION("NUM", instruction_num);
355: INSTRUCTION("OCT", instruction_oct);
356: INSTRUCTION("POS", instruction_pos);
357: INSTRUCTION("PR1", instruction_pr1);
358: INSTRUCTION("PUT", instruction_put);
359: INSTRUCTION("RAD", instruction_rad);
360: INSTRUCTION("RCI", instruction_rci);
361: INSTRUCTION("RCL", instruction_rcl);
362: INSTRUCTION("RDM", instruction_rdm);
363: INSTRUCTION("RDZ", instruction_rdz);
364: INSTRUCTION("RES", instruction_res);
365: INSTRUCTION("RLB", instruction_rlb);
366: INSTRUCTION("RND", instruction_rnd);
367: INSTRUCTION("ROT", instruction_rot);
368: INSTRUCTION("RRB", instruction_rrb);
369: INSTRUCTION("RSD", instruction_rsd);
370: INSTRUCTION("SCI", instruction_sci);
371: INSTRUCTION("SIN", instruction_sin);
372: INSTRUCTION("SLB", instruction_slb);
373: INSTRUCTION("SRB", instruction_srb);
374: INSTRUCTION("SST", instruction_sst);
375: INSTRUCTION("STD", instruction_std);
376: INSTRUCTION("STO", instruction_sto);
377: INSTRUCTION("SVD", instruction_svd);
378: INSTRUCTION("SVL", instruction_svl);
379: INSTRUCTION("SUB", instruction_sub);
380: INSTRUCTION("SWI", instruction_swi);
381: INSTRUCTION("SX2", instruction_sx2);
382: INSTRUCTION("SXY", instruction_sxy);
383: INSTRUCTION("SY2", instruction_sy2);
384: INSTRUCTION("TAN", instruction_tan);
385: INSTRUCTION("TOT", instruction_tot);
386: INSTRUCTION("TRN", instruction_trn);
387: INSTRUCTION("USE", instruction_use);
388: INSTRUCTION("VAR", instruction_var);
389: //INSTRUCTION("V->")
390: //Instruction HP48 (éclate un vecteur [ x y ] => x y quel que soit le
391: //système de
392: //coordonnées)
393: INSTRUCTION("XOR", instruction_xor);
394: INSTRUCTION("->Q", instruction_fleche_q);
395: INSTRUCTION("%CH", instruction_pourcent_ch);
396:
397: INSTRUCTION("ACOS", instruction_acos);
398: INSTRUCTION("ALOG", instruction_alog);
399: INSTRUCTION("ASIN", instruction_asin);
400: INSTRUCTION("ATAN", instruction_atan);
401: INSTRUCTION("AXES", instruction_axes);
402: INSTRUCTION("BEEP", instruction_beep);
403: INSTRUCTION("B->R", instruction_b_vers_r);
404: INSTRUCTION("CASE", instruction_case);
405: INSTRUCTION("CEIL", instruction_ceil);
406: INSTRUCTION("CLMF", instruction_clmf);
407: INSTRUCTION("CNRM", instruction_cnrm);
408: INSTRUCTION("COLS", instruction_cols);
409: INSTRUCTION("COL+", instruction_col_plus);
410: INSTRUCTION("COL-", instruction_col_moins);
411: INSTRUCTION("COMB", instruction_comb);
412: INSTRUCTION("COND", instruction_cond);
413: INSTRUCTION("CONJ", instruction_conj);
414: INSTRUCTION("CONT", instruction_cont);
415: INSTRUCTION("COPY", instruction_copy);
416: INSTRUCTION("CORR", instruction_corr);
417: INSTRUCTION("COSH", instruction_cosh);
418: INSTRUCTION("CSWP", instruction_cswp);
419: INSTRUCTION("C->R", instruction_c_vers_r);
420: INSTRUCTION("DATE", instruction_date);
421: INSTRUCTION("DECR", instruction_decr);
422: INSTRUCTION("DISP", instruction_disp);
423: INSTRUCTION("DRAW", instruction_draw);
424: INSTRUCTION("DRAX", instruction_drax);
425: INSTRUCTION("DROP", instruction_drop);
426: INSTRUCTION("DRWS", instruction_drws);
427: INSTRUCTION("DUP2", instruction_dup2);
428: INSTRUCTION("DUPN", instruction_dupn);
429: INSTRUCTION("D->R", instruction_d_vers_r);
430: INSTRUCTION("EDIT", instruction_edit);
431: INSTRUCTION("EGVL", instruction_egvl);
432: INSTRUCTION("ELSE", instruction_else);
433: INSTRUCTION("ERRM", instruction_errm);
434: INSTRUCTION("ERRN", instruction_errn);
435: INSTRUCTION("EVAL", instruction_eval);
436: INSTRUCTION("EXIT", instruction_exit);
437: INSTRUCTION("EXPM", instruction_expm);
438: INSTRUCTION("FACT", instruction_fact);
439: INSTRUCTION("FC?C", instruction_fc_test_c);
440: INSTRUCTION("FC?S", instruction_fc_test_s);
441: //INSTRUCTION("FORM")
442: INSTRUCTION("FS?C", instruction_fs_test_c);
443: INSTRUCTION("FS?S", instruction_fs_test_s);
444: INSTRUCTION("FUSE", instruction_fuse);
445: INSTRUCTION("GEGV", instruction_gegv);
446: INSTRUCTION("GETC", instruction_getc);
447: INSTRUCTION("GETI", instruction_geti);
448: INSTRUCTION("GETR", instruction_getr);
449: INSTRUCTION("HALT", instruction_halt);
450: INSTRUCTION("HEAD", instruction_head);
451: INSTRUCTION("HELP", instruction_help);
452: INSTRUCTION("HMS+", instruction_hms_plus);
453: INSTRUCTION("HMS-", instruction_hms_moins);
454: //INSTRUCTION("HOME");
455: INSTRUCTION("IDFT", instruction_idft);
456: INSTRUCTION("IFFT", instruction_ifft);
457: INSTRUCTION("IFTE", instruction_ifte);
458: INSTRUCTION("INCR", instruction_incr);
459: //INSTRUCTION("ISOL");
460: INSTRUCTION("ISWI", instruction_iswi);
461: INSTRUCTION("KILL", instruction_kill);
462: INSTRUCTION("KIND", instruction_kind);
463: INSTRUCTION("LAST", instruction_last);
464: INSTRUCTION("LEGV", instruction_legv);
465: INSTRUCTION("LINE", instruction_line);
466: INSTRUCTION("LNP1", instruction_lnp1);
467: INSTRUCTION("LOCK", instruction_lock);
1.36 bertrand 468: INSTRUCTION("L->T", instruction_l_vers_t);
1.1 bertrand 469: INSTRUCTION("MANT", instruction_mant);
470: INSTRUCTION("MARK", instruction_mark);
471: //INSTRUCTION("MAXR")
472: INSTRUCTION("MAXS", instruction_maxs);
473: INSTRUCTION("MEAN", instruction_mean);
474: //INSTRUCTION("MINR");
475: INSTRUCTION("MINS", instruction_mins); // MAXDOUBLE/MINDOUBLE
476: INSTRUCTION("NEXT", instruction_next);
477: //INSTRUCTION("NUMX");
478: //INSTRUCTION("NUMY");
479: INSTRUCTION("OPEN", instruction_open);
480: INSTRUCTION("OVER", instruction_over);
481: //INSTRUCTION("PATH");
482: INSTRUCTION("PCOV", instruction_pcov);
483: INSTRUCTION("PEEK", instruction_peek);
484: INSTRUCTION("PERM", instruction_perm);
485: INSTRUCTION("PICK", instruction_pick);
486: INSTRUCTION("PLOT", instruction_plot);
487: INSTRUCTION("PMAX", instruction_pmax);
488: INSTRUCTION("PMIN", instruction_pmin);
489: INSTRUCTION("POKE", instruction_poke);
490: INSTRUCTION("PPAR", instruction_ppar);
491: INSTRUCTION("PRMD", instruction_prmd);
492: INSTRUCTION("PRST", instruction_prst);
493: INSTRUCTION("PUTC", instruction_putc);
494: INSTRUCTION("PUTI", instruction_puti);
495: INSTRUCTION("PUTR", instruction_putr);
496: INSTRUCTION("PVAR", instruction_pvar);
497: INSTRUCTION("P->R", instruction_p_vers_r);
498: //INSTRUCTION("QUAD");
499: INSTRUCTION("RAND", instruction_rand);
500: INSTRUCTION("RANK", instruction_rank);
501: //INSTRUCTION("RANM")
502: //Instruction HP48 (crée une matrice aléatoire
503: //{ nb_lignes nb_colonnes } ou tableau quelconque dont les éléments seront
504: //modifiés pour prendre des valeurs aléatoires entre -9 et 9)
505: INSTRUCTION("RCEQ", instruction_rceq);
506: INSTRUCTION("RCIJ", instruction_rcij);
507: INSTRUCTION("RCLF", instruction_rclf);
508: INSTRUCTION("RCLS", instruction_rcls);
509: INSTRUCTION("RCWS", instruction_rcws);
510: INSTRUCTION("RDGN", instruction_rdgn);
511: INSTRUCTION("READ", instruction_read);
512: INSTRUCTION("RECV", instruction_recv);
513: INSTRUCTION("REGV", instruction_regv);
514: INSTRUCTION("REPL", instruction_repl);
515: INSTRUCTION("RNRM", instruction_rnrm);
516: INSTRUCTION("ROLL", instruction_roll);
517: //INSTRUCTION("ROOT")
518: INSTRUCTION("ROW-", instruction_row_moins);
519: INSTRUCTION("ROW+", instruction_row_plus);
520: //INSTRUCTION("RREF")
521: //Instruction HP48 (transforme [A B] en [I C] par combinaisons linéaires
522: //de lignes)
523: INSTRUCTION("RSWP", instruction_rswp);
524: INSTRUCTION("R->B", instruction_r_vers_b);
525: INSTRUCTION("R->C", instruction_r_vers_c);
526: INSTRUCTION("R->D", instruction_r_vers_d);
527: INSTRUCTION("R->P", instruction_r_vers_p);
528: INSTRUCTION("SAME", instruction_same);
529: INSTRUCTION("SAVE", instruction_save);
530: INSTRUCTION("SCLS", instruction_scls);
531: INSTRUCTION("SDEV", instruction_sdev);
532: INSTRUCTION("SEND", instruction_send);
533: //INSTRUCTION("SHOW");
534: INSTRUCTION("SIGN", instruction_sign);
535: INSTRUCTION("SINH", instruction_sinh);
536: INSTRUCTION("SINV", instruction_sinv);
537: INSTRUCTION("SIZE", instruction_size);
538: INSTRUCTION("SNEG", instruction_sneg);
539: INSTRUCTION("SORT", instruction_sort);
540: INSTRUCTION("SPAR", instruction_spar);
541: INSTRUCTION("SQRT", instruction_sqrt);
542: //INSTRUCTION("SRAD");
1.53 bertrand 543: INSTRUCTION("SREV", instruction_srev);
1.1 bertrand 544: //INSTRUCTION("SRNM")
545: //Instruction HP48 (renvoie la norme spectrale d'un tableau. Pour une
546: //matrice,
547: //la norme spectrale est égale à sa plus grande valeur singulière. Pour un
548: //vecteur, la fonction est équivalente à ABS.
549: INSTRUCTION("STEP", instruction_step);
550: INSTRUCTION("STEQ", instruction_steq);
551: INSTRUCTION("STO*", instruction_sto_fois);
552: INSTRUCTION("STO+", instruction_sto_plus);
553: INSTRUCTION("STO-", instruction_sto_moins);
554: INSTRUCTION("STO/", instruction_sto_division);
555: INSTRUCTION("STOF", instruction_stof);
556: INSTRUCTION("STOP", instruction_stop);
557: INSTRUCTION("STOS", instruction_stos);
558: INSTRUCTION("STWS", instruction_stws);
559: INSTRUCTION("SWAP", instruction_swap);
560: INSTRUCTION("SYNC", instruction_sync);
561: INSTRUCTION("TAIL", instruction_tail);
562: INSTRUCTION("TANH", instruction_tanh);
563: INSTRUCTION("THEN", instruction_then);
564: INSTRUCTION("TIME", instruction_time);
565: INSTRUCTION("TRIM", instruction_trim);
566: INSTRUCTION("TRNC", instruction_trnc);
567: INSTRUCTION("TRUE", instruction_true);
568: INSTRUCTION("TYPE", instruction_type);
1.36 bertrand 569: INSTRUCTION("T->L", instruction_t_vers_l);
1.1 bertrand 570: INSTRUCTION("UTPC", instruction_utpc);
571: INSTRUCTION("UTPF", instruction_utpf);
572: INSTRUCTION("UTPN", instruction_utpn);
573: INSTRUCTION("UTPT", instruction_utpt);
574: INSTRUCTION("VARS", instruction_vars);
575: INSTRUCTION("WAIT", instruction_wait);
576: INSTRUCTION("XCOL", instruction_xcol);
577: INSTRUCTION("XPON", instruction_xpon);
578: //INSTRUCTION("XRNG")
579: //INSTRUCTION("XVOL")
580: INSTRUCTION("YCOL", instruction_ycol);
581: //INSTRUCTION("YRNG")
582: //INSTRUCTION("YVOL")
583: //INSTRUCTION("ZVOL")
584: //INSTRUCTION("->V2")
585: //Instruction HP48 (combine deux réels x et y en un vecteur 2D en fonction
586: //du mode de coordonnées en cours => [ x y ] et ce quel que soit le système
587: //de coordonnées courant)
588: //INSTRUCTION("->V3")
589:
590: INSTRUCTION("ABORT", instruction_abort);
591: INSTRUCTION("ACOSH", instruction_acosh);
592: INSTRUCTION("ALARM", instruction_alarm);
593: INSTRUCTION("ASINH", instruction_asinh);
594: INSTRUCTION("ATANH", instruction_atanh);
595: //INSTRUCTION("BYTES");
596: INSTRUCTION("CENTR", instruction_centr);
597: //INSTRUCTION("CIRCL");
598: INSTRUCTION("CLEAR", instruction_clear);
599: INSTRUCTION("CLLCD", instruction_cllcd);
600: INSTRUCTION("CLOSE", instruction_close);
601: INSTRUCTION("CLUSR", instruction_clusr);
602: //INSTRUCTION("CLVAR");
603: //INSTRUCTION("COLCT")
604: INSTRUCTION("COL->", instruction_col_fleche);
605: //INSTRUCTION("CONIC")
606: //Instruction HP48 (sélectionne le type de tracé CONIC)
607: //Permet de tracer des coniques en fonction d'équations
608: //de type f(x, y) = 0.
609: //INSTRUCTION("CRDIR")
610: INSTRUCTION("CRMTX", instruction_crmtx);
611: INSTRUCTION("CROSS", instruction_cross);
612: INSTRUCTION("CRTAB", instruction_crtab);
613: INSTRUCTION("CSTOP", instruction_cstop);
614: INSTRUCTION("CYCLE", instruction_cycle);
615: //INSTRUCTION("CYLIN")
616: //Instruction HP48 (sélectionne le type de tracé CYLINDRIC)
617: INSTRUCTION("DEPND", instruction_depnd);
618: INSTRUCTION("DEPTH", instruction_depth);
619: //INSTRUCTION("DOSUB")
620: //Instruction HP48 (application séquentielle d'une fonction à une liste)
621: //liste nombre_elements_traites_a_chaque_iteration fonction DOSUB
622: //{ 1 2 3 4 5 }
623: //2
624: //<< + 2 / >>
625: //DOSUB
626: //=> { 1.5 2.5 3.5 4.5 }
627: INSTRUCTION("DGTIZ", instruction_dgtiz);
628: INSTRUCTION("DROP2", instruction_drop2);
629: INSTRUCTION("DROPN", instruction_dropn);
630: INSTRUCTION("ERASE", instruction_erase);
631: INSTRUCTION("EXGET", instruction_exget);
632: //INSTRUCTION("EXPAN");
633: INSTRUCTION("EXSUB", instruction_exsub);
634: INSTRUCTION("EYEPT", instruction_eyept);
635: INSTRUCTION("FALSE", instruction_false);
636: INSTRUCTION("FLOOR", instruction_floor);
637: INSTRUCTION("GAMMA", instruction_gamma);
638: INSTRUCTION("GEGVL", instruction_gegvl);
639: INSTRUCTION("GLEGV", instruction_glegv);
640: INSTRUCTION("GREGV", instruction_gregv);
641: INSTRUCTION("HMS->", instruction_hms_fleche);
642: INSTRUCTION("IFERR", instruction_iferr);
643: INSTRUCTION("INDEP", instruction_indep);
644: INSTRUCTION("INPUT", instruction_input);
645: INSTRUCTION("JDATE", instruction_jdate);
646: INSTRUCTION("LABEL", instruction_label);
647: INSTRUCTION("LCASE", instruction_lcase);
648: INSTRUCTION("LCHOL", instruction_lchol);
649: INSTRUCTION("LCD->", instruction_lcd_fleche);
1.51 bertrand 650: INSTRUCTION("LIMIT", instruction_limit);
1.1 bertrand 651: //INSTRUCTION("NDIST")
652: //Instruction HP48 (distribution normale, prend la moyenne au niveau 3,
653: //la variance au niveau 2, un réel x au niveau 1 et renvoie la probabilité
654: //qu'une variable aléatoire normale soit égale à x dans une distribution
655: //normale).
656: INSTRUCTION("NRAND", instruction_nrand);
657: INSTRUCTION("OBGET", instruction_obget);
658: INSTRUCTION("OBSUB", instruction_obsub);
659: INSTRUCTION("PAPER", instruction_paper);
660: //INSTRUCTION("PCOEFF")
661: //INSTRUCTION("PEVAL")
662: //INSTRUCTION("PGDIR")
663: //INSTRUCTION("PIXEL")
664: //INSTRUCTION("PLIST")
665: //Instruction HP48 (produit des termes d'une liste)
666: INSTRUCTION("POLAR", instruction_polar);
667: INSTRUCTION("PRINT", instruction_print);
668: //INSTRUCTION("PREDV");
669: INSTRUCTION("PRLCD", instruction_prlcd);
670: //INSTRUCTION("PROOT")
671: //Instruction HP48 (calcule les racines d'un polynôme en fonction du tableau
672: //de coefficients)
673: INSTRUCTION("PRSTC", instruction_prstc);
674: INSTRUCTION("PRUSR", instruction_prusr);
675: INSTRUCTION("PRVAR", instruction_prvar);
676: INSTRUCTION("PSDEV", instruction_psdev);
677: INSTRUCTION("PURGE", instruction_purge);
678: INSTRUCTION("RDATE", instruction_rdate);
1.65 ! bertrand 679: INSTRUCTION("REGEX", instruction_regex);
1.1 bertrand 680: INSTRUCTION("RELAX", instruction_relax);
681: INSTRUCTION("RFUSE", instruction_rfuse);
682: INSTRUCTION("RSTOP", instruction_rstop);
683: INSTRUCTION("ROLLD", instruction_rolld);
684: INSTRUCTION("ROW->", instruction_row_fleche);
685: INSTRUCTION("SCALE", instruction_scale);
686: INSTRUCTION("SCHED", instruction_sched);
687: INSTRUCTION("SCHUR", instruction_schur);
688: INSTRUCTION("SCONJ", instruction_sconj);
689: INSTRUCTION("SLICE", instruction_slice);
690: //INSTRUCTION("SLIST")
691: //Instruction HP48 (somme des termes d'une liste)
692: INSTRUCTION("SPAWN", instruction_spawn);
693: INSTRUCTION("START", instruction_start);
694: INSTRUCTION("STORE", instruction_store);
695: INSTRUCTION("STR->", instruction_str_fleche);
696: INSTRUCTION("TAYLR", instruction_taylr);
697: INSTRUCTION("TITLE", instruction_title);
698: //INSTRUCTION("TRACE")
699: //INSTRUCTION("TRUTH")
700: INSTRUCTION("UCASE", instruction_ucase);
701: INSTRUCTION("UCHOL", instruction_uchol);
702: INSTRUCTION("UNTIL", instruction_until);
703: //INSTRUCTION("UPDIR")
704: INSTRUCTION("VISIT", instruction_visit);
705: INSTRUCTION("WFACK", instruction_wfack);
706: INSTRUCTION("WFSWI", instruction_wfswi);
707: INSTRUCTION("WHILE", instruction_while);
708: //INSTRUCTION("WIDTH")
709: INSTRUCTION("WRITE", instruction_write);
710: INSTRUCTION("XROOT", instruction_xroot);
711: INSTRUCTION("YIELD", instruction_yield);
712: INSTRUCTION("->COL", instruction_fleche_col);
713: INSTRUCTION("->HMS", instruction_fleche_hms);
714: INSTRUCTION("->LCD", instruction_fleche_lcd);
715: INSTRUCTION("->NUM", instruction_fleche_num);
716: INSTRUCTION("->ROW", instruction_fleche_row);
717: INSTRUCTION("->STR", instruction_fleche_str);
718:
719: INSTRUCTION("APPEND", instruction_append);
720: INSTRUCTION("ARRY->", instruction_array_fleche);
1.12 bertrand 721: INSTRUCTION("ATEXIT", instruction_atexit);
1.24 bertrand 722: INSTRUCTION("ATPOKE", instruction_atpoke);
1.1 bertrand 723: INSTRUCTION("BESSEL", instruction_bessel);
724: INSTRUCTION("CLRERR", instruction_clrerr);
725: INSTRUCTION("CLRMTX", instruction_clrmtx);
726: INSTRUCTION("CLRSWI", instruction_clrswi);
727: INSTRUCTION("CREATE", instruction_create);
728: INSTRUCTION("DELETE", instruction_delete);
1.59 bertrand 729: # ifdef SHARED_MEMORY
1.60 bertrand 730: INSTRUCTION("DETACH", instruction_detach);
1.59 bertrand 731: # else
1.60 bertrand 732: if ((*s_etat_processus).langue == 'F')
733: {
734: printf("+++Attention : DETACH est émulé par SPAWN car le système"
735: " hôte ne supporte\n"
736: " pas de mémoire partagée !\n");
737: }
738: else
739: {
740: printf("+++Warning : DETACH is replaced by SPAWN as host system"
741: " does not support\n"
742: " shared memory !\n");
743: }
744:
745: INSTRUCTION("DETACH", instruction_spawn);
1.29 bertrand 746: # endif
1.1 bertrand 747: INSTRUCTION("DIAG->", instruction_diag_fleche);
748: //INSTRUCTION("DOLIST")
749: //Instruction HP48 (application d'une fonction à une liste)
750: //liste(s) nombre_de_listes_a_traiter fonction DOLIST
751: //{ 1 2 3 }
752: //{ 4 5 6 }
753: //{ 7 8 9 }
754: //3
755: //<< * + >>
756: //DOLIST
757: //=> { 29 42 57 }
758: INSTRUCTION("ELSEIF", instruction_elseif);
759: INSTRUCTION("FORMAT", instruction_format);
760: //INSTRUCTION("HEIGHT")
761: INSTRUCTION("ITRACE", instruction_itrace);
762: INSTRUCTION("LIST->", instruction_list_fleche);
763: INSTRUCTION("LOGGER", instruction_logger);
764: INSTRUCTION("MCLRIN", instruction_mclrin);
765: INSTRUCTION("NRPROC", instruction_nrproc);
1.17 bertrand 766: INSTRUCTION("PROCID", instruction_procid);
1.1 bertrand 767: INSTRUCTION("PROMPT", instruction_prompt);
768: INSTRUCTION("RCLSWI", instruction_rclswi);
769: INSTRUCTION("RECALL", instruction_recall);
770: INSTRUCTION("RECODE", instruction_recode);
771: INSTRUCTION("REDRAW", instruction_redraw);
772: INSTRUCTION("REMOVE", instruction_remove);
773: INSTRUCTION("REPEAT", instruction_repeat);
774: INSTRUCTION("RETURN", instruction_return);
775: INSTRUCTION("REWIND", instruction_rewind);
776: //INSTRUCTION("SCREEN")
777: INSTRUCTION("SELECT", instruction_select);
778: //INSTRUCTION("SPHERE")
779: INSTRUCTION("SHARED", instruction_shared);
780: INSTRUCTION("SPLASH", instruction_splash);
781: INSTRUCTION("STATIC", instruction_static);
782: INSTRUCTION("STOSWI", instruction_stoswi);
783: //INSTRUCTION("STREAM", instruction_stream);
784: //{ 1 2 3 4 5 } << * >> STREAM => 120
785: INSTRUCTION("TARGET", instruction_target);
786: INSTRUCTION("UNLOCK", instruction_unlock);
787: INSTRUCTION("VERIFY", instruction_verify);
788: INSTRUCTION("WFDATA", instruction_wfdata);
789: INSTRUCTION("WFLOCK", instruction_wflock);
790: INSTRUCTION("WFPOKE", instruction_wfpoke);
791: INSTRUCTION("WFPROC", instruction_wfproc);
792: INSTRUCTION("WFSOCK", instruction_wfsock);
793: INSTRUCTION("->ARRY", instruction_fleche_array);
794: INSTRUCTION("->DIAG", instruction_fleche_diag);
795: INSTRUCTION("->LIST", instruction_fleche_list);
796:
797: INSTRUCTION("ARRAY->", instruction_array_fleche);
798: //INSTRUCTION("BARPLOT")
799: //INSTRUCTION("BESTFIT")
800: //Instruction HP48 (choisit le meilleur modèle de régression)
801: INSTRUCTION("CLRFUSE", instruction_clrfuse);
802: INSTRUCTION("CONVERT", instruction_convert);
803: INSTRUCTION("CRSMPHR", instruction_crsmphr);
804: INSTRUCTION("CURRENC", instruction_currenc);
805: INSTRUCTION("DEFAULT", instruction_default);
806: INSTRUCTION("EPSILON", instruction_epsilon);
807: //INSTRUCTION("GRIDMAP")
808: //Instruction HP48 (sélectionne le mode de tracé GRIDMAP)
809: //Le tracé GRIDMAP transforme la grille d'échantillonnage rectiligne
810: //en appliquant la fonction en cours à valeurs complexes.
811: //Les coordonnées de chaque point de la grille (un nombre complexe)
812: //constituent
813: //les données d'entrée de la fonction qui les projette ensuite dans le
814: //grille
815: //de sortie.
816: //f(x,y)=fnct complexe évaluée sur la grille (x,y) et affichée comme une
817: //fonction paramétrique.
818: INSTRUCTION("INQUIRE", instruction_inquire);
1.15 bertrand 819: INSTRUCTION("MEMLOCK", instruction_memlock);
1.1 bertrand 820: INSTRUCTION("MTXLOCK", instruction_mtxlock);
821: INSTRUCTION("PERSIST", instruction_persist);
822: INSTRUCTION("PLOTTER", instruction_plotter);
823: INSTRUCTION("PRIVATE", instruction_private);
824: INSTRUCTION("PROTECT", instruction_protect);
825: INSTRUCTION("PSHPRFL", instruction_pshprfl);
826: INSTRUCTION("PULPRFL", instruction_pulprfl);
1.64 bertrand 827: INSTRUCTION("RESTART", instruction_restart);
1.1 bertrand 828: INSTRUCTION("REVLIST", instruction_revlist);
829: INSTRUCTION("SCATTER", instruction_scatter);
830: INSTRUCTION("SUSPEND", instruction_suspend);
831: INSTRUCTION("SWILOCK", instruction_swilock);
832: INSTRUCTION("SYSEVAL", instruction_syseval);
833: INSTRUCTION("TABLE->", instruction_table_fleche);
834: INSTRUCTION("VERSION", instruction_version);
835: INSTRUCTION("WORKDIR", instruction_workdir);
836: INSTRUCTION("->ARRAY", instruction_fleche_array);
837: INSTRUCTION("->TABLE", instruction_fleche_table);
838:
839: INSTRUCTION("CLRCNTXT", instruction_clrcntxt);
840: INSTRUCTION("CLRSMPHR", instruction_clrsmphr);
841: INSTRUCTION("CONTINUE", instruction_continue);
842: INSTRUCTION("DUPCNTXT", instruction_dupcntxt);
843: INSTRUCTION("FUNCTION", instruction_function);
1.7 bertrand 844: INSTRUCTION("IMPLICIT", instruction_implicit);
1.50 bertrand 845: INSTRUCTION("INFINITY", instruction_sensible_infinity);
1.1 bertrand 846: INSTRUCTION("KEYLABEL", instruction_keylabel);
847: INSTRUCTION("KEYTITLE", instruction_keytitle);
848: INSTRUCTION("LOGSCALE", instruction_logscale);
849: INSTRUCTION("NEWPLANE", instruction_newplane);
850: INSTRUCTION("PSHCNTXT", instruction_pshcntxt);
851: INSTRUCTION("PULCNTXT", instruction_pulcntxt);
852: INSTRUCTION("SQLQUERY", instruction_sqlquery);
853: INSTRUCTION("SWIQUEUE", instruction_swiqueue);
854: INSTRUCTION("TOKENIZE", instruction_tokenize);
855: INSTRUCTION("VARIABLE", instruction_variable);
856: INSTRUCTION("VOLATILE", instruction_volatile);
857: INSTRUCTION("WARRANTY", instruction_warranty);
858:
859: INSTRUCTION("AUTOSCALE", instruction_autoscale);
860: INSTRUCTION("BACKSPACE", instruction_backspace);
1.22 bertrand 861: INSTRUCTION("BACKTRACE", instruction_backtrace);
1.13 bertrand 862: INSTRUCTION("CLRATEXIT", instruction_clratexit);
1.24 bertrand 863: INSTRUCTION("CLRATPOKE", instruction_clratpoke);
1.1 bertrand 864: INSTRUCTION("COPYRIGHT", instruction_copyright);
865: //INSTRUCTION("CYLINDRIC");
866: INSTRUCTION("DAEMONIZE", instruction_daemonize);
867: INSTRUCTION("DROPCNTXT", instruction_dropcntxt);
868: INSTRUCTION("EXTERNALS", instruction_externals);
869: INSTRUCTION("HISTOGRAM", instruction_histogram);
1.15 bertrand 870: INSTRUCTION("MEMUNLOCK", instruction_memunlock);
1.1 bertrand 871: INSTRUCTION("MTXSTATUS", instruction_mtxstatus);
872: INSTRUCTION("MTXUNLOCK", instruction_mtxunlock);
873: INSTRUCTION("PARAMETER", instruction_parameter);
874: //INSTRUCTION("PSCONTOUR")
875: //INSTRUCTION("SCATRPLOT")
876: //(trace un nuage de points de SDAT et la courbe de régression)
877: INSTRUCTION("SMPHRDECR", instruction_smphrdecr);
878: INSTRUCTION("SMPHRGETV", instruction_smphrgetv);
879: INSTRUCTION("SMPHRINCR", instruction_smphrincr);
880: INSTRUCTION("SWAPCNTXT", instruction_swapcntxt);
881: INSTRUCTION("SWISTATUS", instruction_swistatus);
882: INSTRUCTION("SWIUNLOCK", instruction_swiunlock);
883: INSTRUCTION("UNPROTECT", instruction_unprotect);
884: INSTRUCTION("WIREFRAME", instruction_wireframe);
885:
886: INSTRUCTION("MTXTRYLOCK", instruction_mtxtrylock);
887: INSTRUCTION("PARAMETRIC", instruction_parametric);
888: //INSTRUCTION("PARSURFACE")
889: //Instruction HP48 (tracé PARSURFACE) Equation sous forme de liste
890: INSTRUCTION("SLICESCALE", instruction_slicescale);
891: INSTRUCTION("SQLCONNECT", instruction_sqlconnect);
892: //INSTRUCTION("SLOPEFIELD")
893: //Instruction HP48 (type de tracé)
894: //Tracé 3D en courbes de niveaux.
895: //Le type de tracé 'SLOPEFIELD' dessine un réseau de segments dont les
896: //pentes
897: //représentent la valeur de la fonction (x,y) en leur milieu.
898: //=> utile pour y'=F(x,y)
899:
900: INSTRUCTION("LOCALIZATION", instruction_localization);
901: INSTRUCTION("SMPHRTRYDECR", instruction_smphrtrydecr);
902:
903: INSTRUCTION("SQLDISCONNECT", instruction_sqldisconnect);
904: #undef INSTRUCTION
905:
906: return;
907: }
908:
909:
1.25 bertrand 910: void *
1.1 bertrand 911: analyse_instruction(struct_processus *s_etat_processus, unsigned char *ptr)
912: {
913: int pointeur;
914:
915: struct_instruction *l_instruction_courante;
916:
917: l_instruction_courante = (*s_etat_processus).arbre_instructions;
918:
919: while((*ptr) != d_code_fin_chaine)
920: {
921: pointeur = (*s_etat_processus).pointeurs_caracteres[*ptr];
922:
923: if (pointeur < 0)
924: {
925: // Caractère hors de l'alphabet des instructions
926:
927: return(NULL);
928: }
929:
1.41 bertrand 930: if ((*l_instruction_courante).noeuds[pointeur] == NULL)
1.1 bertrand 931: {
932: // Le chemin de l'instruction candidate n'existe pas.
933:
934: return(NULL);
935: }
936:
1.41 bertrand 937: l_instruction_courante = (*l_instruction_courante).noeuds[pointeur];
1.1 bertrand 938: ptr++;
939:
940: if ((l_instruction_courante == NULL) && ((*ptr) != d_code_fin_chaine))
941: {
942: // Le chemin de l'instruction candidate est incomplet.
943:
944: return(NULL);
945: }
946: }
947:
948: if ((*l_instruction_courante).feuille != NULL)
949: {
950: return((*l_instruction_courante).feuille);
951: }
952:
953: return(NULL);
954: }
955:
956:
957: void
958: analyse(struct_processus *s_etat_processus, void (*fonction)())
959: {
960: static logical1 initialisation = d_faux;
961:
962: real8 attente;
963: real8 pourcentage;
964: real8 temps_cpu;
965: real8 temps_reel;
966:
967: static struct timeval horodatage_initial;
968: struct timeval horodatage_final;
969:
1.61 bertrand 970: # ifndef OS2
1.1 bertrand 971: static struct rusage usage_initial;
972: struct rusage usage_final;
1.61 bertrand 973: # else
974: static clock_t usage_initial;
975: clock_t usage_final;
976: # endif
1.1 bertrand 977:
978: struct timespec temporisation;
979:
980: unsigned char *position;
981: unsigned char *bibliotheque_candidate;
1.14 bertrand 982: unsigned char instruction_majuscule
983: [d_longueur_maximale_instruction];
1.1 bertrand 984: unsigned char registre_instruction_valide;
985:
986: void (*instruction)();
987:
988: errno = 0;
989: (*s_etat_processus).var_volatile_exception_gsl = 0;
990:
991: (*s_etat_processus).instruction_valide = 'Y';
992: (*s_etat_processus).constante_symbolique = 'N';
993: (*s_etat_processus).nombre_arguments = -2;
994: (*s_etat_processus).instruction_intrinseque = 'I';
995:
996: /*
997: * On autorise l'exécution d'un fork() dans un thread concurrent.
998: */
999:
1.57 bertrand 1000: # ifndef SEMAPHORES_NOMMES
1001: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
1002: # else
1003: if (sem_post((*s_etat_processus).semaphore_fork) != 0)
1004: # endif
1.1 bertrand 1005: {
1006: (*s_etat_processus).erreur_systeme = d_es_processus;
1007: return;
1008: }
1009:
1.57 bertrand 1010: # ifndef SEMAPHORES_NOMMES
1011: while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0)
1012: # else
1013: while(sem_wait((*s_etat_processus).semaphore_fork) != 0)
1014: # endif
1.9 bertrand 1015: {
1.56 bertrand 1016: if (errno != EINTR)
1017: {
1018: (*s_etat_processus).erreur_systeme = d_es_processus;
1019: return;
1020: }
1.9 bertrand 1021: }
1022:
1.1 bertrand 1023: scrutation_injection(s_etat_processus);
1024:
1025: if (fonction == NULL)
1026: {
1.14 bertrand 1027: conversion_majuscule_limitee((*s_etat_processus).instruction_courante,
1028: instruction_majuscule, d_longueur_maximale_instruction);
1.1 bertrand 1029: instruction = analyse_instruction(s_etat_processus,
1030: instruction_majuscule);
1031:
1032: if (instruction == NULL)
1033: {
1034: // L'instruction n'existe pas.
1035:
1036: (*s_etat_processus).instruction_valide = 'N';
1037: }
1038: else
1039: {
1040: // Exécution de l'instruction associée. Le drapeau
1041: // (*s_etat_processus).instruction_valide peut passer à 'N'
1042: // dans le cas d'instructions sensibles à la casse.
1043:
1044: if ((*s_etat_processus).niveau_profilage >= 2)
1045: {
1046: profilage(s_etat_processus, instruction_majuscule);
1047: }
1048:
1049: (*s_etat_processus).instruction_valide = 'Y';
1050: instruction(s_etat_processus);
1051:
1052: if ((*s_etat_processus).niveau_profilage >= 2)
1053: {
1054: profilage(s_etat_processus, NULL);
1055: }
1056: }
1057: }
1058: else
1059: {
1060: if ((*s_etat_processus).niveau_profilage >= 2)
1061: {
1062: profilage(s_etat_processus,
1063: (*s_etat_processus).instruction_courante);
1064: }
1065:
1066: (*s_etat_processus).instruction_valide = 'Y';
1067: fonction(s_etat_processus);
1068:
1069: if ((*s_etat_processus).niveau_profilage >= 2)
1070: {
1071: profilage(s_etat_processus, NULL);
1072: }
1073: }
1074:
1075: if ((*s_etat_processus).instruction_valide == 'Y')
1076: {
1077: (*s_etat_processus).instruction_intrinseque = 'Y';
1078: }
1079:
1080: if ((*s_etat_processus).instruction_valide == 'N')
1081: {
1082: if ((position = index((*s_etat_processus).instruction_courante, '$'))
1083: != NULL)
1084: {
1085: if ((bibliotheque_candidate = malloc((position + 1
1086: - (*s_etat_processus).instruction_courante)
1087: * sizeof(unsigned char))) == NULL)
1088: {
1089: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1090: return;
1091: }
1092:
1093: (*bibliotheque_candidate) = d_code_fin_chaine;
1094: strncat(bibliotheque_candidate,
1095: (*s_etat_processus).instruction_courante,
1096: position - (*s_etat_processus).instruction_courante);
1097:
1098: position++;
1099:
1100: if (execution_fonction_de_bibliotheque(s_etat_processus, position,
1101: bibliotheque_candidate) == d_vrai)
1102: {
1103: (*s_etat_processus).instruction_valide = 'Y';
1104: (*s_etat_processus).instruction_intrinseque = 'N';
1105: }
1106: else
1107: {
1108: (*s_etat_processus).instruction_valide = 'N';
1109: }
1110:
1111: free(bibliotheque_candidate);
1112: }
1113: else
1114: {
1115: if (execution_fonction_de_bibliotheque(s_etat_processus,
1116: (*s_etat_processus).instruction_courante, NULL)
1117: == d_vrai)
1118: {
1119: (*s_etat_processus).instruction_valide = 'Y';
1120: (*s_etat_processus).instruction_intrinseque = 'N';
1121: }
1122: else
1123: {
1124: (*s_etat_processus).instruction_valide = 'N';
1125: }
1126: }
1127: }
1128:
1129: /*
1130: --------------------------------------------------------------------------------
1131: Gestion des interruptions logicielles
1132: --------------------------------------------------------------------------------
1133: */
1134:
1135: if (((*s_etat_processus).erreur_systeme == d_es) &&
1136: ((*s_etat_processus).erreur_execution == d_ex) &&
1137: ((*s_etat_processus).exception == d_ep))
1138: {
1139: if ((*s_etat_processus).test_instruction == 'N')
1140: {
1141: if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
1142: {
1143: affectation_interruptions_logicielles(s_etat_processus);
1144: }
1145:
1146: if (((*s_etat_processus).nombre_interruptions_en_queue != 0) &&
1147: ((*s_etat_processus).erreur_systeme == d_es) &&
1148: ((*s_etat_processus).erreur_execution == d_ex))
1149: {
1150:
1151: registre_instruction_valide =
1152: (*s_etat_processus).instruction_valide;
1153: traitement_interruptions_logicielles(s_etat_processus);
1154: (*s_etat_processus).instruction_valide =
1155: registre_instruction_valide;
1156: }
1157: }
1158: }
1159:
1160: /*
1161: --------------------------------------------------------------------------------
1162: Limitation du pourcetage de temps CPU
1163: --------------------------------------------------------------------------------
1164: */
1165:
1166: if ((*s_etat_processus).pourcentage_maximal_cpu < 100)
1167: {
1.61 bertrand 1168: # ifndef OS2
1.1 bertrand 1169: getrusage(RUSAGE_SELF, &usage_final);
1.61 bertrand 1170: # else
1171: usage_final = clock();
1172: # endif
1173:
1.1 bertrand 1174: gettimeofday(&horodatage_final, NULL);
1175:
1176: if (initialisation == d_vrai)
1177: {
1178: temps_reel = ((real8) (horodatage_final.tv_sec -
1179: horodatage_initial.tv_sec)) +
1180: (((real8) (horodatage_final.tv_usec -
1181: horodatage_initial.tv_usec)) / ((real8) 1E6));
1182:
1.61 bertrand 1183: // Le temps depuis la dernière limitation est de plus de un
1184: // dixième de seconde.
1185:
1.1 bertrand 1186: if (temps_reel >= 0.1)
1187: {
1.61 bertrand 1188: # ifndef OS2
1.1 bertrand 1189: temps_cpu = ((real8) ((usage_final.ru_utime.tv_sec +
1190: usage_final.ru_stime.tv_sec) -
1191: (usage_initial.ru_utime.tv_sec +
1192: usage_initial.ru_stime.tv_sec))) +
1193: (((real8) ((usage_final.ru_utime.tv_usec +
1194: usage_final.ru_stime.tv_usec) -
1195: (usage_initial.ru_utime.tv_usec +
1196: usage_initial.ru_stime.tv_usec))) / ((real8) 1E6));
1.61 bertrand 1197: # else
1198: temps_cpu = (usage_final - usage_initial) / CLOCKS_PER_SEC;
1199: # endif
1.1 bertrand 1200:
1201: pourcentage = 100 * temps_cpu / temps_reel;
1202:
1203: if (pourcentage > 100)
1204: {
1205: pourcentage = 100;
1206: }
1207:
1208: if (pourcentage > (*s_etat_processus).pourcentage_maximal_cpu)
1209: {
1210: attente = ((pourcentage * temps_cpu) /
1211: (*s_etat_processus).pourcentage_maximal_cpu)
1212: - (pourcentage * temps_cpu / 100);
1213:
1214: temporisation.tv_sec = floor(attente);
1215: temporisation.tv_nsec = (attente - temporisation.tv_sec) *
1216: 1E9;
1217:
1.62 bertrand 1218: while(nanosleep(&temporisation, &temporisation) == -1)
1219: {
1220: if (errno != EINTR)
1221: {
1222: break;
1223: }
1224: }
1.1 bertrand 1225: }
1226:
1227: horodatage_initial = horodatage_final;
1228: usage_initial = usage_final;
1229: }
1230: }
1231: else
1232: {
1233: initialisation = d_vrai;
1234:
1235: horodatage_initial = horodatage_final;
1236: usage_initial = usage_final;
1237: }
1238: }
1.61 bertrand 1239: else
1240: {
1241: initialisation = d_faux;
1242: }
1.1 bertrand 1243:
1244: /*
1245: --------------------------------------------------------------------------------
1246: Introduction des erreurs générées
1247: --------------------------------------------------------------------------------
1248: */
1249:
1250: if (((*s_etat_processus).test_instruction == 'N') &&
1251: ((*s_etat_processus).instruction_valide == 'Y'))
1252: {
1253: traitement_asynchrone_exceptions_gsl(s_etat_processus);
1254:
1255: if ((*s_etat_processus).erreur_processus_fils == d_vrai)
1256: {
1257: (*s_etat_processus).erreur_processus_fils = d_faux;
1258:
1259: (*s_etat_processus).erreur_systeme =
1260: (*s_etat_processus).erreur_systeme_processus_fils;
1261: (*s_etat_processus).erreur_execution =
1262: (*s_etat_processus).erreur_execution_processus_fils;
1263: (*s_etat_processus).arret_si_exception = d_vrai;
1264:
1265: if ((*s_etat_processus).pid_erreur_processus_fils == getpid())
1266: {
1267: (*s_etat_processus).invalidation_message_erreur = d_faux;
1268: }
1269: else
1270: {
1271: (*s_etat_processus).invalidation_message_erreur = d_vrai;
1272: }
1273: }
1274:
1275: if (((*s_etat_processus).erreur_execution != d_ex) ||
1276: ((*s_etat_processus).erreur_systeme != d_es) ||
1277: ((*s_etat_processus).exception != d_ep))
1278: {
1279: (*s_etat_processus).niveau_derniere_erreur =
1280: (*s_etat_processus).niveau_courant;
1281:
1282: if ((*s_etat_processus).mode_execution_programme == 'Y')
1283: {
1.21 bertrand 1284: if ((*s_etat_processus).instruction_derniere_erreur != NULL)
1285: {
1286: free((*s_etat_processus).instruction_derniere_erreur);
1287: (*s_etat_processus).instruction_derniere_erreur = NULL;
1288: }
1289:
1.1 bertrand 1290: if ((*s_etat_processus).instruction_courante == NULL)
1291: {
1292: if (((*s_etat_processus).instruction_derniere_erreur =
1293: malloc(16 * sizeof(unsigned char))) == NULL)
1294: {
1295: (*s_etat_processus).erreur_systeme =
1296: d_es_allocation_memoire;
1297: return;
1298: }
1299:
1300: strcpy((*s_etat_processus).instruction_derniere_erreur,
1301: "<not available>");
1302: }
1303: else
1304: {
1305: if (((*s_etat_processus).instruction_derniere_erreur =
1306: malloc((strlen((*s_etat_processus)
1307: .instruction_courante) + 1) *
1308: sizeof(unsigned char))) == NULL)
1309: {
1310: (*s_etat_processus).erreur_systeme =
1311: d_es_allocation_memoire;
1312: return;
1313: }
1314:
1315: strcpy((*s_etat_processus).instruction_derniere_erreur,
1316: (*s_etat_processus).instruction_courante);
1317: }
1318: }
1319: else
1320: {
1.21 bertrand 1321: if ((*s_etat_processus).objet_courant != NULL)
1.1 bertrand 1322: {
1.21 bertrand 1323: if ((*s_etat_processus).instruction_derniere_erreur != NULL)
1324: {
1325: free((*s_etat_processus).instruction_derniere_erreur);
1326: (*s_etat_processus).instruction_derniere_erreur = NULL;
1327: }
1328:
1329: if (((*s_etat_processus).instruction_derniere_erreur =
1330: formateur(s_etat_processus, 0,
1331: (*s_etat_processus).objet_courant)) == NULL)
1332: {
1333: return;
1334: }
1335:
1336: (*s_etat_processus).objet_courant = NULL;
1.1 bertrand 1337: }
1338: }
1339: }
1340: }
1341:
1342: return;
1343: }
1344:
1345:
1346: /*
1347: ================================================================================
1348: Traitement asynchrone des erreurs de la bibliothèque GSL
1349: ================================================================================
1350: Entrées :
1351: --------------------------------------------------------------------------------
1352: Sorties :
1353: --------------------------------------------------------------------------------
1354: Effets de bord : néant
1355: ================================================================================
1356: */
1357:
1358: void
1359: traitement_asynchrone_exceptions_gsl(struct_processus *s_etat_processus)
1360: {
1361: if ((*s_etat_processus).var_volatile_exception_gsl != 0)
1362: {
1363: switch((*s_etat_processus).var_volatile_exception_gsl)
1364: {
1365: case GSL_EINVAL :
1366: {
1367: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
1368: break;
1369: }
1370:
1371: case GSL_EDOM :
1372: {
1373: (*s_etat_processus).exception = d_ep_domaine_definition;
1374: break;
1375: }
1376:
1377: case GSL_ERANGE :
1378: {
1379: (*s_etat_processus).exception = d_ep_resultat_indefini;
1380: break;
1381: }
1382:
1383: case GSL_EZERODIV :
1384: {
1385: (*s_etat_processus).exception = d_ep_division_par_zero;
1386: break;
1387: }
1388:
1389: case GSL_EUNDRFLW :
1390: {
1391: (*s_etat_processus).exception = d_ep_underflow;
1392: break;
1393: }
1394:
1395: case GSL_EOVRFLW :
1396: {
1397: (*s_etat_processus).exception = d_ep_overflow;
1398: break;
1399: }
1400:
1401: case GSL_ENOMEM :
1402: {
1403: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
1404: break;
1405: }
1406:
1407: case GSL_ELOSS :
1408: {
1409: (*s_etat_processus).exception = d_ep_perte_precision;
1410: break;
1411: }
1412:
1413: default :
1414: {
1415: (*s_etat_processus).erreur_execution =
1416: d_ex_routines_mathematiques;
1417: break;
1418: }
1419: }
1420:
1421: (*s_etat_processus).var_volatile_exception_gsl = 0;
1422: }
1423:
1424: return;
1425: }
1426:
1427: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>