00001 #ifndef _CODE_H
00002 #define _CODE_H
00003
00004 #include <setjmp.h>
00005 #include "nasal.h"
00006 #include "data.h"
00007
00008 #define MAX_STACK_DEPTH 512
00009 #define MAX_RECURSION 128
00010 #define MAX_MARK_DEPTH 128
00011
00012
00013
00014
00015
00016
00017
00018
00019 #define OBJ_CACHE_SZ 1
00020
00021 enum {
00022 OP_NOT, OP_MUL, OP_PLUS, OP_MINUS, OP_DIV, OP_NEG, OP_CAT, OP_LT, OP_LTE,
00023 OP_GT, OP_GTE, OP_EQ, OP_NEQ, OP_EACH, OP_JMP, OP_JMPLOOP, OP_JIFNOTPOP,
00024 OP_JIFEND, OP_FCALL, OP_MCALL, OP_RETURN, OP_PUSHCONST, OP_PUSHONE,
00025 OP_PUSHZERO, OP_PUSHNIL, OP_POP, OP_DUP, OP_XCHG, OP_INSERT, OP_EXTRACT,
00026 OP_MEMBER, OP_SETMEMBER, OP_LOCAL, OP_SETLOCAL, OP_NEWVEC, OP_VAPPEND,
00027 OP_NEWHASH, OP_HAPPEND, OP_MARK, OP_UNMARK, OP_BREAK, OP_SETSYM, OP_DUP2,
00028 OP_INDEX, OP_BREAK2, OP_PUSHEND, OP_JIFTRUE, OP_JIFNOT, OP_FCALLH,
00029 OP_MCALLH, OP_XCHG2, OP_UNPACK, OP_SLICE, OP_SLICE2
00030 };
00031
00032 struct Frame {
00033 naRef func;
00034 naRef locals;
00035 int ip;
00036 int bp;
00037 };
00038
00039 struct Globals {
00040
00041 struct naPool pools[NUM_NASAL_TYPES];
00042 int allocCount;
00043
00044
00045 void** deadBlocks;
00046 int deadsz;
00047 int ndead;
00048
00049
00050 int nThreads;
00051 int waitCount;
00052 int needGC;
00053 int bottleneck;
00054 void* sem;
00055 void* lock;
00056
00057
00058 naRef meRef;
00059 naRef argRef;
00060 naRef parentsRef;
00061
00062
00063 naRef symbols;
00064
00065 naRef save;
00066
00067 struct Context* freeContexts;
00068 struct Context* allContexts;
00069 };
00070
00071 struct Context {
00072
00073 struct Frame fStack[MAX_RECURSION];
00074 int fTop;
00075 naRef opStack[MAX_STACK_DEPTH];
00076 int opFrame;
00077 int opTop;
00078 int markStack[MAX_MARK_DEPTH];
00079 int markTop;
00080
00081
00082 struct naObj** free[NUM_NASAL_TYPES];
00083 int nfree[NUM_NASAL_TYPES];
00084
00085
00086
00087
00088 struct naObj** temps;
00089 int ntemps;
00090 int tempsz;
00091
00092
00093 jmp_buf jumpHandle;
00094 char error[128];
00095 naRef dieArg;
00096
00097
00098 struct Context* callParent;
00099 struct Context* callChild;
00100
00101
00102 struct Context* nextFree;
00103 struct Context* nextAll;
00104
00105 void* userData;
00106 };
00107
00108 #define globals nasal_globals
00109 extern struct Globals* globals;
00110
00111
00112 void* naNewLock();
00113 void naFreeLock(void* lock);
00114 void naLock(void* lock);
00115 void naUnlock(void* lock);
00116 void* naNewSem();
00117 void naFreeSem(void* sem);
00118 void naSemDown(void* sem);
00119 void naSemUp(void* sem, int count);
00120
00121 void naCheckBottleneck();
00122
00123 #define LOCK() naLock(globals->lock)
00124 #define UNLOCK() naUnlock(globals->lock)
00125
00126 #endif // _CODE_H