-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgc.h
200 lines (150 loc) · 4.86 KB
/
gc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
Copyright © 2008, 2009 Sam Chapin
This file is part of Gospel.
Gospel is free software: you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License
as published by the Free Software Foundation.
Gospel is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Gospel. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GC_H
#define GC_H
// A compiler hint.
#define tailcall(t_f) do { (t_f)(); return; } while (0)
#define EDEN_OVERHEAD 5 // For the sake of testing.
#include <gmp.h> // For the definition of "mpz_t".
#include <stdint.h> // For the definition of "intptr_t".
typedef struct vectorStruct {
struct vectorStruct *prev, *next;
int type;
void *data[];
} *vector;
typedef vector obj;
typedef intptr_t atom;
#define CELLS_REQUIRED_FOR_BYTES(n) (((n) + sizeof(atom) - 1) / sizeof(atom))
vector shelteredValue(vector);
vector shelter(vector, vector);
vector currentActor(vector);
vector setCurrentActor(vector, vector);
vector threadContinuation(vector);
vector setContinuation(vector);
vector createGarbageCollectorRoot(obj);
void fulfillPromise(obj, vector);
int isMarked(vector);
void mark(vector);
// The following are only exposed because they're used in unit tests.
void scan(void);
void acquireFutex(volatile int *, volatile int *);
void releaseFutex(volatile int *, volatile int *);
vector insertBetween(vector, vector, vector);
extern vector blackList, grayList, whiteList, ecruList;
extern vector emptyVector;
extern vector garbageCollectorRoot;
extern struct vectorStruct dummyThreadData;
#ifdef NO_THREAD_VARIABLES
vector getCurrentThread(void);
#define currentThread (getCurrentThread())
#else
extern __thread vector currentThread;
#endif
vector setCurrentThread(vector);
void initializeMainThread(void);
void acquireThreadListLock(void);
void releaseThreadListLock(void);
void acquireSymbolTableLock(void);
void releaseSymbolTableLock(void);
void acquireTempLock(void);
void releaseTempLock(void);
int freeSpaceCount(void);
void invalidateEden(void);
vector makeVector(int);
vector makeAtomVector(int);
vector newVector(int, ...);
vector newAtomVector(int, ...);
vector duplicateVector(vector);
vector idx(vector, int);
atom atomIdx(vector, int);
vector *idxPointer(vector, int);
vector *edenIdx(vector, int);
void *setIdx(vector, int, void *);
void *vectorData(vector);
int vectorLength(vector);
vector zero(vector);
void forbidGC(void);
void permitGC(void);
void createPrimitiveThread(void (*)(void *), void *);
// NOTE: The first argument to spawn() must be a function name. A function pointer expression would
// break on systems that don't support computed tailcalls.
#define spawn(spawn_f, spawn_a) do { \
void spawn_init(void *spawn_arg) { setCurrentThread(spawn_arg); tailcall(spawn_f); } \
createPrimitiveThread(spawn_init, (void *)(spawn_a)); \
} while (0)
typedef vector promise;
promise newPromise(void);
obj promiseValue(promise);
vector *promiseValueField(promise);
obj waitFor(void *);
void fulfillPromise(promise, obj);
void trimStack(void);
promise currentPromise(void);
vector newActor(obj, obj, obj);
promise enqueueMessage(vector, obj, vector);
void initializeHeap(void);
void collectGarbage(void);
void requireGC(void);
int isPromise(vector);
int isActor(vector);
int isInteger(obj);
int isPrimitive(obj);
int isMethod(obj);
int isString(obj);
int isSymbol(obj);
int isStackFrame(obj);
int isVectorObject(obj);
int isEnvironment(obj);
int isRegex(obj);
obj vectorObject(vector);
vector vectorObjectVector(obj);
__mpz_struct *bignumData(obj);
obj emptyBignum(void);
vector emptyBignumVector(void);
obj string(const char *);
obj stringFromVector(vector);
char *stringData(obj);
int stringLength(obj);
char stringIdx(obj, int);
void setStringIdx(obj, int, char);
int vectorType(vector);
void setVectorType(vector, int);
vector suffix(void *, vector);
vector prefix(void *, vector);
obj dispatchMethod(obj);
void setDispatchMethod(obj, obj);
obj newSlot(obj, obj, void *, obj);
vector hiddenEntity(obj);
void *hiddenAtom(obj);
void setSlots(obj, vector);
int slotCount(obj);
obj slotName(obj, int);
obj slotNamespace(obj, int);
void **slotValuePointer(obj, int);
vector setHiddenData(obj, vector);
obj proto(obj);
obj setProto(obj, obj);
obj newObject(obj, vector, vector, void *);
obj slotlessObject(obj, vector);
obj typedObject(obj, vector);
obj method(vector, vector, obj);
vector methodParams(obj);
vector methodBody(obj);
obj methodScope(obj);
obj primitive(void *);
int (*primitiveCode(obj))(void);
obj stackFrame(obj, vector, vector, vector);
vector stackFrameContinuation(obj);
void initializePrototypeTags(void);
#endif