Changes to support garbage collection with tags...
[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 void * allocate_new(void *, int type);
20 struct ArrayObject * allocate_newarray(void *, int type, int length);
21 struct ___String___ * NewString(void *, const char *str,int length);
22 #else
23 void * allocate_new(int type);
24 struct ArrayObject * allocate_newarray(int type, int length);
25 struct ___String___ * NewString(const char *str,int length);
26 #endif
27
28 void initializeexithandler();
29 void failedboundschk();
30 void failednullptr();
31 void abort_task();
32 void injectinstructionfailure();
33 void createstartupobject();
34
35 #ifdef PRECISE_GC
36 #define VAR(name) ___params___->name
37 #define CALL00(name) name(struct name ## _params * ___params___)
38 #define CALL01(name, alt) name(struct name ## _params * ___params___)
39 #define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___)
40 #define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest)
41 #define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
42 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
43 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
44 #else
45 #define VAR(name) name
46 #define CALL00(name) name()
47 #define CALL01(name, alt) name(alt)
48 #define CALL02(name, alt1, alt2) name(alt1, alt2)
49 #define CALL11(name,rest, alt) name(alt)
50 #define CALL12(name,rest, alt1, alt2) name(alt1, alt2)
51 #define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3)
52 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(alt1, alt2, alt3, alt4)
53 #endif
54
55 #ifdef TASK
56 #include "SimpleHash.h"
57 #include "task.h"
58 #include "structdefs.h"
59
60 void flagorand(void * ptr, int ormask, int andmask);
61 void flagorandinit(void * ptr, int ormask, int andmask);
62 void executetasks();
63 void processtasks();
64
65 struct tagobjectiterator {
66   int istag; /* 0 if object iterator, 1 if tag iterator */
67   struct RuntimeIterator it; /* Object iterator */
68   struct RuntimeHash * objectset;
69   int slot;
70   int tagobjindex; /* Index for tag or object depending on use */
71   /*if tag we have an object binding */
72   int tagid;
73   int tagobjectslot;
74   /*if object, we may have one or more tag bindings */
75   int numtags;
76   int tagbindings[MAXTASKPARAMS-1]; /* list slots */
77 };
78
79 struct parameterwrapper {
80   struct parameterwrapper *next;
81   struct RuntimeHash * objectset;
82   int numberofterms;
83   int * intarray;
84   int numbertags;
85   int * tagarray;
86   struct taskdescriptor * task;
87   int slot;
88   struct tagobjectiterator iterators[MAXTASKPARAMS-1];
89 };
90
91 struct taskparamdescriptor {
92   struct taskdescriptor * task;
93   int numParameters;
94   void ** parameterArray;
95 };
96
97 int hashCodetpd(struct taskparamdescriptor *);
98 int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *);
99
100 void toiReset(struct tagobjectiterator * it);
101 int toiHasNext(struct tagobjectiterator *it, void ** objectarray);
102 void toiNext(struct tagobjectiterator *it , void ** objectarray);
103 void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams);
104 void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams);
105 void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter);
106 void enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr);
107
108 #endif
109
110 #endif