diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-10-13 20:12:04 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-10-13 20:12:04 -0200 |
| commit | 7c261a13b572fb0f7449f6cdf2b495d0e5bd57d5 (patch) | |
| tree | 026cbe3e25e1929f171d0f30ac7a588bfb29f573 | |
| parent | 2bb94d9e22f1f8ab2c00c9296a3920bebe4862bd (diff) | |
| download | lua-7c261a13b572fb0f7449f6cdf2b495d0e5bd57d5.tar.gz lua-7c261a13b572fb0f7449f6cdf2b495d0e5bd57d5.tar.bz2 lua-7c261a13b572fb0f7449f6cdf2b495d0e5bd57d5.zip | |
more uniform treatment to opcode variants.
| -rw-r--r-- | lopcodes.h | 117 | ||||
| -rw-r--r-- | lua.stx | 208 | ||||
| -rw-r--r-- | lvm.c | 145 |
3 files changed, 241 insertions, 229 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.h,v 1.6 1997/10/01 20:05:34 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.7 1997/10/06 14:51:11 roberto Exp roberto $ |
| 3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -9,9 +9,9 @@ | |||
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | /* | 11 | /* |
| 12 | ** NOTICE: variants of the same opcode (like PUSH0, PUSHBYTE, PUSHWORD) must | 12 | ** NOTICE: variants of the same opcode must be consecutive: First, those |
| 13 | ** be consecutive: First, those with built-in parameters, then with byte | 13 | ** with byte parameter, then with built-in parameters, and last with |
| 14 | ** parameter and last with word parameter. | 14 | ** word parameter. |
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | 17 | ||
| @@ -20,15 +20,16 @@ typedef enum { | |||
| 20 | -----------------------------------------------------------------------------*/ | 20 | -----------------------------------------------------------------------------*/ |
| 21 | ENDCODE,/* - - - */ | 21 | ENDCODE,/* - - - */ |
| 22 | 22 | ||
| 23 | PUSHNIL,/* - - nil */ | 23 | PUSHNIL,/* b - nil_0...nil_b */ |
| 24 | PUSHNILS,/* b - nil_1...nil_b */ | 24 | PUSHNIL0,/* - - nil */ |
| 25 | 25 | ||
| 26 | PUSH0,/* - - 0.0 */ | 26 | PUSHNUMBER,/* b - (float)b */ |
| 27 | PUSH1,/* - - 1.0 */ | 27 | PUSHNUMBER0,/* - - 0.0 */ |
| 28 | PUSH2,/* - - 2.0 */ | 28 | PUSHNUMBER1,/* - - 1.0 */ |
| 29 | PUSHBYTE,/* b - (float)b */ | 29 | PUSHNUMBER2,/* - - 2.0 */ |
| 30 | PUSHWORD,/* w - (float)w */ | 30 | PUSHNUMBERW,/* w - (float)w */ |
| 31 | 31 | ||
| 32 | PUSHCONSTANT,/* b - CNST[b] */ | ||
| 32 | PUSHCONSTANT0,/*- - CNST[0] */ | 33 | PUSHCONSTANT0,/*- - CNST[0] */ |
| 33 | PUSHCONSTANT1,/*- - CNST[1] */ | 34 | PUSHCONSTANT1,/*- - CNST[1] */ |
| 34 | PUSHCONSTANT2,/*- - CNST[2] */ | 35 | PUSHCONSTANT2,/*- - CNST[2] */ |
| @@ -37,15 +38,13 @@ PUSHCONSTANT4,/*- - CNST[4] */ | |||
| 37 | PUSHCONSTANT5,/*- - CNST[5] */ | 38 | PUSHCONSTANT5,/*- - CNST[5] */ |
| 38 | PUSHCONSTANT6,/*- - CNST[6] */ | 39 | PUSHCONSTANT6,/*- - CNST[6] */ |
| 39 | PUSHCONSTANT7,/*- - CNST[7] */ | 40 | PUSHCONSTANT7,/*- - CNST[7] */ |
| 40 | PUSHCONSTANT8,/*- - CNST[8] */ | 41 | PUSHCONSTANTW,/*w - CNST[w] */ |
| 41 | PUSHCONSTANT9,/*- - CNST[9] */ | ||
| 42 | PUSHCONSTANTB,/*b - CNST[b] */ | ||
| 43 | PUSHCONSTANT,/* w - CNST[w] */ | ||
| 44 | 42 | ||
| 43 | PUSHUPVALUE,/* b - Closure[b] */ | ||
| 45 | PUSHUPVALUE0,/* - - Closure[0] */ | 44 | PUSHUPVALUE0,/* - - Closure[0] */ |
| 46 | PUSHUPVALUE1,/* - - Closure[1] */ | 45 | PUSHUPVALUE1,/* - - Closure[1] */ |
| 47 | PUSHUPVALUE,/* b - Closure[b] */ | ||
| 48 | 46 | ||
| 47 | PUSHLOCAL,/* b - LOC[b] */ | ||
| 49 | PUSHLOCAL0,/* - - LOC[0] */ | 48 | PUSHLOCAL0,/* - - LOC[0] */ |
| 50 | PUSHLOCAL1,/* - - LOC[1] */ | 49 | PUSHLOCAL1,/* - - LOC[1] */ |
| 51 | PUSHLOCAL2,/* - - LOC[2] */ | 50 | PUSHLOCAL2,/* - - LOC[2] */ |
| @@ -54,10 +53,8 @@ PUSHLOCAL4,/* - - LOC[4] */ | |||
| 54 | PUSHLOCAL5,/* - - LOC[5] */ | 53 | PUSHLOCAL5,/* - - LOC[5] */ |
| 55 | PUSHLOCAL6,/* - - LOC[6] */ | 54 | PUSHLOCAL6,/* - - LOC[6] */ |
| 56 | PUSHLOCAL7,/* - - LOC[7] */ | 55 | PUSHLOCAL7,/* - - LOC[7] */ |
| 57 | PUSHLOCAL8,/* - - LOC[8] */ | ||
| 58 | PUSHLOCAL9,/* - - LOC[9] */ | ||
| 59 | PUSHLOCAL,/* b - LOC[b] */ | ||
| 60 | 56 | ||
| 57 | GETGLOBAL,/* b - VAR[CNST[b]] */ | ||
| 61 | GETGLOBAL0,/* - - VAR[CNST[0]] */ | 58 | GETGLOBAL0,/* - - VAR[CNST[0]] */ |
| 62 | GETGLOBAL1,/* - - VAR[CNST[1]] */ | 59 | GETGLOBAL1,/* - - VAR[CNST[1]] */ |
| 63 | GETGLOBAL2,/* - - VAR[CNST[2]] */ | 60 | GETGLOBAL2,/* - - VAR[CNST[2]] */ |
| @@ -66,19 +63,19 @@ GETGLOBAL4,/* - - VAR[CNST[4]] */ | |||
| 66 | GETGLOBAL5,/* - - VAR[CNST[5]] */ | 63 | GETGLOBAL5,/* - - VAR[CNST[5]] */ |
| 67 | GETGLOBAL6,/* - - VAR[CNST[6]] */ | 64 | GETGLOBAL6,/* - - VAR[CNST[6]] */ |
| 68 | GETGLOBAL7,/* - - VAR[CNST[7]] */ | 65 | GETGLOBAL7,/* - - VAR[CNST[7]] */ |
| 69 | GETGLOBAL8,/* - - VAR[CNST[8]] */ | 66 | GETGLOBALW,/* w - VAR[CNST[w]] */ |
| 70 | GETGLOBAL9,/* - - VAR[CNST[9]] */ | ||
| 71 | GETGLOBALB,/* b - VAR[CNST[b]] */ | ||
| 72 | GETGLOBAL,/* w - VAR[CNST[w]] */ | ||
| 73 | 67 | ||
| 74 | GETTABLE,/* - i t t[i] */ | 68 | GETTABLE,/* - i t t[i] */ |
| 75 | 69 | ||
| 76 | PUSHSELFB,/* b t t t[CNST[b]] */ | 70 | PUSHSELF,/* b t t t[CNST[b]] */ |
| 77 | PUSHSELF,/* w t t t[CNST[w]] */ | 71 | PUSHSELFW,/* w t t t[CNST[w]] */ |
| 78 | 72 | ||
| 79 | CREATEARRAYB,/* b - newarray(size = b) */ | 73 | CREATEARRAY,/* b - newarray(size = b) */ |
| 80 | CREATEARRAY,/* w - newarray(size = w) */ | 74 | CREATEARRAY0,/* - - newarray(size = 0) */ |
| 75 | CREATEARRAY1,/* - - newarray(size = 1) */ | ||
| 76 | CREATEARRAYW,/* w - newarray(size = w) */ | ||
| 81 | 77 | ||
| 78 | SETLOCAL,/* b x - LOC[b]=x */ | ||
| 82 | SETLOCAL0,/* - x - LOC[0]=x */ | 79 | SETLOCAL0,/* - x - LOC[0]=x */ |
| 83 | SETLOCAL1,/* - x - LOC[1]=x */ | 80 | SETLOCAL1,/* - x - LOC[1]=x */ |
| 84 | SETLOCAL2,/* - x - LOC[2]=x */ | 81 | SETLOCAL2,/* - x - LOC[2]=x */ |
| @@ -87,19 +84,28 @@ SETLOCAL4,/* - x - LOC[4]=x */ | |||
| 87 | SETLOCAL5,/* - x - LOC[5]=x */ | 84 | SETLOCAL5,/* - x - LOC[5]=x */ |
| 88 | SETLOCAL6,/* - x - LOC[6]=x */ | 85 | SETLOCAL6,/* - x - LOC[6]=x */ |
| 89 | SETLOCAL7,/* - x - LOC[7]=x */ | 86 | SETLOCAL7,/* - x - LOC[7]=x */ |
| 90 | SETLOCAL8,/* - x - LOC[8]=x */ | ||
| 91 | SETLOCAL9,/* - x - LOC[9]=x */ | ||
| 92 | SETLOCAL,/* b x - LOC[b]=x */ | ||
| 93 | 87 | ||
| 94 | SETGLOBALB,/* b x - VAR[CNST[b]]=x */ | 88 | SETGLOBAL,/* b x - VAR[CNST[b]]=x */ |
| 95 | SETGLOBAL,/* w x - VAR[CNST[w]]=x */ | 89 | SETGLOBAL0,/* - x - VAR[CNST[0]]=x */ |
| 90 | SETGLOBAL1,/* - x - VAR[CNST[1]]=x */ | ||
| 91 | SETGLOBAL2,/* - x - VAR[CNST[2]]=x */ | ||
| 92 | SETGLOBAL3,/* - x - VAR[CNST[3]]=x */ | ||
| 93 | SETGLOBAL4,/* - x - VAR[CNST[4]]=x */ | ||
| 94 | SETGLOBAL5,/* - x - VAR[CNST[5]]=x */ | ||
| 95 | SETGLOBAL6,/* - x - VAR[CNST[6]]=x */ | ||
| 96 | SETGLOBAL7,/* - x - VAR[CNST[7]]=x */ | ||
| 97 | SETGLOBALW,/* w x - VAR[CNST[w]]=x */ | ||
| 96 | 98 | ||
| 97 | SETTABLE0,/* - v i t - t[i]=v */ | 99 | SETTABLE0,/* - v i t - t[i]=v */ |
| 100 | |||
| 98 | SETTABLE,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */ | 101 | SETTABLE,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */ |
| 99 | 102 | ||
| 100 | SETLIST0,/* b v_b...v_1 t - t[i]=v_i */ | ||
| 101 | SETLIST,/* b c v_b...v_1 t - t[i+c*FPF]=v_i */ | 103 | SETLIST,/* b c v_b...v_1 t - t[i+c*FPF]=v_i */ |
| 102 | SETMAP,/* b v_b k_b ...v_1 k_1 t t t[k_i]=v_i */ | 104 | SETLIST0,/* b v_b...v_1 t - t[i]=v_i */ |
| 105 | SETLISTW,/* w c v_b...v_1 t - t[i+c*FPF]=v_i */ | ||
| 106 | |||
| 107 | SETMAP,/* b v_b k_b ...v_0 k_0 t t t[k_i]=v_i */ | ||
| 108 | SETMAP0,/* - v_0 k_0 t t t[k_0]=v_0 */ | ||
| 103 | 109 | ||
| 104 | EQOP,/* - y x (x==y)? 1 : nil */ | 110 | EQOP,/* - y x (x==y)? 1 : nil */ |
| 105 | NEQOP,/* - y x (x~=y)? 1 : nil */ | 111 | NEQOP,/* - y x (x~=y)? 1 : nil */ |
| @@ -117,25 +123,34 @@ MINUSOP,/* - x -x */ | |||
| 117 | NOTOP,/* - x (x==nil)? 1 : nil */ | 123 | NOTOP,/* - x (x==nil)? 1 : nil */ |
| 118 | 124 | ||
| 119 | ONTJMP,/* b x (x!=nil)? x : - (x!=nil)? PC+=b */ | 125 | ONTJMP,/* b x (x!=nil)? x : - (x!=nil)? PC+=b */ |
| 126 | ONTJMPW,/* w x (x!=nil)? x : - (x!=nil)? PC+=w */ | ||
| 120 | ONFJMP,/* b x (x==nil)? x : - (x==nil)? PC+=b */ | 127 | ONFJMP,/* b x (x==nil)? x : - (x==nil)? PC+=b */ |
| 121 | JMPB,/* b - - PC+=b */ | 128 | ONFJMPW,/* w x (x==nil)? x : - (x==nil)? PC+=w */ |
| 122 | JMP,/* w - - PC+=w */ | 129 | JMP,/* b - - PC+=b */ |
| 123 | IFFJMPB,/* b x - (x==nil)? PC+=b */ | 130 | JMPW,/* w - - PC+=w */ |
| 124 | IFFJMP,/* w x - (x==nil)? PC+=w */ | 131 | IFFJMP,/* b x - (x==nil)? PC+=b */ |
| 125 | IFTUPJMPB,/* b x - (x!=nil)? PC-=b */ | 132 | IFFJMPW,/* w x - (x==nil)? PC+=w */ |
| 126 | IFTUPJMP,/* w x - (x!=nil)? PC-=w */ | 133 | IFTUPJMP,/* b x - (x!=nil)? PC-=b */ |
| 127 | IFFUPJMPB,/* b x - (x==nil)? PC-=b */ | 134 | IFTUPJMPW,/* w x - (x!=nil)? PC-=w */ |
| 128 | IFFUPJMP,/* w x - (x==nil)? PC-=w */ | 135 | IFFUPJMP,/* b x - (x==nil)? PC-=b */ |
| 129 | 136 | IFFUPJMPW,/* w x - (x==nil)? PC-=w */ | |
| 130 | CLOSUREB,/* b v_1...v_n c(CNST[b]) */ | 137 | |
| 131 | CLOSURE,/* w v_1...v_n c(CNST[w]) */ | 138 | CLOSURE,/* b v_1...v_n c(CNST[b]) */ |
| 132 | 139 | CLOSUREW,/* w v_1...v_n c(CNST[w]) */ | |
| 133 | CALLFUNC,/* b c v_b...v_1 f r_c...r_1 f(v1,...,v_b) */ | 140 | |
| 141 | CALLFUNC,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */ | ||
| 142 | CALLFUNC0,/* b v_b...v_1 f - f(v1,...,v_b) */ | ||
| 143 | CALLFUNC1,/* b v_b...v_1 f r_1 f(v1,...,v_b) */ | ||
| 144 | |||
| 134 | RETCODE,/* b - - */ | 145 | RETCODE,/* b - - */ |
| 135 | SETLINE,/* w - - LINE=w */ | 146 | |
| 136 | POP1,/* - - - TOP-=1 */ | 147 | SETLINE,/* b - - LINE=b */ |
| 137 | POP2,/* - - - TOP-=2 */ | 148 | SETLINEW,/* w - - LINE=w */ |
| 138 | POPS,/* b - - TOP-=b */ | 149 | |
| 150 | POP,/* b - - TOP-=(b+1) */ | ||
| 151 | POP0,/* - - - TOP-=1 */ | ||
| 152 | POP1,/* - - - TOP-=2 */ | ||
| 153 | |||
| 139 | ARGS,/* b - - TOP=BASE+b */ | 154 | ARGS,/* b - - TOP=BASE+b */ |
| 140 | VARARGS/* b v_x...v_1 {v_1...v_x;n=x} TOP=BASE+b+1 */ | 155 | VARARGS/* b v_x...v_1 {v_1...v_x;n=x} TOP=BASE+b+1 */ |
| 141 | } OpCode; | 156 | } OpCode; |
| @@ -1,6 +1,6 @@ | |||
| 1 | %{ | 1 | %{ |
| 2 | /* | 2 | /* |
| 3 | ** $Id: lua.stx,v 1.7 1997/10/01 20:05:34 roberto Exp roberto $ | 3 | ** $Id: lua.stx,v 1.8 1997/10/06 14:51:11 roberto Exp roberto $ |
| 4 | ** Syntax analizer and code generator | 4 | ** Syntax analizer and code generator |
| 5 | ** See Copyright Notice in lua.h | 5 | ** See Copyright Notice in lua.h |
| 6 | */ | 6 | */ |
| @@ -23,9 +23,6 @@ | |||
| 23 | 23 | ||
| 24 | /* to avoid warnings generated by yacc */ | 24 | /* to avoid warnings generated by yacc */ |
| 25 | int luaY_parse (void); | 25 | int luaY_parse (void); |
| 26 | #define malloc luaM_malloc | ||
| 27 | #define realloc luaM_realloc | ||
| 28 | #define free luaM_free | ||
| 29 | 26 | ||
| 30 | 27 | ||
| 31 | /* size of a "normal" jump instruction: OpCode + 1 byte */ | 28 | /* size of a "normal" jump instruction: OpCode + 1 byte */ |
| @@ -118,23 +115,6 @@ static void code_byte (Byte c) | |||
| 118 | } | 115 | } |
| 119 | 116 | ||
| 120 | 117 | ||
| 121 | static void code_word_at (int pc, int n) | ||
| 122 | { | ||
| 123 | if (n > MAX_WORD) | ||
| 124 | luaY_error("construction too big; unable to compile"); | ||
| 125 | currState->f->code[pc] = n&0xFF; | ||
| 126 | currState->f->code[pc+1] = n>>8; | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | static void code_word (int n) | ||
| 131 | { | ||
| 132 | check_pc(2); | ||
| 133 | currState->pc += 2; | ||
| 134 | code_word_at(currState->pc-2, n); | ||
| 135 | } | ||
| 136 | |||
| 137 | |||
| 138 | static void deltastack (int delta) | 118 | static void deltastack (int delta) |
| 139 | { | 119 | { |
| 140 | currState->stacksize += delta; | 120 | currState->stacksize += delta; |
| @@ -146,41 +126,55 @@ static void deltastack (int delta) | |||
| 146 | } | 126 | } |
| 147 | 127 | ||
| 148 | 128 | ||
| 149 | static void code_opcode (OpCode op, int delta) | 129 | static int code_oparg_at (int pc, OpCode op, int builtin, int arg, int delta) |
| 150 | { | 130 | { |
| 151 | code_byte(op); | ||
| 152 | deltastack(delta); | 131 | deltastack(delta); |
| 132 | if (arg < builtin) { | ||
| 133 | currState->f->code[pc] = op+1+arg; | ||
| 134 | return 1; | ||
| 135 | } | ||
| 136 | else if (arg <= 255) { | ||
| 137 | currState->f->code[pc] = op; | ||
| 138 | currState->f->code[pc+1] = arg; | ||
| 139 | return 2; | ||
| 140 | } | ||
| 141 | else if (arg <= MAX_WORD) { | ||
| 142 | currState->f->code[pc] = op+1+builtin; | ||
| 143 | currState->f->code[pc+1] = arg&0xFF; | ||
| 144 | currState->f->code[pc+2] = arg>>8; | ||
| 145 | return 3; | ||
| 146 | } | ||
| 147 | else luaY_error("construction too big - unable to compile"); | ||
| 148 | return 0; /* to avoid warnings */ | ||
| 153 | } | 149 | } |
| 154 | 150 | ||
| 155 | 151 | ||
| 156 | static void code_opb (OpCode opbyte, int arg, int delta) | 152 | static int fix_opcode (int pc, OpCode op, int builtin, int arg) |
| 157 | { | 153 | { |
| 158 | code_opcode(opbyte, delta); | 154 | if (arg < builtin) { /* close space */ |
| 159 | code_byte(arg); | 155 | movecode_down(pc+1, pc+2, currState->pc-(pc+2)); |
| 160 | } | 156 | currState->pc--; |
| 161 | 157 | } | |
| 162 | static void code_opw (OpCode opbyte, int arg, int delta) | 158 | else if (arg > 255) { /* open space */ |
| 163 | { | 159 | check_pc(1); |
| 164 | code_opcode(opbyte, delta); | 160 | movecode_up(pc+1, pc, currState->pc-pc); |
| 165 | code_word(arg); | 161 | currState->pc++; |
| 162 | } | ||
| 163 | return code_oparg_at(pc, op, builtin, arg, 0) - 2; | ||
| 166 | } | 164 | } |
| 167 | 165 | ||
| 168 | 166 | ||
| 169 | static void code_opborw (OpCode opbyte, int arg, int delta) | 167 | static void code_oparg (OpCode op, int builtin, int arg, int delta) |
| 170 | { | 168 | { |
| 171 | if (arg <= 255) | 169 | check_pc(3); /* maximum code size */ |
| 172 | code_opb(opbyte, arg, delta); | 170 | currState->pc += code_oparg_at(currState->pc, op, builtin, arg, delta); |
| 173 | else | ||
| 174 | code_opw(opbyte+1, arg, delta); | ||
| 175 | } | 171 | } |
| 176 | 172 | ||
| 177 | 173 | ||
| 178 | static void code_oparg (OpCode firstop, OpCode opbyte, int arg, int delta) | 174 | static void code_opcode (OpCode op, int delta) |
| 179 | { | 175 | { |
| 180 | if (firstop+arg < opbyte) | 176 | deltastack(delta); |
| 181 | code_opcode(firstop+arg, delta); | 177 | code_byte(op); |
| 182 | else | ||
| 183 | code_opborw(opbyte, arg, delta); | ||
| 184 | } | 178 | } |
| 185 | 179 | ||
| 186 | 180 | ||
| @@ -193,7 +187,10 @@ static void code_pop (OpCode op) | |||
| 193 | #define code_binop(op) code_pop(op) | 187 | #define code_binop(op) code_pop(op) |
| 194 | 188 | ||
| 195 | 189 | ||
| 196 | #define code_neutralop(op) code_byte(op) | 190 | static void code_neutralop (OpCode op) |
| 191 | { | ||
| 192 | code_opcode(op, 0); | ||
| 193 | } | ||
| 197 | 194 | ||
| 198 | /* unary operations get 1 argument and leave one, so they are neutral */ | 195 | /* unary operations get 1 argument and leave one, so they are neutral */ |
| 199 | #define code_unop(op) code_neutralop(op) | 196 | #define code_unop(op) code_neutralop(op) |
| @@ -201,7 +198,7 @@ static void code_pop (OpCode op) | |||
| 201 | 198 | ||
| 202 | static void code_constant (int c) | 199 | static void code_constant (int c) |
| 203 | { | 200 | { |
| 204 | code_oparg(PUSHCONSTANT0, PUSHCONSTANTB, c, 1); | 201 | code_oparg(PUSHCONSTANT, 8, c, 1); |
| 205 | } | 202 | } |
| 206 | 203 | ||
| 207 | 204 | ||
| @@ -237,7 +234,7 @@ static void code_string (TaggedString *s) | |||
| 237 | } | 234 | } |
| 238 | 235 | ||
| 239 | 236 | ||
| 240 | #define LIM 13 | 237 | #define LIM 20 |
| 241 | static int real_constant (real r) | 238 | static int real_constant (real r) |
| 242 | { | 239 | { |
| 243 | /* check whether 'r' has appeared within the last LIM entries */ | 240 | /* check whether 'r' has appeared within the last LIM entries */ |
| @@ -261,7 +258,7 @@ static void code_number (real f) | |||
| 261 | { | 258 | { |
| 262 | Word i; | 259 | Word i; |
| 263 | if (f >= 0 && f <= (real)MAX_WORD && (real)(i=(Word)f) == f) | 260 | if (f >= 0 && f <= (real)MAX_WORD && (real)(i=(Word)f) == f) |
| 264 | code_oparg(PUSH0, PUSHBYTE, i, 1); /* f has an (short) integer value */ | 261 | code_oparg(PUSHNUMBER, 3, i, 1); /* f has an (short) integer value */ |
| 265 | else | 262 | else |
| 266 | code_constant(real_constant(f)); | 263 | code_constant(real_constant(f)); |
| 267 | } | 264 | } |
| @@ -270,18 +267,13 @@ static void code_number (real f) | |||
| 270 | static void flush_record (int n) | 267 | static void flush_record (int n) |
| 271 | { | 268 | { |
| 272 | if (n > 0) | 269 | if (n > 0) |
| 273 | code_opb(SETMAP, n, -2*n); | 270 | code_oparg(SETMAP, 1, n-1, -2*n); |
| 274 | } | 271 | } |
| 275 | 272 | ||
| 276 | static void flush_list (int m, int n) | 273 | static void flush_list (int m, int n) |
| 277 | { | 274 | { |
| 278 | if (n == 0) return; | 275 | if (n == 0) return; |
| 279 | if (m == 0) | 276 | code_oparg(SETLIST, 1, m, -n); |
| 280 | code_opcode(SETLIST0, -n); | ||
| 281 | else if (m < 255) | ||
| 282 | code_opb(SETLIST, m, -n); | ||
| 283 | else | ||
| 284 | luaY_error("list constructor too long"); | ||
| 285 | code_byte(n); | 277 | code_byte(n); |
| 286 | } | 278 | } |
| 287 | 279 | ||
| @@ -375,7 +367,7 @@ static void pushupvalue (TaggedString *n) | |||
| 375 | if (aux_localname(n, currState) >= 0) | 367 | if (aux_localname(n, currState) >= 0) |
| 376 | luaY_syntaxerror("cannot access an upvalue in current scope", n->str); | 368 | luaY_syntaxerror("cannot access an upvalue in current scope", n->str); |
| 377 | i = indexupvalue(n); | 369 | i = indexupvalue(n); |
| 378 | code_oparg(PUSHUPVALUE0, PUSHUPVALUE, i, 1); | 370 | code_oparg(PUSHUPVALUE, 2, i, 1); |
| 379 | } | 371 | } |
| 380 | 372 | ||
| 381 | 373 | ||
| @@ -383,7 +375,7 @@ void luaY_codedebugline (int line) | |||
| 383 | { | 375 | { |
| 384 | static int lastline = 0; | 376 | static int lastline = 0; |
| 385 | if (lua_debug && line != lastline) { | 377 | if (lua_debug && line != lastline) { |
| 386 | code_opw(SETLINE, line, 0); | 378 | code_oparg(SETLINE, 0, line, 0); |
| 387 | lastline = line; | 379 | lastline = line; |
| 388 | } | 380 | } |
| 389 | } | 381 | } |
| @@ -392,22 +384,25 @@ void luaY_codedebugline (int line) | |||
| 392 | static void adjuststack (int n) | 384 | static void adjuststack (int n) |
| 393 | { | 385 | { |
| 394 | if (n > 0) | 386 | if (n > 0) |
| 395 | code_oparg(POP1-1, POPS, n, -n); /* POP1-1 = POP0 */ | 387 | code_oparg(POP, 2, n-1, -n); |
| 396 | else if (n < 0) | 388 | else if (n < 0) |
| 397 | code_oparg(PUSHNIL-1, PUSHNILS, -n, -n); /* PUSHNIL1-1 = PUSHNIL0 */ | 389 | code_oparg(PUSHNIL, 1, (-n)-1, -n); |
| 398 | } | 390 | } |
| 399 | 391 | ||
| 400 | 392 | ||
| 401 | static long adjust_functioncall (long exp, int i) | 393 | static long adjust_functioncall (long exp, int nresults) |
| 402 | { | 394 | { |
| 403 | if (exp <= 0) | 395 | if (exp <= 0) |
| 404 | return -exp; /* exp is -list length */ | 396 | return -exp; /* exp is -list length */ |
| 405 | else { | 397 | else { |
| 406 | int temp = currState->f->code[exp]; | 398 | int temp = currState->f->code[exp]; |
| 407 | currState->f->code[exp] = i; | 399 | int nparams = currState->f->code[exp-1]; |
| 408 | if (i != MULT_RET) | 400 | exp += fix_opcode(exp-2, CALLFUNC, 2, nresults); |
| 409 | deltastack(i); | 401 | currState->f->code[exp] = nparams; |
| 410 | return temp+i; | 402 | if (nresults != MULT_RET) |
| 403 | deltastack(nresults); | ||
| 404 | deltastack(-(nparams+1)); | ||
| 405 | return temp+nresults; | ||
| 411 | } | 406 | } |
| 412 | } | 407 | } |
| 413 | 408 | ||
| @@ -430,9 +425,9 @@ static void adjust_mult_assign (int vars, long exps) | |||
| 430 | static void code_args (int dots) | 425 | static void code_args (int dots) |
| 431 | { | 426 | { |
| 432 | if (!dots) | 427 | if (!dots) |
| 433 | code_opb(ARGS, currState->nlocalvar, currState->nlocalvar); | 428 | code_oparg(ARGS, 0, currState->nlocalvar, currState->nlocalvar); |
| 434 | else { | 429 | else { |
| 435 | code_opb(VARARGS, currState->nlocalvar, currState->nlocalvar+1); | 430 | code_oparg(VARARGS, 0, currState->nlocalvar, currState->nlocalvar+1); |
| 436 | add_localvar(luaS_new("arg")); | 431 | add_localvar(luaS_new("arg")); |
| 437 | } | 432 | } |
| 438 | } | 433 | } |
| @@ -441,9 +436,9 @@ static void code_args (int dots) | |||
| 441 | static void lua_pushvar (vardesc number) | 436 | static void lua_pushvar (vardesc number) |
| 442 | { | 437 | { |
| 443 | if (number > 0) /* global var */ | 438 | if (number > 0) /* global var */ |
| 444 | code_oparg(GETGLOBAL0, GETGLOBALB, number-1, 1); | 439 | code_oparg(GETGLOBAL, 8, number-1, 1); |
| 445 | else if (number < 0) /* local var */ | 440 | else if (number < 0) /* local var */ |
| 446 | code_oparg(PUSHLOCAL0, PUSHLOCAL, (-number)-1, 1); | 441 | code_oparg(PUSHLOCAL, 8, (-number)-1, 1); |
| 447 | else | 442 | else |
| 448 | code_pop(GETTABLE); | 443 | code_pop(GETTABLE); |
| 449 | } | 444 | } |
| @@ -454,9 +449,9 @@ static void storevar (vardesc number) | |||
| 454 | if (number == 0) /* indexed var */ | 449 | if (number == 0) /* indexed var */ |
| 455 | code_opcode(SETTABLE0, -3); | 450 | code_opcode(SETTABLE0, -3); |
| 456 | else if (number > 0) /* global var */ | 451 | else if (number > 0) /* global var */ |
| 457 | code_opborw(SETGLOBALB, number-1, -1); | 452 | code_oparg(SETGLOBAL, 8, number-1, -1); |
| 458 | else /* number < 0 - local var */ | 453 | else /* number < 0 - local var */ |
| 459 | code_oparg(SETLOCAL0, SETLOCAL, (-number)-1, -1); | 454 | code_oparg(SETLOCAL, 8, (-number)-1, -1); |
| 460 | } | 455 | } |
| 461 | 456 | ||
| 462 | 457 | ||
| @@ -469,35 +464,16 @@ static int lua_codestore (int i, int left) | |||
| 469 | return left; | 464 | return left; |
| 470 | } | 465 | } |
| 471 | else { /* indexed var with values in between*/ | 466 | else { /* indexed var with values in between*/ |
| 472 | code_pop(SETTABLE); | 467 | code_oparg(SETTABLE, 0, left+i, -1); |
| 473 | code_byte(left+i); /* number of elements between table/index and value */ | ||
| 474 | return left+2; /* table/index are not poped, since they are not on top */ | 468 | return left+2; /* table/index are not poped, since they are not on top */ |
| 475 | } | 469 | } |
| 476 | } | 470 | } |
| 477 | 471 | ||
| 478 | 472 | ||
| 479 | static int fix_opcode (int pc, OpCode op, int n) | ||
| 480 | { | ||
| 481 | if (n <= 255) { | ||
| 482 | currState->f->code[pc] = op; | ||
| 483 | currState->f->code[pc+1] = n; | ||
| 484 | return 0; | ||
| 485 | } | ||
| 486 | else { | ||
| 487 | check_pc(1); /* open space */ | ||
| 488 | movecode_up(pc+1, pc, currState->pc-pc); | ||
| 489 | currState->pc++; | ||
| 490 | currState->f->code[pc] = op+1; /* opcode must be word variant */ | ||
| 491 | code_word_at(pc+1, n); | ||
| 492 | return 1; | ||
| 493 | } | ||
| 494 | } | ||
| 495 | |||
| 496 | |||
| 497 | static int fix_jump (int pc, OpCode op, int n) | 473 | static int fix_jump (int pc, OpCode op, int n) |
| 498 | { | 474 | { |
| 499 | /* jump is relative to position following jump instruction */ | 475 | /* jump is relative to position following jump instruction */ |
| 500 | return fix_opcode(pc, op, n-(pc+JMPSIZE)); | 476 | return fix_opcode(pc, op, 0, n-(pc+JMPSIZE)); |
| 501 | } | 477 | } |
| 502 | 478 | ||
| 503 | 479 | ||
| @@ -505,7 +481,7 @@ static void fix_upjmp (OpCode op, int pos) | |||
| 505 | { | 481 | { |
| 506 | int delta = currState->pc+JMPSIZE - pos; /* jump is relative */ | 482 | int delta = currState->pc+JMPSIZE - pos; /* jump is relative */ |
| 507 | if (delta > 255) delta++; | 483 | if (delta > 255) delta++; |
| 508 | code_opborw(op, delta, 0); | 484 | code_oparg(op, 0, delta, 0); |
| 509 | } | 485 | } |
| 510 | 486 | ||
| 511 | 487 | ||
| @@ -517,25 +493,20 @@ static void codeIf (int thenAdd, int elseAdd) | |||
| 517 | elseinit = currState->pc; | 493 | elseinit = currState->pc; |
| 518 | } | 494 | } |
| 519 | else | 495 | else |
| 520 | elseinit += fix_jump(elseAdd, JMPB, currState->pc); | 496 | elseinit += fix_jump(elseAdd, JMP, currState->pc); |
| 521 | fix_jump(thenAdd, IFFJMPB, elseinit); | 497 | fix_jump(thenAdd, IFFJMP, elseinit); |
| 522 | } | 498 | } |
| 523 | 499 | ||
| 524 | 500 | ||
| 525 | static void code_shortcircuit (OpCode op, int pos) | 501 | static void code_shortcircuit (int pc, OpCode op) |
| 526 | { | 502 | { |
| 527 | int dist = currState->pc - (pos+JMPSIZE); | 503 | fix_jump(pc, op, currState->pc); |
| 528 | if (dist > 255) | ||
| 529 | luaY_error("and/or expression too long"); | ||
| 530 | currState->f->code[pos] = op; | ||
| 531 | currState->f->code[pos+1] = dist; | ||
| 532 | } | 504 | } |
| 533 | 505 | ||
| 534 | 506 | ||
| 535 | static void codereturn (void) | 507 | static void codereturn (void) |
| 536 | { | 508 | { |
| 537 | code_neutralop(RETCODE); | 509 | code_oparg(RETCODE, 0, currState->nlocalvar, 0); |
| 538 | code_byte(currState->nlocalvar); | ||
| 539 | currState->stacksize = currState->nlocalvar; | 510 | currState->stacksize = currState->nlocalvar; |
| 540 | } | 511 | } |
| 541 | 512 | ||
| @@ -549,7 +520,7 @@ static void func_onstack (TProtoFunc *f) | |||
| 549 | currState->f->consts[c].value.tf = (currState+1)->f; | 520 | currState->f->consts[c].value.tf = (currState+1)->f; |
| 550 | for (i=0; i<nupvalues; i++) | 521 | for (i=0; i<nupvalues; i++) |
| 551 | lua_pushvar((currState+1)->upvalues[i]); | 522 | lua_pushvar((currState+1)->upvalues[i]); |
| 552 | code_opborw(CLOSUREB, c, 1-nupvalues); | 523 | code_oparg(CLOSURE, 0, c, 1-nupvalues); |
| 553 | } | 524 | } |
| 554 | 525 | ||
| 555 | 526 | ||
| @@ -585,7 +556,6 @@ static void init_func (void) | |||
| 585 | currState->f->lineDefined = luaX_linenumber; | 556 | currState->f->lineDefined = luaX_linenumber; |
| 586 | } | 557 | } |
| 587 | 558 | ||
| 588 | |||
| 589 | static TProtoFunc *close_func (void) | 559 | static TProtoFunc *close_func (void) |
| 590 | { | 560 | { |
| 591 | TProtoFunc *f = currState->f; | 561 | TProtoFunc *f = currState->f; |
| @@ -687,13 +657,13 @@ stat : IF cond THEN block SaveWord elsepart END | |||
| 687 | memcpy(&currState->f->code[currState->pc], | 657 | memcpy(&currState->f->code[currState->pc], |
| 688 | &currState->f->code[$2], expsize); | 658 | &currState->f->code[$2], expsize); |
| 689 | movecode_down($2, $3, currState->pc-$2); | 659 | movecode_down($2, $3, currState->pc-$2); |
| 690 | newpos += fix_jump($2, JMPB, currState->pc-expsize); | 660 | newpos += fix_jump($2, JMP, currState->pc-expsize); |
| 691 | fix_upjmp(IFTUPJMPB, newpos); | 661 | fix_upjmp(IFTUPJMP, newpos); |
| 692 | }} | 662 | }} |
| 693 | 663 | ||
| 694 | | REPEAT GetPC block UNTIL expr1 | 664 | | REPEAT GetPC block UNTIL expr1 |
| 695 | { | 665 | { |
| 696 | fix_upjmp(IFFUPJMPB, $2); | 666 | fix_upjmp(IFFUPJMP, $2); |
| 697 | deltastack(-1); /* pops condition */ | 667 | deltastack(-1); /* pops condition */ |
| 698 | } | 668 | } |
| 699 | 669 | ||
| @@ -706,7 +676,7 @@ stat : IF cond THEN block SaveWord elsepart END | |||
| 706 | left = lua_codestore(i, left); | 676 | left = lua_codestore(i, left); |
| 707 | adjuststack(left); /* remove eventual 'garbage' left on stack */ | 677 | adjuststack(left); /* remove eventual 'garbage' left on stack */ |
| 708 | }} | 678 | }} |
| 709 | | functioncall | 679 | | functioncall { adjust_functioncall($1, 0); } |
| 710 | | LOCAL localdeclist decinit | 680 | | LOCAL localdeclist decinit |
| 711 | { | 681 | { |
| 712 | currState->nlocalvar += $2; | 682 | currState->nlocalvar += $2; |
| @@ -757,7 +727,11 @@ ret : /* empty */ | |||
| 757 | GetPC : /* empty */ { $$ = currState->pc; } | 727 | GetPC : /* empty */ { $$ = currState->pc; } |
| 758 | ; | 728 | ; |
| 759 | 729 | ||
| 760 | SaveWord : GetPC { $$ = $1; code_word(0); /* open space */ } | 730 | SaveWord : /* empty */ |
| 731 | { $$ = currState->pc; | ||
| 732 | check_pc(JMPSIZE); | ||
| 733 | currState->pc += JMPSIZE; /* open space */ | ||
| 734 | } | ||
| 761 | ; | 735 | ; |
| 762 | 736 | ||
| 763 | SaveWordPop : SaveWord { $$ = $1; deltastack(-1); /* pop condition */ } | 737 | SaveWordPop : SaveWord { $$ = $1; deltastack(-1); /* pop condition */ } |
| @@ -787,33 +761,33 @@ expr : '(' expr ')' { $$ = $2; } | |||
| 787 | | expr1 CONC expr1 { code_binop(CONCOP); $$ = 0; } | 761 | | expr1 CONC expr1 { code_binop(CONCOP); $$ = 0; } |
| 788 | | '-' expr1 %prec UNARY { code_unop(MINUSOP); $$ = 0;} | 762 | | '-' expr1 %prec UNARY { code_unop(MINUSOP); $$ = 0;} |
| 789 | | NOT expr1 { code_unop(NOTOP); $$ = 0;} | 763 | | NOT expr1 { code_unop(NOTOP); $$ = 0;} |
| 790 | | table { $$ = 0; } | 764 | | table { $$ = 0; } |
| 791 | | varexp { $$ = 0;} | 765 | | varexp { $$ = 0;} |
| 792 | | NUMBER { code_number($1); $$ = 0; } | 766 | | NUMBER { code_number($1); $$ = 0; } |
| 793 | | STRING { code_string($1); $$ = 0; } | 767 | | STRING { code_string($1); $$ = 0; } |
| 794 | | NIL {code_opcode(PUSHNIL, 1); $$ = 0; } | 768 | | NIL { adjuststack(-1); $$ = 0; } |
| 795 | | functioncall { $$ = $1; } | 769 | | functioncall { $$ = $1; } |
| 796 | | FUNCTION { init_func(); } body { func_onstack($3); $$ = 0; } | 770 | | FUNCTION { init_func(); } body { func_onstack($3); $$ = 0; } |
| 797 | | expr1 AND SaveWordPop expr1 { code_shortcircuit(ONFJMP, $3); $$ = 0; } | 771 | | expr1 AND SaveWordPop expr1 { code_shortcircuit($3, ONFJMP); $$ = 0; } |
| 798 | | expr1 OR SaveWordPop expr1 { code_shortcircuit(ONTJMP, $3); $$ = 0; } | 772 | | expr1 OR SaveWordPop expr1 { code_shortcircuit($3, ONTJMP); $$ = 0; } |
| 799 | ; | 773 | ; |
| 800 | 774 | ||
| 801 | table : '{' SaveWordPush fieldlist '}' { fix_opcode($2, CREATEARRAYB, $3); } | 775 | table : '{' SaveWordPush fieldlist '}' { fix_opcode($2, CREATEARRAY, 2, $3); } |
| 802 | ; | 776 | ; |
| 803 | 777 | ||
| 804 | functioncall : funcvalue funcParams | 778 | functioncall : funcvalue funcParams |
| 805 | { | 779 | { |
| 806 | code_opcode(CALLFUNC, -($1+$2+1)); /* ajdust counts results */ | 780 | code_byte(0); /* save space for opcode */ |
| 807 | code_byte($1+$2); | 781 | code_byte($1+$2); /* number of parameters */ |
| 808 | $$ = currState->pc; | 782 | $$ = currState->pc; |
| 809 | code_byte(0); /* may be adjusted by other rules */ | 783 | code_byte(0); /* must be adjusted by other rules */ |
| 810 | } | 784 | } |
| 811 | ; | 785 | ; |
| 812 | 786 | ||
| 813 | funcvalue : varexp { $$ = 0; } | 787 | funcvalue : varexp { $$ = 0; } |
| 814 | | varexp ':' NAME | 788 | | varexp ':' NAME |
| 815 | { | 789 | { |
| 816 | code_opborw(PUSHSELFB, string_constant($3, currState), 1); | 790 | code_oparg(PUSHSELF, 0, string_constant($3, currState), 1); |
| 817 | $$ = 1; | 791 | $$ = 1; |
| 818 | } | 792 | } |
| 819 | ; | 793 | ; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.7 1997/10/01 20:05:34 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.8 1997/10/06 14:51:11 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -284,25 +284,25 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 284 | int aux; | 284 | int aux; |
| 285 | switch ((OpCode)(aux = *pc++)) { | 285 | switch ((OpCode)(aux = *pc++)) { |
| 286 | 286 | ||
| 287 | case PUSHNIL: | 287 | case PUSHNIL0: |
| 288 | ttype(luaD_stack.top++) = LUA_T_NIL; | 288 | ttype(luaD_stack.top++) = LUA_T_NIL; |
| 289 | break; | 289 | break; |
| 290 | 290 | ||
| 291 | case PUSHNILS: { | 291 | case PUSHNIL: |
| 292 | int n = *pc++; | 292 | aux = *pc++; |
| 293 | while (n--) | 293 | do { |
| 294 | ttype(luaD_stack.top++) = LUA_T_NIL; | 294 | ttype(luaD_stack.top++) = LUA_T_NIL; |
| 295 | } while (aux--); | ||
| 295 | break; | 296 | break; |
| 296 | } | ||
| 297 | 297 | ||
| 298 | case PUSHBYTE: | 298 | case PUSHNUMBER: |
| 299 | aux = *pc++; goto pushnumber; | 299 | aux = *pc++; goto pushnumber; |
| 300 | 300 | ||
| 301 | case PUSHWORD: | 301 | case PUSHNUMBERW: |
| 302 | aux = next_word(pc); goto pushnumber; | 302 | aux = next_word(pc); goto pushnumber; |
| 303 | 303 | ||
| 304 | case PUSH0: case PUSH1: case PUSH2: | 304 | case PUSHNUMBER0: case PUSHNUMBER1: case PUSHNUMBER2: |
| 305 | aux -= PUSH0; | 305 | aux -= PUSHNUMBER0; |
| 306 | pushnumber: | 306 | pushnumber: |
| 307 | ttype(luaD_stack.top) = LUA_T_NUMBER; | 307 | ttype(luaD_stack.top) = LUA_T_NUMBER; |
| 308 | nvalue(luaD_stack.top) = aux; | 308 | nvalue(luaD_stack.top) = aux; |
| @@ -312,25 +312,21 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 312 | case PUSHLOCAL: | 312 | case PUSHLOCAL: |
| 313 | aux = *pc++; goto pushlocal; | 313 | aux = *pc++; goto pushlocal; |
| 314 | 314 | ||
| 315 | case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: | 315 | case PUSHLOCAL0: case PUSHLOCAL1: case PUSHLOCAL2: case PUSHLOCAL3: |
| 316 | case PUSHLOCAL3: case PUSHLOCAL4: case PUSHLOCAL5: | 316 | case PUSHLOCAL4: case PUSHLOCAL5: case PUSHLOCAL6: case PUSHLOCAL7: |
| 317 | case PUSHLOCAL6: case PUSHLOCAL7: case PUSHLOCAL8: | ||
| 318 | case PUSHLOCAL9: | ||
| 319 | aux -= PUSHLOCAL0; | 317 | aux -= PUSHLOCAL0; |
| 320 | pushlocal: | 318 | pushlocal: |
| 321 | *luaD_stack.top++ = *((luaD_stack.stack+base) + aux); | 319 | *luaD_stack.top++ = *((luaD_stack.stack+base) + aux); |
| 322 | break; | 320 | break; |
| 323 | 321 | ||
| 324 | case GETGLOBAL: | 322 | case GETGLOBALW: |
| 325 | aux = next_word(pc); goto getglobal; | 323 | aux = next_word(pc); goto getglobal; |
| 326 | 324 | ||
| 327 | case GETGLOBALB: | 325 | case GETGLOBAL: |
| 328 | aux = *pc++; goto getglobal; | 326 | aux = *pc++; goto getglobal; |
| 329 | 327 | ||
| 330 | case GETGLOBAL0: case GETGLOBAL1: case GETGLOBAL2: | 328 | case GETGLOBAL0: case GETGLOBAL1: case GETGLOBAL2: case GETGLOBAL3: |
| 331 | case GETGLOBAL3: case GETGLOBAL4: case GETGLOBAL5: | 329 | case GETGLOBAL4: case GETGLOBAL5: case GETGLOBAL6: case GETGLOBAL7: |
| 332 | case GETGLOBAL6: case GETGLOBAL7: case GETGLOBAL8: | ||
| 333 | case GETGLOBAL9: | ||
| 334 | aux -= GETGLOBAL0; | 330 | aux -= GETGLOBAL0; |
| 335 | getglobal: | 331 | getglobal: |
| 336 | luaV_getglobal(tsvalue(&consts[aux])); | 332 | luaV_getglobal(tsvalue(&consts[aux])); |
| @@ -340,10 +336,10 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 340 | luaV_gettable(); | 336 | luaV_gettable(); |
| 341 | break; | 337 | break; |
| 342 | 338 | ||
| 343 | case PUSHSELF: | 339 | case PUSHSELFW: |
| 344 | aux = next_word(pc); goto pushself; | 340 | aux = next_word(pc); goto pushself; |
| 345 | 341 | ||
| 346 | case PUSHSELFB: | 342 | case PUSHSELF: |
| 347 | aux = *pc++; | 343 | aux = *pc++; |
| 348 | pushself: { | 344 | pushself: { |
| 349 | TObject receiver = *(luaD_stack.top-1); | 345 | TObject receiver = *(luaD_stack.top-1); |
| @@ -353,16 +349,15 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 353 | break; | 349 | break; |
| 354 | } | 350 | } |
| 355 | 351 | ||
| 356 | case PUSHCONSTANT: | 352 | case PUSHCONSTANTW: |
| 357 | aux = next_word(pc); goto pushconstant; | 353 | aux = next_word(pc); goto pushconstant; |
| 358 | 354 | ||
| 359 | case PUSHCONSTANTB: | 355 | case PUSHCONSTANT: |
| 360 | aux = *pc++; goto pushconstant; | 356 | aux = *pc++; goto pushconstant; |
| 361 | 357 | ||
| 362 | case PUSHCONSTANT0: case PUSHCONSTANT1: case PUSHCONSTANT2: | 358 | case PUSHCONSTANT0: case PUSHCONSTANT1: case PUSHCONSTANT2: |
| 363 | case PUSHCONSTANT3: case PUSHCONSTANT4: case PUSHCONSTANT5: | 359 | case PUSHCONSTANT3: case PUSHCONSTANT4: case PUSHCONSTANT5: |
| 364 | case PUSHCONSTANT6: case PUSHCONSTANT7: case PUSHCONSTANT8: | 360 | case PUSHCONSTANT6: case PUSHCONSTANT7: |
| 365 | case PUSHCONSTANT9: | ||
| 366 | aux -= PUSHCONSTANT0; | 361 | aux -= PUSHCONSTANT0; |
| 367 | pushconstant: | 362 | pushconstant: |
| 368 | *luaD_stack.top++ = consts[aux]; | 363 | *luaD_stack.top++ = consts[aux]; |
| @@ -380,20 +375,22 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 380 | case SETLOCAL: | 375 | case SETLOCAL: |
| 381 | aux = *pc++; goto setlocal; | 376 | aux = *pc++; goto setlocal; |
| 382 | 377 | ||
| 383 | case SETLOCAL0: case SETLOCAL1: case SETLOCAL2: | 378 | case SETLOCAL0: case SETLOCAL1: case SETLOCAL2: case SETLOCAL3: |
| 384 | case SETLOCAL3: case SETLOCAL4: case SETLOCAL5: | 379 | case SETLOCAL4: case SETLOCAL5: case SETLOCAL6: case SETLOCAL7: |
| 385 | case SETLOCAL6: case SETLOCAL7: case SETLOCAL8: | ||
| 386 | case SETLOCAL9: | ||
| 387 | aux -= SETLOCAL0; | 380 | aux -= SETLOCAL0; |
| 388 | setlocal: | 381 | setlocal: |
| 389 | *((luaD_stack.stack+base) + aux) = *(--luaD_stack.top); | 382 | *((luaD_stack.stack+base) + aux) = *(--luaD_stack.top); |
| 390 | break; | 383 | break; |
| 391 | 384 | ||
| 392 | case SETGLOBAL: | 385 | case SETGLOBALW: |
| 393 | aux = next_word(pc); goto setglobal; | 386 | aux = next_word(pc); goto setglobal; |
| 394 | 387 | ||
| 395 | case SETGLOBALB: | 388 | case SETGLOBAL: |
| 396 | aux = *pc++; | 389 | aux = *pc++; goto setglobal; |
| 390 | |||
| 391 | case SETGLOBAL0: case SETGLOBAL1: case SETGLOBAL2: case SETGLOBAL3: | ||
| 392 | case SETGLOBAL4: case SETGLOBAL5: case SETGLOBAL6: case SETGLOBAL7: | ||
| 393 | aux -= SETGLOBAL0; | ||
| 397 | setglobal: | 394 | setglobal: |
| 398 | luaV_setglobal(tsvalue(&consts[aux])); | 395 | luaV_setglobal(tsvalue(&consts[aux])); |
| 399 | break; | 396 | break; |
| @@ -406,6 +403,9 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 406 | luaV_settable(luaD_stack.top-3-(*pc++), 2); | 403 | luaV_settable(luaD_stack.top-3-(*pc++), 2); |
| 407 | break; | 404 | break; |
| 408 | 405 | ||
| 406 | case SETLISTW: | ||
| 407 | aux = next_word(pc); aux *= LFIELDS_PER_FLUSH; goto setlist; | ||
| 408 | |||
| 409 | case SETLIST: | 409 | case SETLIST: |
| 410 | aux = *(pc++) * LFIELDS_PER_FLUSH; goto setlist; | 410 | aux = *(pc++) * LFIELDS_PER_FLUSH; goto setlist; |
| 411 | 411 | ||
| @@ -423,23 +423,27 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 423 | break; | 423 | break; |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | case SETMAP: { | 426 | case SETMAP0: |
| 427 | int n = *(pc++); | 427 | aux = 0; goto setmap; |
| 428 | TObject *arr = luaD_stack.top-(2*n)-1; | 428 | |
| 429 | while (n--) { | 429 | case SETMAP: |
| 430 | aux = *(pc++); | ||
| 431 | setmap: { | ||
| 432 | TObject *arr = luaD_stack.top-(2*aux)-3; | ||
| 433 | do { | ||
| 430 | *(luaH_set (avalue(arr), luaD_stack.top-2)) = *(luaD_stack.top-1); | 434 | *(luaH_set (avalue(arr), luaD_stack.top-2)) = *(luaD_stack.top-1); |
| 431 | luaD_stack.top-=2; | 435 | luaD_stack.top-=2; |
| 432 | } | 436 | } while (aux--); |
| 433 | break; | 437 | break; |
| 434 | } | 438 | } |
| 435 | 439 | ||
| 436 | case POPS: | 440 | case POP: |
| 437 | aux = *pc++; goto pop; | 441 | aux = *pc++; goto pop; |
| 438 | 442 | ||
| 439 | case POP1: case POP2: | 443 | case POP0: case POP1: |
| 440 | aux -= (POP1-1); | 444 | aux -= POP0; |
| 441 | pop: | 445 | pop: |
| 442 | luaD_stack.top -= aux; | 446 | luaD_stack.top -= (aux+1); |
| 443 | break; | 447 | break; |
| 444 | 448 | ||
| 445 | case ARGS: | 449 | case ARGS: |
| @@ -451,10 +455,13 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 451 | adjust_varargs(base + *(pc++)); | 455 | adjust_varargs(base + *(pc++)); |
| 452 | break; | 456 | break; |
| 453 | 457 | ||
| 454 | case CREATEARRAY: | 458 | case CREATEARRAYW: |
| 455 | aux = next_word(pc); goto createarray; | 459 | aux = next_word(pc); goto createarray; |
| 456 | 460 | ||
| 457 | case CREATEARRAYB: | 461 | case CREATEARRAY0: case CREATEARRAY1: |
| 462 | aux -= CREATEARRAY0; goto createarray; | ||
| 463 | |||
| 464 | case CREATEARRAY: | ||
| 458 | aux = *pc++; | 465 | aux = *pc++; |
| 459 | createarray: | 466 | createarray: |
| 460 | luaC_checkGC(); | 467 | luaC_checkGC(); |
| @@ -569,58 +576,66 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 569 | nvalue(luaD_stack.top-1) = 1; | 576 | nvalue(luaD_stack.top-1) = 1; |
| 570 | break; | 577 | break; |
| 571 | 578 | ||
| 579 | case ONTJMPW: | ||
| 580 | aux = next_word(pc); goto ontjmp; | ||
| 581 | |||
| 572 | case ONTJMP: | 582 | case ONTJMP: |
| 573 | aux = *pc++; | 583 | aux = *pc++; |
| 584 | ontjmp: | ||
| 574 | if (ttype(luaD_stack.top-1) != LUA_T_NIL) pc += aux; | 585 | if (ttype(luaD_stack.top-1) != LUA_T_NIL) pc += aux; |
| 575 | else luaD_stack.top--; | 586 | else luaD_stack.top--; |
| 576 | break; | 587 | break; |
| 577 | 588 | ||
| 589 | case ONFJMPW: | ||
| 590 | aux = next_word(pc); goto onfjmp; | ||
| 591 | |||
| 578 | case ONFJMP: | 592 | case ONFJMP: |
| 579 | aux = *pc++; | 593 | aux = *pc++; |
| 594 | onfjmp: | ||
| 580 | if (ttype(luaD_stack.top-1) == LUA_T_NIL) pc += aux; | 595 | if (ttype(luaD_stack.top-1) == LUA_T_NIL) pc += aux; |
| 581 | else luaD_stack.top--; | 596 | else luaD_stack.top--; |
| 582 | break; | 597 | break; |
| 583 | 598 | ||
| 584 | case JMP: | 599 | case JMPW: |
| 585 | aux = next_word(pc); goto jmp; | 600 | aux = next_word(pc); goto jmp; |
| 586 | 601 | ||
| 587 | case JMPB: | 602 | case JMP: |
| 588 | aux = *pc++; | 603 | aux = *pc++; |
| 589 | jmp: | 604 | jmp: |
| 590 | pc += aux; | 605 | pc += aux; |
| 591 | break; | 606 | break; |
| 592 | 607 | ||
| 593 | case IFFJMP: | 608 | case IFFJMPW: |
| 594 | aux = next_word(pc); goto iffjmp; | 609 | aux = next_word(pc); goto iffjmp; |
| 595 | 610 | ||
| 596 | case IFFJMPB: | 611 | case IFFJMP: |
| 597 | aux = *pc++; | 612 | aux = *pc++; |
| 598 | iffjmp: | 613 | iffjmp: |
| 599 | if (ttype(--luaD_stack.top) == LUA_T_NIL) pc += aux; | 614 | if (ttype(--luaD_stack.top) == LUA_T_NIL) pc += aux; |
| 600 | break; | 615 | break; |
| 601 | 616 | ||
| 602 | case IFTUPJMP: | 617 | case IFTUPJMPW: |
| 603 | aux = next_word(pc); goto iftupjmp; | 618 | aux = next_word(pc); goto iftupjmp; |
| 604 | 619 | ||
| 605 | case IFTUPJMPB: | 620 | case IFTUPJMP: |
| 606 | aux = *pc++; | 621 | aux = *pc++; |
| 607 | iftupjmp: | 622 | iftupjmp: |
| 608 | if (ttype(--luaD_stack.top) != LUA_T_NIL) pc -= aux; | 623 | if (ttype(--luaD_stack.top) != LUA_T_NIL) pc -= aux; |
| 609 | break; | 624 | break; |
| 610 | 625 | ||
| 611 | case IFFUPJMP: | 626 | case IFFUPJMPW: |
| 612 | aux = next_word(pc); goto iffupjmp; | 627 | aux = next_word(pc); goto iffupjmp; |
| 613 | 628 | ||
| 614 | case IFFUPJMPB: | 629 | case IFFUPJMP: |
| 615 | aux = *pc++; | 630 | aux = *pc++; |
| 616 | iffupjmp: | 631 | iffupjmp: |
| 617 | if (ttype(--luaD_stack.top) == LUA_T_NIL) pc -= aux; | 632 | if (ttype(--luaD_stack.top) == LUA_T_NIL) pc -= aux; |
| 618 | break; | 633 | break; |
| 619 | 634 | ||
| 620 | case CLOSURE: | 635 | case CLOSUREW: |
| 621 | aux = next_word(pc); goto closure; | 636 | aux = next_word(pc); goto closure; |
| 622 | 637 | ||
| 623 | case CLOSUREB: | 638 | case CLOSURE: |
| 624 | aux = *pc++; | 639 | aux = *pc++; |
| 625 | closure: | 640 | closure: |
| 626 | *luaD_stack.top++ = consts[aux]; | 641 | *luaD_stack.top++ = consts[aux]; |
| @@ -628,9 +643,14 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 628 | luaC_checkGC(); | 643 | luaC_checkGC(); |
| 629 | break; | 644 | break; |
| 630 | 645 | ||
| 631 | case CALLFUNC: { | 646 | case CALLFUNC: |
| 647 | aux = *pc++; goto callfunc; | ||
| 648 | |||
| 649 | case CALLFUNC0: case CALLFUNC1: | ||
| 650 | aux -= CALLFUNC0; | ||
| 651 | callfunc: { | ||
| 632 | StkId newBase = (luaD_stack.top-luaD_stack.stack)-(*pc++); | 652 | StkId newBase = (luaD_stack.top-luaD_stack.stack)-(*pc++); |
| 633 | luaD_call(newBase, *pc++); | 653 | luaD_call(newBase, aux); |
| 634 | break; | 654 | break; |
| 635 | } | 655 | } |
| 636 | 656 | ||
| @@ -642,19 +662,22 @@ StkId luaV_execute (Closure *cl, StkId base) | |||
| 642 | luaD_callHook(base, LUA_T_MARK, 1); | 662 | luaD_callHook(base, LUA_T_MARK, 1); |
| 643 | return (base + ((aux==RETCODE) ? *pc : 0)); | 663 | return (base + ((aux==RETCODE) ? *pc : 0)); |
| 644 | 664 | ||
| 645 | case SETLINE: { | 665 | case SETLINEW: |
| 646 | int line = next_word(pc); | 666 | aux = next_word(pc); goto setline; |
| 667 | |||
| 668 | case SETLINE: | ||
| 669 | aux = *pc++; | ||
| 670 | setline: | ||
| 647 | if ((luaD_stack.stack+base-1)->ttype != LUA_T_LINE) { | 671 | if ((luaD_stack.stack+base-1)->ttype != LUA_T_LINE) { |
| 648 | /* open space for LINE value */ | 672 | /* open space for LINE value */ |
| 649 | luaD_openstack((luaD_stack.top-luaD_stack.stack)-base); | 673 | luaD_openstack((luaD_stack.top-luaD_stack.stack)-base); |
| 650 | base++; | 674 | base++; |
| 651 | (luaD_stack.stack+base-1)->ttype = LUA_T_LINE; | 675 | (luaD_stack.stack+base-1)->ttype = LUA_T_LINE; |
| 652 | } | 676 | } |
| 653 | (luaD_stack.stack+base-1)->value.i = line; | 677 | (luaD_stack.stack+base-1)->value.i = aux; |
| 654 | if (lua_linehook) | 678 | if (lua_linehook) |
| 655 | luaD_lineHook(line); | 679 | luaD_lineHook(aux); |
| 656 | break; | 680 | break; |
| 657 | } | ||
| 658 | 681 | ||
| 659 | #ifdef DEBUG | 682 | #ifdef DEBUG |
| 660 | default: | 683 | default: |
