8 #define MAX_STACK_DEPTH 512
9 #define MAX_RECURSION 128
10 #define MAX_MARK_DEPTH 128
12 // Number of objects (per pool per thread) asked for using naGC_get().
13 // The idea is that contexts can "cache" allocations to prevent thread
14 // contention on the global pools. But in practice this interacts
15 // very badly with small subcontext calls, which grab huge numbers of
16 // cached objects and don't use them, causing far more collections
17 // than necessary. Just leave it at 1 pending a rework of the
18 // collector synchronization.
19 #define OBJ_CACHE_SZ 1
22 OP_NOT, OP_MUL, OP_PLUS, OP_MINUS, OP_DIV, OP_NEG, OP_CAT, OP_LT, OP_LTE,
23 OP_GT, OP_GTE, OP_EQ, OP_NEQ, OP_EACH, OP_JMP, OP_JMPLOOP, OP_JIFNOTPOP,
24 OP_JIFEND, OP_FCALL, OP_MCALL, OP_RETURN, OP_PUSHCONST, OP_PUSHONE,
25 OP_PUSHZERO, OP_PUSHNIL, OP_POP, OP_DUP, OP_XCHG, OP_INSERT, OP_EXTRACT,
26 OP_MEMBER, OP_SETMEMBER, OP_LOCAL, OP_SETLOCAL, OP_NEWVEC, OP_VAPPEND,
27 OP_NEWHASH, OP_HAPPEND, OP_MARK, OP_UNMARK, OP_BREAK, OP_SETSYM, OP_DUP2,
28 OP_INDEX, OP_BREAK2, OP_PUSHEND, OP_JIFTRUE, OP_JIFNOT, OP_FCALLH,
29 OP_MCALLH, OP_XCHG2, OP_UNPACK, OP_SLICE, OP_SLICE2
33 naRef func; // naFunc object
34 naRef locals; // local per-call namespace
35 int ip; // instruction pointer into code
36 int bp; // opStack pointer to start of frame
40 // Garbage collecting allocators:
41 struct naPool pools[NUM_NASAL_TYPES];
44 // Dead blocks waiting to be freed when it is safe
62 // A hash of symbol names
67 struct Context* freeContexts;
68 struct Context* allContexts;
73 struct Frame fStack[MAX_RECURSION];
75 naRef opStack[MAX_STACK_DEPTH];
76 int opFrame; // like Frame::bp, but for C functions
78 int markStack[MAX_MARK_DEPTH];
81 // Free object lists, cached from the global GC
82 struct naObj** free[NUM_NASAL_TYPES];
83 int nfree[NUM_NASAL_TYPES];
85 // GC-findable reference point for objects that may live on the
86 // processor ("real") stack during execution. naNew() places them
87 // here, and clears the array each instruction
98 struct Context* callParent;
99 struct Context* callChild;
101 // Linked list pointers in globals
102 struct Context* nextFree;
103 struct Context* nextAll;
108 #define globals nasal_globals
109 extern struct Globals* globals;
111 // Threading low-level functions
113 void naFreeLock(void* lock);
114 void naLock(void* lock);
115 void naUnlock(void* lock);
117 void naFreeSem(void* sem);
118 void naSemDown(void* sem);
119 void naSemUp(void* sem, int count);
121 void naCheckBottleneck();
123 #define LOCK() naLock(globals->lock)
124 #define UNLOCK() naUnlock(globals->lock)