]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/code.h
89c07fe9d6719bc86bf1c8bc55ae11c08bd2ebb1
[simgear.git] / simgear / nasal / code.h
1 #ifndef _CODE_H
2 #define _CODE_H
3
4 #include <setjmp.h>
5 #include "nasal.h"
6 #include "data.h"
7
8 #define MAX_STACK_DEPTH 1024
9 #define MAX_RECURSION 128
10 #define MAX_MARK_DEPTH 32
11
12 enum {    
13     OP_AND, OP_OR, OP_NOT, OP_MUL, OP_PLUS, OP_MINUS, OP_DIV, OP_NEG,
14     OP_CAT, OP_LT, OP_LTE, OP_GT, OP_GTE, OP_EQ, OP_NEQ, OP_EACH,
15     OP_JMP, OP_JIFNOT, OP_JIFNIL, OP_FCALL, OP_MCALL, OP_RETURN,
16     OP_PUSHCONST, OP_PUSHONE, OP_PUSHZERO, OP_PUSHNIL, OP_POP,
17     OP_DUP, OP_XCHG, OP_INSERT, OP_EXTRACT, OP_MEMBER, OP_SETMEMBER,
18     OP_LOCAL, OP_SETLOCAL, OP_NEWVEC, OP_VAPPEND, OP_NEWHASH, OP_HAPPEND,
19     OP_LINE, OP_MARK, OP_UNMARK, OP_BREAK, OP_NEWARGS
20 };
21
22 struct Frame {
23     naRef func; // naFunc object
24     naRef locals; // local per-call namespace
25     naRef args; // vector of arguments
26     int ip; // instruction pointer into code
27     int bp; // opStack pointer to start of frame
28     int line; // current line number
29 };
30
31 struct Context {
32     // Garbage collecting allocators:
33     struct naPool pools[NUM_NASAL_TYPES];
34
35     // Stack(s)
36     struct Frame fStack[MAX_RECURSION];
37     int fTop;
38     naRef opStack[MAX_STACK_DEPTH];
39     int opTop;
40     int markStack[MAX_MARK_DEPTH];
41     int markTop;
42     int done;
43
44     // Vector of arguments vectors.  A LIFO cache, basically, to avoid
45     // thrashing the GC just for function call arguments.
46     naRef argPool;
47
48     // Constants
49     naRef meRef;
50     naRef argRef;
51     naRef parentsRef;
52
53     // Error handling
54     jmp_buf jumpHandle;
55     char* error;
56
57     // GC-findable reference point for objects that may live on the
58     // processor ("real") stack during execution.  naNew() places them
59     // here, and clears the array each time we return from a C
60     // function.
61     naRef temps;
62
63     naRef save;
64 };
65
66 void printRefDEBUG(naRef r);
67
68 #endif // _CODE_H