1 #ifndef js_compile_h 2 #define js_compile_h 3 4 enum js_OpCode 5 { 6 OP_POP, /* A -- */ 7 OP_DUP, /* A -- A A */ 8 OP_DUP2, /* A B -- A B A B */ 9 OP_ROT2, /* A B -- B A */ 10 OP_ROT3, /* A B C -- C A B */ 11 OP_ROT4, /* A B C D -- D A B C */ 12 13 OP_NUMBER_0, /* -- 0 */ 14 OP_NUMBER_1, /* -- 1 */ 15 OP_NUMBER_POS, /* -K- K */ 16 OP_NUMBER_NEG, /* -K- -K */ 17 18 OP_NUMBER, /* -N- <number> */ 19 OP_STRING, /* -S- <string> */ 20 OP_CLOSURE, /* -F- <closure> */ 21 22 OP_NEWARRAY, 23 OP_NEWOBJECT, 24 OP_NEWREGEXP, /* -S,opts- <regexp> */ 25 26 OP_UNDEF, 27 OP_NULL, 28 OP_TRUE, 29 OP_FALSE, 30 31 OP_THIS, 32 OP_CURRENT, /* currently executing function object */ 33 34 OP_INITLOCAL, /* <value> -K- */ 35 OP_GETLOCAL, /* -K- <value> */ 36 OP_SETLOCAL, /* <value> -K- <value> */ 37 OP_DELLOCAL, /* -K- false */ 38 39 OP_INITVAR, /* <value> -S- */ 40 OP_DEFVAR, /* -S- */ 41 OP_HASVAR, /* -S- ( <value> | undefined ) */ 42 OP_GETVAR, /* -S- <value> */ 43 OP_SETVAR, /* <value> -S- <value> */ 44 OP_DELVAR, /* -S- <success> */ 45 46 OP_IN, /* <name> <obj> -- <exists?> */ 47 48 OP_INITPROP, /* <obj> <key> <val> -- <obj> */ 49 OP_INITGETTER, /* <obj> <key> <closure> -- <obj> */ 50 OP_INITSETTER, /* <obj> <key> <closure> -- <obj> */ 51 52 OP_GETPROP, /* <obj> <name> -- <value> */ 53 OP_GETPROP_S, /* <obj> -S- <value> */ 54 OP_SETPROP, /* <obj> <name> <value> -- <value> */ 55 OP_SETPROP_S, /* <obj> <value> -S- <value> */ 56 OP_DELPROP, /* <obj> <name> -- <success> */ 57 OP_DELPROP_S, /* <obj> -S- <success> */ 58 59 OP_ITERATOR, /* <obj> -- <iobj> */ 60 OP_NEXTITER, /* <iobj> -- ( <iobj> <name> true | false ) */ 61 62 OP_EVAL, /* <args...> -(numargs)- <returnvalue> */ 63 OP_CALL, /* <closure> <this> <args...> -(numargs)- <returnvalue> */ 64 OP_NEW, /* <closure> <args...> -(numargs)- <returnvalue> */ 65 66 OP_TYPEOF, 67 OP_POS, 68 OP_NEG, 69 OP_BITNOT, 70 OP_LOGNOT, 71 OP_INC, /* <x> -- ToNumber(x)+1 */ 72 OP_DEC, /* <x> -- ToNumber(x)-1 */ 73 OP_POSTINC, /* <x> -- ToNumber(x)+1 ToNumber(x) */ 74 OP_POSTDEC, /* <x> -- ToNumber(x)-1 ToNumber(x) */ 75 76 OP_MUL, 77 OP_DIV, 78 OP_MOD, 79 OP_ADD, 80 OP_SUB, 81 OP_SHL, 82 OP_SHR, 83 OP_USHR, 84 OP_LT, 85 OP_GT, 86 OP_LE, 87 OP_GE, 88 OP_EQ, 89 OP_NE, 90 OP_STRICTEQ, 91 OP_STRICTNE, 92 OP_JCASE, 93 OP_BITAND, 94 OP_BITXOR, 95 OP_BITOR, 96 97 OP_INSTANCEOF, 98 99 OP_THROW, 100 101 OP_TRY, /* -ADDR- /jump/ or -ADDR- <exception> */ 102 OP_ENDTRY, 103 104 OP_CATCH, /* push scope chain with exception variable */ 105 OP_ENDCATCH, 106 107 OP_WITH, 108 OP_ENDWITH, 109 110 OP_DEBUGGER, 111 OP_JUMP, 112 OP_JTRUE, 113 OP_JFALSE, 114 OP_RETURN, 115 116 OP_LINE, /* -K- */ 117 }; 118 119 struct js_Function 120 { 121 const char *name; 122 int script; 123 int lightweight; 124 int strict; 125 int arguments; 126 int numparams; 127 128 js_Instruction *code; 129 int codecap, codelen; 130 131 js_Function **funtab; 132 int funcap, funlen; 133 134 double *numtab; 135 int numcap, numlen; 136 137 const char **strtab; 138 int strcap, strlen; 139 140 const char **vartab; 141 int varcap, varlen; 142 143 const char *filename; 144 int line, lastline; 145 146 js_Function *gcnext; 147 int gcmark; 148 }; 149 150 js_Function *jsC_compilefunction(js_State *J, js_Ast *prog); 151 js_Function *jsC_compile(js_State *J, js_Ast *prog); 152 const char *jsC_opcodestring(enum js_OpCode opcode); 153 void jsC_dumpfunction(js_State *J, js_Function *fun); 154 155 #endif 156