]> git.mxchange.org Git - simgear.git/blob - simgear/nasal/code.h
Clamp pitch values rather than just dumping an error message.
[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
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     // Constants
45     naRef meRef;
46     naRef argRef;
47     naRef parentsRef;
48
49     // Error handling
50     jmp_buf jumpHandle;
51     char* error;
52
53     // GC-findable reference point for objects that may live on the
54     // processor ("real") stack during execution.  naNew() places them
55     // here, and clears the array each time we return from a C
56     // function.
57     naRef temps;
58
59     naRef save;
60 };
61
62 void printRefDEBUG(naRef r);
63
64 #endif // _CODE_H