1: /*
2: ================================================================================
3: RPL/2 (R) version 4.0.16
4: Copyright (C) 1989-2010 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: #ifndef INCLUSION_RPLARGS
24: # define INCLUSION_RPLARGS
25:
26: /*
27: ================================================================================
28: INCLUSIONS
29: ================================================================================
30: */
31:
32: # define RPLARGS
33: # define struct_processus void
34: # include "rpl.h"
35:
36: /*
37: ================================================================================
38: MACROS SPECIFIQUES
39: ================================================================================
40: */
41:
42: #define allocation(a) librpl_allocation((*rpl_arguments).s_etat_processus, a)
43: #define copie_objet(a, b) librpl_copie_objet( \
44: (*rpl_arguments).s_etat_processus, a, b)
45: #define liberation(a) librpl_liberation((*rpl_arguments).s_etat_processus, a)
46:
47: /*
48: --------------------------------------------------------------------------------
49: Types
50: --------------------------------------------------------------------------------
51: */
52:
53: #define declareObject(object) struct_objet *object = NULL
54: #define declareInteger(integer) integer8 integer
55: #define declareReal(real) real8 real
56: #define declareComplex(complex) complex16 complex
57: #define declareDaisyChain(daisyChain) struct_liste_chainee *daisyChain = NULL
58:
59: #define getDaisyChainFromList(list, daisyChain) { \
60: typeof(list) __list = list; \
61: daisyChain = NULL; \
62: ifIsList(__list) { daisyChain = (*__list).objet; } \
63: else executionError("Type mistmatch error"); } while(0)
64:
65: #define fetchElementFromDaisyChain(daisyChain) \
66: ({ typeof(daisyChain) __daisyChain = daisyChain; \
67: if (__daisyChain == NULL) executionError("End of daisy chain"); \
68: (__daisyChain == NULL) ? NULL : (*__daisyChain).donnee; })
69:
70: #define replaceElementIntoDaisyChain(daisyChain, element) \
71: do { typeof(daisyChain) __daisyChain = daisyChain; \
72: if (__daisyChain == NULL) executionError("Nullified daisy chain"); \
73: (*__daisyChain).donnee = element; } while(0)
74:
75: #define nextElementOfDaisyChain(daisyChain) \
76: ({ typeof(daisyChain) __daisyChain = daisyChain; \
77: if (__daisyChain == NULL) executionError("End of daisy chain"); \
78: (__daisyChain == NULL) ? NULL : (*__daisyChain).suivant; })
79:
80: #define null NULL
81: #define nullify(ptr) { ptr = NULL; } while(0)
82: #define nullified(ptr) ((ptr) == NULL)
83:
84: #define postIncr(x) (x++)
85: #define preIncr(x) (++x)
86: #define postDecr(x) (x--)
87: #define preDecr(x) (--x)
88:
89: #define eq ==
90: #define ne !=
91: #define ge >=
92: #define gt >
93: #define le <=
94: #define lt <
95: #define not !
96: #define and &&
97: #define or ||
98: #define false 0
99: #define true -1
100:
101: #define setFalse(a) a = false
102: #define setTrue(a) a = true
103:
104: #define logical int
105: #define string char *
106: #define integer int
107:
108: #define declareStructure typedef struct {
109: #define declareUnion typedef union {
110: #define as(name) } name;
111:
112: #define target(a) (*a)
113: #define address(a) (&a)
114:
115: #define beginGroup {
116: #define endGroup }
117: #define beginMacro beginGroup
118: #define endMacro endGroup while(0)
119: #define stopRequest test_arret((*rpl_arguments).s_etat_processus)
120:
121: /*
122: --------------------------------------------------------------------------------
123: Constructeurs
124: --------------------------------------------------------------------------------
125: */
126:
127: #define HEADER \
128: int __constante; \
129: logical1 __evaluation; \
130: logical1 __validation_instruction = d_faux; \
131: logical1 __presence_aide = d_faux; \
132: logical1 __presence_validation = d_faux; \
133: unsigned char __indice_bit; \
134: unsigned char __indice_bloc; \
135: unsigned char __taille_bloc; \
136: unsigned char __type; \
137: t_8_bits __masque; \
138: { \
139: (*rpl_arguments).instruction_valide = 'Y'; \
140: (*rpl_arguments).erreur = 0; \
141: __constante = 0; \
142: __evaluation = d_faux;
143:
144: #define FUNCTION \
145: if (__validation_instruction == d_vrai) return; \
146: if (__presence_aide == d_faux) \
147: { \
148: systemError("Help string not defined"); \
149: } \
150: else if (__presence_validation == d_faux) \
151: { \
152: systemError("Number of arguments not defined"); \
153: } \
154: __indice_bit = 0; \
155: __indice_bloc = 0; \
156: __taille_bloc = 0; \
157: __type = 0; \
158: __masque = 0; \
159: {
160:
161: #define END \
162: strcpy((char *) __function_name, ""); \
163: if (__constante != 0) \
164: systemError("Constant definition error"); \
165: } } \
166: return;
167:
168: /*
169: --------------------------------------------------------------------------------
170: Déclaration des fonctions externes
171: --------------------------------------------------------------------------------
172: */
173:
174: #define declareExternalFunction(name) \
175: void __external_##name(struct_rpl_arguments *rpl_arguments) { \
176: char __function_name[] = "__external_"#name;
177:
178: #define useExternalFunction(function) \
179: void __external_##function(struct_rpl_arguments *rpl_arguments)
180:
181: #define libraryName(name) char __library_name[] = #name;
182:
183: #define __onLoading void __runOnLoading(struct_rpl_arguments *rpl_arguments)
184: #define __onClosing void __runOnClosing(struct_rpl_arguments *rpl_arguments)
185: #define declareSubroutine(when) __##when { \
186: char __function_name[] = #when; \
187: HEADER \
188: declareHelpString(""); \
189: numberOfArguments(0); \
190: FUNCTION
191: #define endSubroutine END }
192:
193: #define notice(s, ...) do { ufprintf(s, __VA_ARGS__); fflush(s); } while(0)
194: #define logger(...) do { syslog(LOG_NOTICE, __VA_ARGS__); } while(0)
195:
196: #define exportExternalFunctions(...) \
197: char **__external_symbols(unsigned long *nb_symbols, \
198: const char *version) { \
199: char arguments[] = #__VA_ARGS__; \
200: char **tableau; \
201: char *ptr1, *ptr2; \
202: int drapeau; \
203: unsigned long i; \
204: if (strcmp(version, _d_version_rpl) != 0) \
205: { \
206: (*nb_symbols) = -1; return(NULL); \
207: } \
208: (*nb_symbols) = 0; ptr1 = arguments; drapeau = 0; \
209: while((*ptr1) != 0) \
210: { \
211: if (((*ptr1) != ',') && ((*ptr1) != ' ')) drapeau = -1; \
212: ptr1++; \
213: } \
214: if (drapeau == 0) return(NULL); \
215: ptr1 = arguments; (*nb_symbols) = 1; \
216: while((*ptr1) != 0) if ((*ptr1++) == ',') (*nb_symbols)++; \
217: if ((tableau = malloc((*nb_symbols) * sizeof(char *))) == NULL) \
218: return(NULL); \
219: ptr2 = arguments; i = 0; \
220: while(*ptr2 != 0) \
221: { \
222: while(((*ptr2) == ' ') || ((*ptr2) == ',')) ptr2++; \
223: ptr1 = ptr2; \
224: while(((*ptr2) != 0) && ((*ptr2) != ',') && ((*ptr2) != ' ')) \
225: ptr2++; \
226: if ((tableau[i] = malloc((ptr2 + 2 + \
227: strlen(__library_name) - ptr1) * \
228: sizeof(unsigned char))) == NULL) \
229: return(NULL); \
230: sprintf(tableau[i], "%s$", __library_name); \
231: strncat(&tableau[i][strlen(tableau[i])], ptr1, ptr2 - ptr1); \
232: i++; \
233: if ((*ptr2) != 0) \
234: { \
235: while((*ptr2) == ' ') ptr2++; \
236: if ((*ptr2) == ',') ptr2++; \
237: } \
238: } \
239: (*nb_symbols) = i; \
240: return(tableau); \
241: }
242:
243: #define endExternalFunction return; }
244:
245: #define callExternalFunction(function) { \
246: __taille_bloc = sizeof(t_8_bits) * 8; \
247: __indice_bloc = (35 - 1) / __taille_bloc; \
248: __indice_bit = (35 - 1) % __taille_bloc; \
249: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
250: __evaluation = ((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) \
251: ? d_vrai : d_faux; \
252: __masque = ~(((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1)); \
253: (*rpl_arguments).drapeaux_etat[__indice_bloc] &= __masque; \
254: __external_##function(rpl_arguments); \
255: if (__evaluation == d_vrai) \
256: { \
257: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
258: (*rpl_arguments).drapeaux_etat[__indice_bloc] |= __masque; \
259: } \
260: else \
261: { \
262: __masque = ~(((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1)); \
263: (*rpl_arguments).drapeaux_etat[__indice_bloc] &= __masque; \
264: } } while(0)
265:
266: /*
267: --------------------------------------------------------------------------------
268: Macros spécifiques à l'en-tête
269: --------------------------------------------------------------------------------
270: */
271:
272: #define declareHelpString(h) { \
273: __presence_aide = d_vrai; \
274: if ((*rpl_arguments).affichage_arguments == 'Y') \
275: { \
276: uprintf("%s\n", h); \
277: return; \
278: } } while(0)
279:
280: #define declareSymbolicConstant { \
281: numberOfArguments(0); \
282: (*rpl_arguments).constante_symbolique = 'Y'; \
283: __constante++; } while(0)
284:
285: #define numberOfArguments(n) { \
286: __presence_validation = d_vrai; \
287: if ((*rpl_arguments).test_instruction == 'Y') \
288: { \
289: if (n < 0) \
290: systemError("Number of arguments must be positive or null"); \
291: (*rpl_arguments).nombre_arguments = n; \
292: __validation_instruction = d_vrai; \
293: } \
294: else \
295: { \
296: __taille_bloc = sizeof(t_8_bits) * 8; \
297: __indice_bloc = (31 - 1) / __taille_bloc; \
298: __indice_bit = (31 - 1) % __taille_bloc; \
299: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
300: if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
301: { \
302: (*rpl_arguments).l_base_pile_last = \
303: sauvegarde_arguments(rpl_arguments, n); \
304: } \
305: } } while(0)
306:
307: /*
308: --------------------------------------------------------------------------------
309: Gestion des boucles
310: --------------------------------------------------------------------------------
311: */
312:
313: #define loop(b, e, s) for(b; e; s) {
314: #define endLoop }
315:
316: #define repeatWhile(c) while(c) {
317: #define endWhile }
318:
319: #define doUntil do {
320: #define repeatUntil(c) } while(!(c));
321:
322: #define select(s) switch(s) {
323: #define endSelect }
324: #define nonExclusiveCase(c) case c: {
325: #define endNonExclusiveCase }
326: #define exclusiveCase(c) case c: {
327: #define endExclusiveCase break; }
328: #define defaultCase default:
329: #define endDefaultCase break; }
330:
331: /*
332: --------------------------------------------------------------------------------
333: Gestion des erreurs
334: --------------------------------------------------------------------------------
335: */
336:
337: #define returnOnError(...) { \
338: if ((*rpl_arguments).erreur != 0) \
339: { \
340: __VA_ARGS__; \
341: return; \
342: } } while(0)
343:
344: #define systemError(message) { \
345: (*rpl_arguments).erreur = __LINE__; \
346: (*rpl_arguments).type_erreur = 'S'; \
347: (*rpl_arguments).message_erreur = (unsigned char *) message; \
348: return; } while(0)
349:
350: #define executionError(message) { \
351: (*rpl_arguments).erreur = __LINE__; \
352: (*rpl_arguments).type_erreur = 'E'; \
353: (*rpl_arguments).message_erreur = (unsigned char *) message; } while(0)
354:
355: #define onError(...) \
356: do { if (((*rpl_arguments).type_erreur == 'E') && \
357: ((*rpl_arguments).erreur != 0)) { __VA_ARGS__; \
358: (*rpl_arguments).erreur = 0; } } while(0)
359:
360: #define onExecution(...) \
361: do { if (((*rpl_arguments).type_erreur == 'E') && \
362: ((*rpl_arguments).erreur == 0)) { __VA_ARGS__; } } while(0)
363:
364: /*
365: --------------------------------------------------------------------------------
366: Gestion de la pile opérationnelle
367: --------------------------------------------------------------------------------
368: */
369:
370: #define pushOnStack(object) { \
371: if (((*rpl_arguments).l_base_pile = \
372: empilement_pile_operationnelle(rpl_arguments, object)) == NULL) \
373: systemError("Memory allocation error"); \
374: if ((*object).nombre_occurrences == 1) object = NULL; } while(0)
375:
376: #define pullFromStack(object, ...) { \
377: (*rpl_arguments).l_base_pile = \
378: depilement_pile_operationnelle(rpl_arguments, &object); \
379: if (object == NULL) \
380: { \
381: executionError("Too few arguments"); \
382: } \
383: else \
384: { \
385: if (strlen(#__VA_ARGS__) == 0) \
386: { \
387: systemError("Undefined type"); \
388: } \
389: else \
390: { \
391: __type = 0; \
392: if (strstr(#__VA_ARGS__, "integer") != NULL) \
393: if ((*object).type == INT) __type = 1; \
394: if (strstr(#__VA_ARGS__, "real") != NULL) \
395: if ((*object).type == REL) __type = 1; \
396: if (strstr(#__VA_ARGS__, "complex") != NULL) \
397: if ((*object).type == CPL) __type = 1; \
398: if (strstr(#__VA_ARGS__, "string") != NULL) \
399: if ((*object).type == CHN) __type = 1; \
400: if (strstr(#__VA_ARGS__, "list") != NULL) \
401: if ((*object).type == LST) __type = 1; \
402: if (strstr(#__VA_ARGS__, "unknown") != NULL) \
403: __type = 1; \
404: if (__type == 0) \
405: { \
406: executionError("Type not allowed"); \
407: } \
408: } \
409: } } while(0)
410:
411: /*
412: --------------------------------------------------------------------------------
413: Gestion des objets
414: --------------------------------------------------------------------------------
415: */
416:
417: #define then {
418: #define endIf }
419: #define elseIf } else if
420: #define orElse } else {
421:
422: // Constantes symboliques
423:
424: #define createSymbolicConstant(object, type, value) { \
425: if ((strcmp(#type, "integer") != 0) && (strcmp(#type, "real") != 0)) \
426: systemError("Type not allowed for symbolic constant"); \
427: __taille_bloc = sizeof(t_8_bits) * 8; \
428: __indice_bloc = (35 - 1) / __taille_bloc; \
429: __indice_bit = (35 - 1) % __taille_bloc; \
430: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
431: if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
432: { \
433: createNameObject(object); \
434: { \
435: char *__constant_name; \
436: if ((__constant_name = malloc((strlen(__library_name) + \
437: strlen(__function_name) - 9) * sizeof(char))) == NULL) \
438: systemError("Memory allocation error"); \
439: sprintf(__constant_name, "%s$%s", __library_name, \
440: &(__function_name[11])); \
441: setName(object, __constant_name); \
442: free(__constant_name); \
443: } \
444: } \
445: else \
446: { \
447: if (strcmp(#type, "integer") == 0) \
448: { \
449: createIntegerObject(object); \
450: setInteger(object, value); \
451: } \
452: else if (strcmp(#type, "real") == 0) \
453: { \
454: createRealObject(object); \
455: setReal(object, value); \
456: } \
457: } \
458: __constante--; } while(0)
459:
460: #define createSymbolicComplexConstant(object, rp, ip) { \
461: __taille_bloc = sizeof(t_8_bits) * 8; \
462: __indice_bloc = (35 - 1) / __taille_bloc; \
463: __indice_bit = (35 - 1) % __taille_bloc; \
464: __masque = ((t_8_bits) 1) << (__taille_bloc - __indice_bit - 1); \
465: if (((*rpl_arguments).drapeaux_etat[__indice_bloc] & __masque) != 0) \
466: { \
467: createNameObject(object); \
468: { \
469: char *__constant_name; \
470: if ((__constant_name = malloc((strlen(__library_name) + \
471: strlen(__function_name) + 2) * sizeof(char))) == NULL) \
472: systemError("Memory allocation error"); \
473: sprintf(__constant_name, "%s$%s", __library_name, \
474: __function_name); \
475: setName(object, __constant_name); \
476: free(__constant_name); \
477: } \
478: } \
479: else \
480: { \
481: createComplexObject(object); \
482: setComplex(object, rp, im); \
483: } \
484: __constante--; } while(0)
485:
486: // Integer
487:
488: #define setInteger(object, value) { \
489: ifIsInteger(object) \
490: { \
491: if ((*object).nombre_occurrences > 1) \
492: { \
493: struct_objet *__tmp_object; \
494: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
495: systemError("Memory allocation error"); \
496: liberation(object); \
497: object = __tmp_object; \
498: } \
499: (*((integer8 *) (*object).objet)) = (integer8) value; \
500: } \
501: else executionError("Type mistmatch error"); } while(0)
502:
503: #define isInteger(object) \
504: ((*object).type == INT)
505:
506: #define ifIsInteger(object) if (isInteger(object))
507: #define elseIfIsInteger(object) } else ifIsInteger(object)
508:
509: #define getInteger(object, value) { \
510: value = 0; \
511: ifIsInteger(object) value = (*((integer8 *) (*object).objet)); \
512: else executionError("Type mismatch error"); } while(0)
513:
514: #define createIntegerObject(object) { \
515: if (object != NULL) \
516: systemError("Reallocated object"); \
517: if ((object = allocation(INT)) == NULL) \
518: systemError("Memory allocation error"); \
519: setInteger(object, 0); } while(0)
520:
521: // Real
522:
523: #define setReal(object, value) { \
524: ifIsReal(object) \
525: { \
526: if ((*object).nombre_occurrences > 1) \
527: { \
528: struct_objet *__tmp_object; \
529: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
530: systemError("Memory allocation error"); \
531: liberation(object); \
532: object = __tmp_object; \
533: } \
534: (*((real8 *) (*object).objet)) = (real8) value; \
535: } \
536: else executionError("Type mistmatch error"); } while(0)
537:
538: #define isReal(object) \
539: ((*object).type == REL)
540:
541: #define ifIsReal(object) if (isReal(object))
542: #define elseIfIsReal(object) } else ifIsReal(object)
543:
544: #define getReal(object, value) { \
545: value = 0; \
546: ifIsReal(object) value = (*((real8 *) (*object).objet)); \
547: else executionError("Type mismatch error"); } while(0)
548:
549: #define createRealObject(object) { \
550: if (object != NULL) \
551: systemError("Reallocated object"); \
552: if ((object = allocation(REL)) == NULL) \
553: systemError("Memory allocation error"); \
554: setReal(object, 0); } while(0)
555:
556: // Complex
557:
558: #define setComplex(object, rp, ip) { \
559: typeof(rp) __rp = rp; \
560: typeof(ip) __ip = ip; \
561: ifIsComplex(object) \
562: { \
563: if ((*object).nombre_occurrences > 1) \
564: { \
565: struct_objet *__tmp_object; \
566: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
567: systemError("Memory allocation error"); \
568: liberation(object); \
569: object = __tmp_object; \
570: } \
571: setRealPartOfComplex(object, __rp); \
572: setImaginaryPartOfComplex(object, __ip); \
573: } \
574: else executionError("Type mismatch error"); } while(0)
575:
576: #define setRealPartOfComplex(object, value) { \
577: if ((*object).nombre_occurrences > 1) \
578: { \
579: struct_objet *__tmp_object; \
580: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
581: systemError("Memory allocation error"); \
582: liberation(object); \
583: object = __tmp_object; \
584: } \
585: ifIsComplex(object) (*((complex16 *) (*object).objet)).partie_reelle = \
586: value; \
587: else executionError("Type mismatch error"); } while(0)
588:
589: #define setImaginaryPartOfComplex(object, value) { \
590: if ((*object).nombre_occurrences > 1) \
591: { \
592: struct_objet *__tmp_object; \
593: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
594: systemError("Memory allocation error"); \
595: liberation(object); \
596: object = __tmp_object; \
597: } \
598: (*((complex16 *) (*object).objet)).partie_imaginaire = value; \
599: else executionError("Type mismatch error"); } while(0)
600:
601: #define getRealPartOfComplex(object, value) \
602: value = (*((complex16 *) (*object).objet)).partie_reelle
603:
604: #define getImaginaryPartOfComplex(object, value) \
605: value = (*((complex16 *) (*object).objet)).partie_imaginaire
606:
607: #define isComplex(object) \
608: ((*object).type == CPL)
609:
610: #define ifIsComplex(object) if (isComplex(object))
611: #define elseIfIsComplex(object) } else ifIsComplex(object)
612:
613: #define getComplex(object, value) { \
614: value.partie_reelle = 0; \
615: value.partie_imaginaire = 0; \
616: ifIsComplex(object) value = (*((complex16 *) (*object).objet)); \
617: else systemError("Not a complex"); } while(0)
618:
619: #define createComplexObject(object) { \
620: if (object != NULL) \
621: systemError("Reallocated object"); \
622: if ((object = allocation(CPL)) == NULL) \
623: systemError("Memory allocation error"); \
624: setComplex(object, 0, 0); } while(0)
625:
626: // Generalized vectors
627:
628: #define createVectorObject(object, size, otype, structure, cat) { \
629: integer8 i; \
630: if (object != NULL) \
631: systemError("Reallocated object"); \
632: if ((object = allocation(cat)) == NULL) \
633: systemError("Memory allocation error"); \
634: (*((structure *) (*object).objet)).taille = size; \
635: if (((*((structure *) (*object).objet)).tableau = \
636: malloc(size * sizeof(otype))) == NULL) \
637: systemError("Memory allocation error"); \
638: if (cat != VCX) \
639: { \
640: if (cat == VIN) \
641: (*((structure *) (*object).objet)).type = 'I'; \
642: else \
643: (*((structure *) (*object).objet)).type = 'R'; \
644: for(i = 0; i < size; ((otype *) (*((structure *) (*object).objet)) \
645: .tableau)[i++] = (otype) 0); \
646: } \
647: else \
648: { \
649: (*((structure *) (*object).objet)).type = 'C'; \
650: for(i = 0; i < size; i++) \
651: { \
652: ((complex16 *) (*((structure *) (*object).objet)).tableau)[i] \
653: .partie_reelle = 0; \
654: ((complex16 *) (*((structure *) (*object).objet)).tableau)[i] \
655: .partie_imaginaire = 0; \
656: } \
657: } } while(0)
658:
659: // Integer vector
660:
661: #define setIntegerIntoVector(object, value, position) { \
662: typeof(position) __position = position; \
663: ifIsIntegerVector(object) \
664: { \
665: if ((*object).nombre_occurrences > 1) \
666: { \
667: struct_objet *__tmp_object; \
668: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
669: systemError("Memory allocation error"); \
670: liberation(object); \
671: object = __tmp_object; \
672: } \
673: __position--; \
674: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
675: (*object).objet)).taille)) \
676: { executionError("Element out of range"); } \
677: else \
678: ((integer8 *) (*((struct_vecteur *) (*object).objet)).tableau) \
679: [__position] = (integer8) value; \
680: } \
681: else executionError("Type mistmatch error"); } while(0)
682:
683: #define isIntegerVector(object) \
684: ((*object).type == VIN)
685:
686: #define ifIsIntegerVector(object) if (isIntegerVector(object))
687: #define elseIfIsIntegerVector(object) } else ifIsIntegerVector(object)
688:
689: #define getIntegerFromVector(object, value, position) { \
690: typeof(position) __position = position; \
691: value = 0; \
692: ifIsIntegerVector(object) \
693: { \
694: __position--; \
695: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
696: (*object).objet)).taille)) \
697: executionError("Element out of range"); \
698: else \
699: value = ((integer8 *) (*((struct_vecteur *) (*object).objet)) \
700: .tableau)[__position]; \
701: } \
702: else executionError("Type mismatch error"); } while(0)
703:
704: #define createIntegerVectorObject(object, size) \
705: createVectorObject(object, size, integer8, struct_vecteur, VIN)
706:
707: // Real vector
708:
709: #define setRealIntoVector(object, value, position) { \
710: typeof(position) __position = position; \
711: ifIsRealVector(object) \
712: { \
713: if ((*object).nombre_occurrences > 1) \
714: { \
715: struct_objet *__tmp_object; \
716: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
717: systemError("Memory allocation error"); \
718: liberation(object); \
719: object = __tmp_object; \
720: } \
721: __position--; \
722: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
723: (*object).objet)).taille)) \
724: { executionError("Element out of range"); } \
725: else \
726: ((real8 *) (*((struct_vecteur *) (*object).objet)).tableau) \
727: [__position] = (real8) value; \
728: } \
729: else executionError("Type mistmatch error"); } while(0)
730:
731: #define isRealVector(object) \
732: ((*object).type == VRL)
733:
734: #define ifIsRealVector(object) if (isRealVector(object))
735: #define elseIfIsRealVector(object) } else ifIsRealVector(object)
736:
737: #define getRealFromVector(object, value, position) { \
738: typeof(position) __position = position; \
739: value = 0; \
740: ifIsRealVector(object) \
741: { \
742: __position--; \
743: if ((__position < 0) || (__position >= (*((struct_vecteur *) \
744: (*object).objet)).taille)) \
745: executionError("Element out of range"); \
746: value = ((real8 *) (*((struct_vecteur *) (*object).objet)).tableau) \
747: [__position]; \
748: } \
749: else executionError("Type mismatch error"); } while(0)
750:
751: #define createRealVectorObject(object, size) \
752: createVectorObject(object, size, real8, struct_vecteur, VRL)
753:
754: // A FIXER
755:
756: #define createComplexVectorObject
757:
758: #define createIntegerMatrixObject
759:
760: #define createRealMatrixObject
761:
762: #define createComplexMatrixObject
763:
764: // Binary integer
765:
766: #define setBinaryInteger(object, value) { \
767: ifIsBinaryInteger(object) \
768: { \
769: if ((*object).nombre_occurrences > 1) \
770: { \
771: struct_objet *__tmp_object; \
772: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
773: systemError("Memory allocation error"); \
774: liberation(object); \
775: object = __tmp_object; \
776: } \
777: (*((integer8 *) (*object).objet)) = (integer8) value; \
778: } \
779: else executionError("Type mistmatch error"); } while(0)
780:
781: #define isBinaryInteger(object) \
782: ((*object).type == BIN)
783:
784: #define ifIsBinaryInteger(object) if (isBinaryInteger(object))
785: #define elseIfIsBinaryInteger(object) } else ifIsBinaryInteger(object)
786:
787: #define getBinaryInteger(object, value) { \
788: value = 0; \
789: ifIsBinaryInteger(object) value = (*((integer8 *) (*object).objet)); \
790: else executionError("Type mismatch error"); } while(0)
791:
792: #define createBinaryIntegerObject(object) { \
793: if (object != NULL) \
794: systemError("Reallocated object"); \
795: if ((object = allocation(BIN)) == NULL) \
796: systemError("Memory allocation error"); \
797: setBinaryInteger(object, 0); } while(0)
798:
799: // Name
800:
801: #define isName(object) \
802: ((*object).type == NOM)
803:
804: #define ifIsName(object) if (isName(object))
805: #define elseIfIsName(object) } else if (isName(object))
806:
807: #define setName(object, value) { \
808: ifIsName(object) \
809: { \
810: if ((*object).nombre_occurrences > 1) \
811: { \
812: struct_objet *__tmp_object; \
813: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
814: systemError("Memory allocation error"); \
815: liberation(object); \
816: object = __tmp_object; \
817: } \
818: free((*((struct_nom *) (*object).objet)).nom); \
819: (*((struct_nom *) (*object).objet)).symbole = d_faux; \
820: if (((*((struct_nom *) (*object).objet)).nom = malloc( \
821: (strlen(value) + 1) * sizeof(unsigned char))) == NULL) \
822: systemError("Memory allocation error"); \
823: strcpy((char *) (*((struct_nom *) (*object).objet)).nom, \
824: (char *) value); \
825: } \
826: else executionError("Type mistmatch error"); } while(0)
827:
828: #define createNameObject(object) { \
829: if (object != NULL) \
830: systemError("Reallocated object"); \
831: if ((object = allocation(NOM)) == NULL) \
832: systemError("Memory allocation error"); \
833: (*((struct_nom *) (*object).objet)).symbole = d_faux; \
834: if (((*((struct_nom *) (*object).objet)).nom = malloc( \
835: sizeof(unsigned char))) == NULL) \
836: systemError("Memory allocation error"); \
837: strcpy((char *) (*((struct_nom *) (*object).objet)).nom, ""); } while(0)
838:
839: // String
840:
841: #define isString(object) \
842: ((*object).type == CHN)
843:
844: #define ifIsString(object) if (isString(object))
845: #define elseIfIsString(object) else if (isString(objet))
846:
847: #define setString(object, string) { \
848: ifIsString(object) \
849: { \
850: if ((*object).nombre_occurrences > 1) \
851: { \
852: struct_objet *__tmp_object; \
853: if ((__tmp_object = copie_objet(object, 'O')) == NULL) \
854: systemError("Memory allocation error"); \
855: liberation(object); \
856: object = __tmp_object; \
857: } \
858: free((unsigned char *) (*object).objet); \
859: if (((*object).objet = malloc((strlen(string) + 1) * \
860: sizeof(unsigned char))) == NULL) \
861: systemError("Memory allocation error"); \
862: strcpy((char *) (*object).objet, string); \
863: } \
864: else executionError("Type mistmatch error"); } while(0)
865:
866: #define getString(object, string) { \
867: string = NULL; \
868: ifIsString(object) string = (char *) (*object).objet; \
869: else executionError("Type mismatch error"); } while(0)
870:
871: #define createStringObject(object) { \
872: if (object != NULL) \
873: systemError("Reallocated object"); \
874: if ((object = allocation(CHN)) == NULL) \
875: systemError("Memory allocation error"); \
876: if (((*object).objet = malloc(sizeof(unsigned char))) == NULL) \
877: systemError("Memory allocation error"); \
878: strcpy((char *) (*object).objet, ""); } while(0)
879:
880: // List
881:
882: #define isList(object) \
883: ((*object).type == LST)
884:
885: #define ifIsList(object) if (isList(object))
886: #define elseIfIsList(object) else if (isList(object))
887:
888: #define createListObject(object) { \
889: if (object != NULL) \
890: systemError("Reallocated object"); \
891: if ((object = allocation(LST)) == NULL) \
892: systemError("Memory allocation error"); \
893: (*object).objet = NULL; } while(0)
894:
895: #define addObjectToList(list, object) { \
896: ifIsList(list) \
897: { \
898: struct_objet *__tmp_object; \
899: if ((__tmp_object = copie_objet(list, 'N')) == NULL) \
900: systemError("Memory allocation error"); \
901: liberation(list); \
902: list = __tmp_object; \
903: if ((*list).objet == NULL) \
904: { \
905: if (((*list).objet = malloc(sizeof(struct_liste_chainee))) \
906: == NULL) \
907: systemError("Memory allocation error"); \
908: (*((struct_liste_chainee *) (*list).objet)).suivant = NULL; \
909: (*((struct_liste_chainee *) (*list).objet)).donnee = object; \
910: } \
911: else \
912: { \
913: struct_liste_chainee *l_element_courant; \
914: l_element_courant = (*list).objet; \
915: while((*l_element_courant).suivant != NULL) \
916: l_element_courant = (*l_element_courant).suivant; \
917: if (((*l_element_courant).suivant = \
918: malloc(sizeof(struct_liste_chainee))) == NULL) \
919: systemError("Memory allocation error"); \
920: l_element_courant = (*l_element_courant).suivant; \
921: (*l_element_courant).suivant = NULL; \
922: (*l_element_courant).donnee = object; \
923: } \
924: object = NULL; \
925: } \
926: else executionError("Type mistmatch error"); } while(0)
927:
928: #define insertObjectIntoList(list, object) { \
929: ifIsList(list) \
930: { \
931: struct_objet *__tmp_object; \
932: if ((__tmp_object = copie_objet(list, 'N')) == NULL) \
933: systemError("Memory allocation error"); \
934: liberation(list); \
935: list = __tmp_object; \
936: if ((*list).objet == NULL) \
937: { \
938: if (((*list).objet = malloc(sizeof(struct_liste_chainee))) \
939: == NULL) \
940: systemError("Memory allocation error"); \
941: (*((struct_liste_chainee *) (*list).objet)).suivant = NULL; \
942: (*((struct_liste_chainee *) (*list).objet)).donnee = object; \
943: } \
944: else \
945: { \
946: struct_liste_chainee *l_element_courant; \
947: if ((l_element_courant = \
948: malloc(sizeof(struct_liste_chainee))) == NULL) \
949: systemError("Memory allocation error"); \
950: (*l_element_courant).donnee = object; \
951: (*l_element_courant).suivant = (*list).objet; \
952: (*list).objet = l_element_courant; \
953: } \
954: object = NULL; \
955: } \
956: else executionError("Type mistmatch error"); } while(0)
957:
958: #define removeObjectFromList(list, object) \
959: ifIsList(list) \
960: { \
961: if ((*object).objet == NULL) \
962: { \
963: struct_objet *__tmp_object; \
964: if ((__tmp_object = copie_objet(list, 'N')) == NULL) \
965: systemError("Memory allocation error"); \
966: liberation(object); \
967: object = __tmp_object; \
968: \
969: \
970: \
971: \
972: } \
973: } \
974: else executionError("Type mistmatch error"); } while(0)
975:
976: #define getObjectFromList(list, position, object)
977:
978: #define putObjectIntoList(list, position, object)
979:
980: #define getListFromList(list, position1, position2, object)
981:
982: #define listLength(list, length) { \
983: if (list == NULL) executionError("Nullified object"); \
984: if ((*list).type != LST) \
985: executionError("Type mistmatch error"); \
986: { \
987: struct_liste_chainee *l_element_courant; \
988: length = 0; \
989: l_element_courant = (*list).objet; \
990: while(l_element_courant != NULL) \
991: { \
992: l_element_courant = (*l_element_courant).suivant; \
993: length++; \
994: } \
995: } } while(0)
996:
997:
998: /*
999: --------------------------------------------------------------------------------
1000: Destruction d'un objet
1001: --------------------------------------------------------------------------------
1002: */
1003:
1004: #define freeObject(object) \
1005: { \
1006: if (object == NULL) \
1007: systemError("Nullified object"); \
1008: liberation(object); \
1009: object = NULL; \
1010: } while(0)
1011:
1012: /*
1013: --------------------------------------------------------------------------------
1014: Copie d'un objet
1015: --------------------------------------------------------------------------------
1016: */
1017:
1018: #define dupObject(object) \
1019: { if (copie_objet(object, 'P') != object) \
1020: systemError("Memory allocation error"); } while(0)
1021:
1022: /*
1023: --------------------------------------------------------------------------------
1024: Allocation mémoire
1025: --------------------------------------------------------------------------------
1026: */
1027:
1028: #define size(a) sizeof(a)
1029:
1030: #define allocate(a) ({ void *ptr; \
1031: if ((ptr = malloc(a)) == NULL) \
1032: systemError("Memory allocation error"); ptr; })
1033:
1034: #define deallocate(a) free(a)
1035:
1036: /*
1037: --------------------------------------------------------------------------------
1038: Exécution d'une fonction intrinsèque
1039: --------------------------------------------------------------------------------
1040: */
1041:
1042: #define intrinsic(function) { \
1043: int __status; \
1044: __status = wrapper_instruction_intrinseque( \
1045: instruction_##function, rpl_arguments); \
1046: if (__status == 1) executionError(#function); \
1047: if (__status == 2) systemError(#function); \
1048: } while(0)
1049:
1050: #endif
1051:
1052: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>