more 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 #ifdef DSTM
8 #include "dstm.h"
9 #endif
10
11 #define TAGARRAYINTERVAL 10
12 #define OBJECTARRAYINTERVAL 10
13
14 #define ARRAYSET(array, type, index, value) \
15 ((type *)(&(& array->___length___)[1]))[index]=value
16
17 #define ARRAYGET(array, type, index) \
18 ((type *)(&(& array->___length___)[1]))[index]
19
20 #ifdef OPTIONAL
21 #define OPTARG(x) , x
22 #else
23 #define OPTARG(x)
24 #endif
25
26 #ifdef DSTM
27 void * allocate_newglobal(transrecord_t *, int type);
28 struct ArrayObject * allocate_newarrayglobal(transrecord_t *, int type, int length);
29 #endif
30
31 #ifdef PRECISE_GC
32 #include "garbage.h"
33 void * allocate_new(void *, int type);
34 struct ArrayObject * allocate_newarray(void *, int type, int length);
35 struct ___String___ * NewString(void *, const char *str,int length);
36 struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
37 #else
38 void * allocate_new(int type);
39 struct ArrayObject * allocate_newarray(int type, int length);
40 struct ___String___ * NewString(const char *str,int length);
41 struct ___TagDescriptor___ * allocate_tag(int index);
42 #endif
43
44
45
46 void initializeexithandler();
47 void failedboundschk();
48 void failednullptr();
49 void abort_task();
50 void injectinstructionfailure();
51 void createstartupobject();
52
53 #ifdef PRECISE_GC
54 #define VAR(name) ___params___->name
55 #define CALL00(name) name(struct name ## _params * ___params___)
56 #define CALL01(name, alt) name(struct name ## _params * ___params___)
57 #define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___)
58 #define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest)
59 #define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
60 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
61 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
62 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
63 #else
64 #define VAR(name) name
65 #define CALL00(name) name()
66 #define CALL01(name, alt) name(alt)
67 #define CALL02(name, alt1, alt2) name(alt1, alt2)
68 #define CALL11(name,rest, alt) name(alt)
69 #define CALL12(name,rest, alt1, alt2) name(alt1, alt2)
70 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3)
71 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
72 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
73 #endif
74
75 #ifdef TASK
76 #include "SimpleHash.h"
77 #include "ObjectHash.h"
78 #include "task.h"
79 #include "structdefs.h"
80 #ifdef OPTIONAL
81 #include "optionalstruct.h"
82 #endif
83
84 #ifdef OPTIONAL
85 struct failedtasklist {
86   struct taskdescriptor *task;
87   int index;
88   int numflags;
89   int *flags;
90   struct failedtasklist *next;
91 };
92 #endif
93
94 void flagorand(void * ptr, int ormask, int andmask);
95 void flagorandinit(void * ptr, int ormask, int andmask);
96 void executetasks();
97 void processtasks();
98
99 struct tagobjectiterator {
100   int istag; /* 0 if object iterator, 1 if tag iterator */
101   struct ObjectIterator it; /* Object iterator */
102   struct ObjectHash * objectset;
103 #ifdef OPTIONAL
104   int failedstate;
105 #endif
106   int slot;
107   int tagobjindex; /* Index for tag or object depending on use */
108   /*if tag we have an object binding */
109   int tagid;
110   int tagobjectslot;
111   /*if object, we may have one or more tag bindings */
112   int numtags;
113   int tagbindings[MAXTASKPARAMS-1]; /* list slots */
114 };
115
116 struct parameterwrapper {
117   struct parameterwrapper *next;
118   struct ObjectHash * objectset;
119   int numberofterms;
120   int * intarray;
121   int numbertags;
122   int * tagarray;
123   struct taskdescriptor * task;
124   int slot;
125   struct tagobjectiterator iterators[MAXTASKPARAMS-1];
126 };
127
128 struct taskparamdescriptor {
129   struct taskdescriptor * task;
130   int numParameters;
131   void ** parameterArray;
132 #ifdef OPTIONAL
133   int * failed;
134 #endif
135 };
136
137 int hashCodetpd(struct taskparamdescriptor *);
138 int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *);
139
140 void toiReset(struct tagobjectiterator * it);
141 int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed));
142 void toiNext(struct tagobjectiterator *it , void ** objectarray OPTARG(int * failed));
143 void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams);
144 void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams);
145 void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter);
146 int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags);
147
148 #endif
149
150 #endif