@@ -15,7 +15,8 @@
15// Closures
15// Closures
17typedef enum {
17typedef enum {
18+ CON, INT, BIGINT, FLOAT, STRING, STROFFSET,
18− CON, INT, BIGINT, FLOAT, STRING, BITS8, BITS16, BITS32, BITS64, UNIT, PTR, FWD
19+ BITS8, BITS16, BITS32, BITS64, UNIT, PTR, FWD
19} ClosureType;
20} ClosureType;
21typedef struct Closure *VAL;
22typedef struct Closure *VAL;
@@ -25,6 +26,11 @@ typedef struct {
25 VAL args[];
26 VAL args[];
28typedef struct Closure {
34typedef struct Closure {
29// Use top 16 bits of ty for saying which heap value is in
35// Use top 16 bits of ty for saying which heap value is in
30// Bottom 16 bits for closure type
36// Bottom 16 bits for closure type
@@ -34,6 +40,7 @@ typedef struct Closure {
36 char* str;
42 char* str;
43+ StrOffset* str_offset;
37 void* ptr;
44 void* ptr;
38 uint8_t bits8;
45 uint8_t bits8;
39 uint16_t bits16;
46 uint16_t bits16;
@@ -92,7 +99,7 @@ typedef void(*func)(VM*, VAL*);
93// Retrieving values
100// Retrieving values
95−#define GETSTR(x) (((VAL)(x))->info.str)
102+#define GETSTR(x) (ISSTR(x) ? (((VAL)(x))->info.str) : GETSTROFF(x))
96#define GETPTR(x) (((VAL)(x))->info.ptr)
103#define GETPTR(x) (((VAL)(x))->info.ptr)
97#define GETFLOAT(x) (((VAL)(x))->info.f)
104#define GETFLOAT(x) (((VAL)(x))->info.f)
@@ -119,6 +126,7 @@ typedef intptr_t i_int;
119#define MKINT(x) ((void*)((x)<<1)+1)
126#define MKINT(x) ((void*)((x)<<1)+1)
120#define GETINT(x) ((i_int)(x)>>1)
127#define GETINT(x) ((i_int)(x)>>1)
121#define ISINT(x) ((((i_int)x)&1) == 1)
128#define ISINT(x) ((((i_int)x)&1) == 1)
129+#define ISSTR(x) (((VAL)(x))->ty == STRING)
123#define INTOP(op,x,y) MKINT((i_int)((((i_int)x)>>1) op (((i_int)y)>>1)))
131#define INTOP(op,x,y) MKINT((i_int)((((i_int)x)>>1) op (((i_int)y)>>1)))
124#define UINTOP(op,x,y) MKINT((i_int)((((uintptr_t)x)>>1) op (((uintptr_t)y)>>1)))
132#define UINTOP(op,x,y) MKINT((i_int)((((uintptr_t)x)>>1) op (((uintptr_t)y)>>1)))
@@ -151,9 +159,12 @@ VAL MKB64(VM* vm, uint64_t b);
152// following versions don't take a lock when allocating
160// following versions don't take a lock when allocating
153VAL MKFLOATc(VM* vm, double val);
161VAL MKFLOATc(VM* vm, double val);
162+VAL MKSTROFFc(VM* vm, StrOffset* off);
154VAL MKSTRc(VM* vm, char* str);
163VAL MKSTRc(VM* vm, char* str);
155VAL MKPTRc(VM* vm, void* ptr);
164VAL MKPTRc(VM* vm, void* ptr);
166+char* GETSTROFF(VAL stroff);
157// #define SETTAG(x, a) (x)->info.c.tag = (a)
168// #define SETTAG(x, a) (x)->info.c.tag = (a)
158#define SETARG(x, i, a) ((x)->info.c.args)[i] = ((VAL)(a))
169#define SETARG(x, i, a) ((x)->info.c.args)[i] = ((VAL)(a))
159#define GETARG(x, i) ((x)->info.c.args)[i]
170#define GETARG(x, i) ((x)->info.c.args)[i]