my changes
[IRC.git] / Robust / src / Runtime / runtime.h
1 #ifndef RUNTIME
2 #define RUNTIME
3 #include <setjmp.h>
4 extern jmp_buf error_handler;
5 extern int instructioncount;
6 extern int failurecount;
7
8 #define TAGARRAYINTERVAL 10
9 #define OBJECTARRAYINTERVAL 10
10
11 #define ARRAYSET(array, type, index, value) \
12 ((type *)(&(& array->___length___)[1]))[index]=value
13
14 #define ARRAYGET(array, type, index) \
15 ((type *)(&(& array->___length___)[1]))[index]
16
17 #ifdef PRECISE_GC
18 #include "garbage.h"
19 #ifdef DSTM
20 void * allocate_newglobal(void *, int type);
21 struct ArrayObject * allocate_newarrayglobal(void *, int type, int length);
22 #endif
23 void * allocate_new(void *, int type);
24 struct ArrayObject * allocate_newarray(void *, int type, int length);
25 struct ___String___ * NewString(void *, const char *str,int length);
26 struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
27 #else
28 #ifdef DSTM
29 void * allocate_newglobal(int type);
30 struct ArrayObject * allocate_newarrayglobal(int type, int length);
31 #endif
32 void * allocate_new(int type);
33 struct ArrayObject * allocate_newarray(int type, int length);
34 struct ___String___ * NewString(const char *str,int length);
35 struct ___TagDescriptor___ * allocate_tag(int index);
36 #endif
37
38
39
40 void initializeexithandler();
41 void failedboundschk();
42 void failednullptr();
43 void abort_task();
44 void injectinstructionfailure();
45 void createstartupobject();
46
47 #ifdef PRECISE_GC
48 #define VAR(name) ___params___->name
49 #define CALL00(name) name(struct name ## _params * ___params___)
50 #define CALL01(name, alt) name(struct name ## _params * ___params___)
51 #define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___)
52 #define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest)
53 #define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
54 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
55 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
56 #else
57 #define VAR(name) name
58 #define CALL00(name) name()
59 #define CALL01(name, alt) name(alt)
60 #define CALL02(name, alt1, alt2) name(alt1, alt2)
61 #define CALL11(name,rest, alt) name(alt)
62 #define CALL12(name,rest, alt1, alt2) name(alt1, alt2)
63 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3)
64 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
65 #endif
66
67 #ifdef TASK
68 #include "SimpleHash.h"
69 #include "task.h"
70 #include "structdefs.h"
71 #include "optionalstruct.h"
72
73 void flagorand(void * ptr, int ormask, int andmask);
74 void flagorandinit(void * ptr, int ormask, int andmask);
75 void executetasks();
76 void processtasks();
77
78 struct tagobjectiterator {
79   int istag; /* 0 if object iterator, 1 if tag iterator */
80   struct RuntimeIterator it; /* Object iterator */
81   struct RuntimeHash * objectset;
82   int slot;
83   int tagobjindex; /* Index for tag or object depending on use */
84   /*if tag we have an object binding */
85   int tagid;
86   int tagobjectslot;
87   /*if object, we may have one or more tag bindings */
88   int numtags;
89   int tagbindings[MAXTASKPARAMS-1]; /* list slots */
90 };
91
92 struct parameterwrapper {
93   struct parameterwrapper *next;
94   struct RuntimeHash * objectset;
95   int numberofterms;
96   int * intarray;
97   int numbertags;
98   int * tagarray;
99   struct taskdescriptor * task;
100   int slot;
101   struct tagobjectiterator iterators[MAXTASKPARAMS-1];
102 };
103
104 struct taskparamdescriptor {
105   struct taskdescriptor * task;
106   int numParameters;
107   void ** parameterArray;
108 };
109
110 int hashCodetpd(struct taskparamdescriptor *);
111 int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *);
112
113 void toiReset(struct tagobjectiterator * it);
114 int toiHasNext(struct tagobjectiterator *it, void ** objectarray);
115 void toiNext(struct tagobjectiterator *it , void ** objectarray);
116 void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams);
117 void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams);
118 void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter);
119 void enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr);
120
121 #endif
122
123 #endif