96cc3087d7174fb8da2b50fd3f94fa2c3ea29b5b
[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 DSTM
21 void * allocate_newglobal(transrecord_t *, int type);
22 struct ArrayObject * allocate_newarrayglobal(transrecord_t *, int type, int length);
23 #endif
24
25 #ifdef PRECISE_GC
26 #include "garbage.h"
27 void * allocate_new(void *, int type);
28 struct ArrayObject * allocate_newarray(void *, int type, int length);
29 struct ___String___ * NewString(void *, const char *str,int length);
30 struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
31 #else
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 "ObjectHash.h"
70 #include "task.h"
71 #include "structdefs.h"
72 #ifdef OPTIONAL
73 #include "optionalstruct.h"
74 #endif
75
76 void flagorand(void * ptr, int ormask, int andmask);
77 void flagorandinit(void * ptr, int ormask, int andmask);
78 void executetasks();
79 void processtasks();
80
81 struct tagobjectiterator {
82   int istag; /* 0 if object iterator, 1 if tag iterator */
83   struct ObjectIterator it; /* Object iterator */
84   struct ObjectHash * objectset;
85   int slot;
86   int tagobjindex; /* Index for tag or object depending on use */
87   /*if tag we have an object binding */
88   int tagid;
89   int tagobjectslot;
90   /*if object, we may have one or more tag bindings */
91   int numtags;
92   int tagbindings[MAXTASKPARAMS-1]; /* list slots */
93 };
94
95 struct parameterwrapper {
96   struct parameterwrapper *next;
97   struct ObjectHash * objectset;
98   int numberofterms;
99   int * intarray;
100   int numbertags;
101   int * tagarray;
102   struct taskdescriptor * task;
103   int slot;
104   struct tagobjectiterator iterators[MAXTASKPARAMS-1];
105 };
106
107 struct taskparamdescriptor {
108   struct taskdescriptor * task;
109   int numParameters;
110   void ** parameterArray;
111 };
112
113 int hashCodetpd(struct taskparamdescriptor *);
114 int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *);
115
116 void toiReset(struct tagobjectiterator * it);
117 int toiHasNext(struct tagobjectiterator *it, void ** objectarray);
118 void toiNext(struct tagobjectiterator *it , void ** objectarray);
119 void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams);
120 void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams);
121 void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter);
122 void enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr);
123
124 #endif
125
126 #endif