6 enum { T_STR, T_VEC, T_HASH, T_CODE, T_FUNC, T_CCODE, T_GHOST,
7 NUM_NASAL_TYPES }; // V. important that this come last!
9 #define IS_REF(r) ((r).ref.reftag == NASAL_REFTAG)
10 #define IS_NUM(r) ((r).ref.reftag != NASAL_REFTAG)
11 #define IS_OBJ(r) (IS_REF((r)) && (r).ref.ptr.obj != 0)
12 //#define IS_OBJ(r) (IS_REF((r)) && (r).ref.ptr.obj != 0 && (((r).ref.ptr.obj->type == 123) ? *(int*)0 : 1))
13 #define IS_NIL(r) (IS_REF((r)) && (r).ref.ptr.obj == 0)
14 #define IS_STR(r) (IS_OBJ((r)) && (r).ref.ptr.obj->type == T_STR)
15 #define IS_VEC(r) (IS_OBJ((r)) && (r).ref.ptr.obj->type == T_VEC)
16 #define IS_HASH(r) (IS_OBJ((r)) && (r).ref.ptr.obj->type == T_HASH)
17 #define IS_CODE(r) (IS_OBJ((r)) && (r).ref.ptr.obj->type == T_CODE)
18 #define IS_FUNC(r) (IS_OBJ((r)) && (r).ref.ptr.obj->type == T_FUNC)
19 #define IS_CCODE(r) (IS_OBJ((r)) && (r).ref.ptr.obj->type == T_CCODE)
20 #define IS_GHOST(r) (IS_OBJ((r)) && (r).ref.ptr.obj->type == T_GHOST)
21 #define IS_CONTAINER(r) (IS_VEC(r)||IS_HASH(r))
22 #define IS_SCALAR(r) (IS_NUM((r)) || IS_STR((r)))
23 #define IDENTICAL(a, b) (IS_REF(a) && IS_REF(b) \
24 && a.ref.ptr.obj == b.ref.ptr.obj)
26 #define MUTABLE(r) (IS_STR(r) && (r).ref.ptr.str->hashcode == 0)
28 // This is a macro instead of a separate struct to allow compilers to
29 // avoid padding. GCC on x86, at least, will always padd the size of
30 // an embedded struct up to 32 bits. Doing it this way allows the
31 // implementing objects to pack in 16 bits worth of data "for free".
44 unsigned int hashcode;
61 struct HashNode* next;
68 struct HashNode* nodes;
69 struct HashNode* table[];
80 unsigned char nOptArgs;
81 unsigned char needArgVector;
82 unsigned short nConstants;
83 unsigned short nLines;
84 unsigned short codesz;
85 unsigned short* byteCode;
87 int* argSyms; // indices into constants
90 unsigned short* lineIps; // pairs of {ip, line}
92 naRef restArgSym; // The "..." vector name, defaults to "arg"
99 naRef next; // parent closure
116 struct Block* blocks;
117 void** free0; // pointer to the alloced buffer
118 int freesz; // size of the alloced buffer
119 void** free; // current "free frame"
120 int nfree; // down-counting index within the free frame
121 int freetop; // curr. top of the free list
124 void naFree(void* m);
125 void* naAlloc(int n);
126 void* naRealloc(void* buf, int sz);
127 void naBZero(void* m, int n);
129 int naTypeSize(int type);
130 naRef naObj(int type, struct naObj* o);
131 naRef naNew(naContext c, int type);
132 naRef naNewCode(naContext c);
134 int naStr_equal(naRef s1, naRef s2);
135 naRef naStr_fromnum(naRef dest, double num);
136 int naStr_numeric(naRef str);
137 int naStr_parsenum(char* str, int len, double* result);
138 int naStr_tonum(naRef str, double* out);
139 naRef naStr_buf(naRef str, int len);
141 int naHash_tryset(naRef hash, naRef key, naRef val); // sets if exists
142 int naHash_sym(struct naHash* h, struct naStr* sym, naRef* out);
143 void naHash_newsym(struct naHash* h, naRef* sym, naRef* val);
145 void naGC_init(struct naPool* p, int type);
146 struct naObj** naGC_get(struct naPool* p, int n, int* nout);
147 void naGC_swapfree(void** target, void* val);
148 void naGC_freedead();
150 void naStr_gcclean(struct naStr* s);
151 void naVec_gcclean(struct naVec* s);
152 void naHash_gcclean(struct naHash* s);