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 // Testing with fib.nas shows that this gives the best performance,
14 // without too much per-thread overhead.
15 #define OBJ_CACHE_SZ 128
18 OP_AND, OP_OR, OP_NOT, OP_MUL, OP_PLUS, OP_MINUS, OP_DIV, OP_NEG,
19 OP_CAT, OP_LT, OP_LTE, OP_GT, OP_GTE, OP_EQ, OP_NEQ, OP_EACH,
20 OP_JMP, OP_JMPLOOP, OP_JIFNOT, OP_JIFNIL, OP_FCALL, OP_MCALL, OP_RETURN,
21 OP_PUSHCONST, OP_PUSHONE, OP_PUSHZERO, OP_PUSHNIL, OP_POP,
22 OP_DUP, OP_XCHG, OP_INSERT, OP_EXTRACT, OP_MEMBER, OP_SETMEMBER,
23 OP_LOCAL, OP_SETLOCAL, OP_NEWVEC, OP_VAPPEND, OP_NEWHASH, OP_HAPPEND,
24 OP_MARK, OP_UNMARK, OP_BREAK, OP_FTAIL, OP_MTAIL, OP_SETSYM, OP_DUP2,
29 naRef func; // naFunc object
30 naRef locals; // local per-call namespace
31 int ip; // instruction pointer into code
32 int bp; // opStack pointer to start of frame
36 // Garbage collecting allocators:
37 struct naPool pools[NUM_NASAL_TYPES];
40 // Dead blocks waiting to be freed when it is safe
58 // A hash of symbol names
63 struct Context* freeContexts;
64 struct Context* allContexts;
69 struct Frame fStack[MAX_RECURSION];
71 naRef opStack[MAX_STACK_DEPTH];
73 int markStack[MAX_MARK_DEPTH];
76 // Free object lists, cached from the global GC
77 struct naObj** free[NUM_NASAL_TYPES];
78 int nfree[NUM_NASAL_TYPES];
80 // GC-findable reference point for objects that may live on the
81 // processor ("real") stack during execution. naNew() places them
82 // here, and clears the array each instruction
91 struct Context* callParent;
92 struct Context* callChild;
94 // Linked list pointers in globals
95 struct Context* nextFree;
96 struct Context* nextAll;
99 #define globals nasal_globals
100 extern struct Globals* globals;
102 // Threading low-level functions
104 void naLock(void* lock);
105 void naUnlock(void* lock);
107 void naSemDown(void* sem);
108 void naSemUpAll(void* sem, int count);
110 void naCheckBottleneck();
112 #define LOCK() naLock(globals->lock)
113 #define UNLOCK() naUnlock(globals->lock)