diff options
| -rw-r--r-- | lopcodes.h | 18 | ||||
| -rw-r--r-- | lparser.c | 13 | ||||
| -rw-r--r-- | lvm.c | 16 |
3 files changed, 30 insertions, 17 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lopcodes.h,v 1.22 1999/02/08 17:07:59 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.23 1999/02/08 18:54:19 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 | */ |
| @@ -21,11 +21,14 @@ ENDCODE,/* - - - */ | |||
| 21 | RETCODE,/* b - - */ | 21 | RETCODE,/* b - - */ |
| 22 | 22 | ||
| 23 | PUSHNIL,/* b - nil_0...nil_b */ | 23 | PUSHNIL,/* b - nil_0...nil_b */ |
| 24 | POP,/* b - - TOP-=(b+1) */ | 24 | POP,/* b - - TOP-=b */ |
| 25 | POPDUP,/* b v v TOP-=(b+1) */ | 25 | POPDUP,/* b v v TOP-=b */ |
| 26 | 26 | ||
| 27 | PUSHNUMBERW,/* w - (float)(w-NUMOFFSET) */ | 27 | PUSHNUMBERW,/* w - (float)w */ |
| 28 | PUSHNUMBER,/* b - (float)(b-NUMOFFSET) */ | 28 | PUSHNUMBER,/* b - (float)b */ |
| 29 | |||
| 30 | PUSHNEGW,/* w - (float)-w */ | ||
| 31 | PUSHNEG,/* b - (float)-b */ | ||
| 29 | 32 | ||
| 30 | PUSHCONSTANTW,/*w - CNST[w] */ | 33 | PUSHCONSTANTW,/*w - CNST[w] */ |
| 31 | PUSHCONSTANT,/* b - CNST[b] */ | 34 | PUSHCONSTANT,/* b - CNST[b] */ |
| @@ -57,7 +60,7 @@ SETGLOBALDUPW,/*w x x VAR[CNST[w]]=x */ | |||
| 57 | SETGLOBALDUP,/* b x x VAR[CNST[b]]=x */ | 60 | SETGLOBALDUP,/* b x x VAR[CNST[b]]=x */ |
| 58 | 61 | ||
| 59 | SETTABLEPOP,/* - v i t - t[i]=v */ | 62 | SETTABLEPOP,/* - v i t - t[i]=v */ |
| 60 | SETTABPPDUP,/* - v i t v t[i]=v */ | 63 | SETTABLEPOPDUP,/* - v i t v t[i]=v */ |
| 61 | 64 | ||
| 62 | SETTABLE,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */ | 65 | SETTABLE,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */ |
| 63 | SETTABLEDUP,/* b v a_b...a_1 i t v a_b...a_1 i t t[i]=v */ | 66 | SETTABLEDUP,/* b v a_b...a_1 i t v a_b...a_1 i t t[i]=v */ |
| @@ -95,6 +98,7 @@ IFTUPJMP,/* b x - (x!=nil)? PC-=b */ | |||
| 95 | IFFUPJMPW,/* w x - (x==nil)? PC-=w */ | 98 | IFFUPJMPW,/* w x - (x==nil)? PC-=w */ |
| 96 | IFFUPJMP,/* b x - (x==nil)? PC-=b */ | 99 | IFFUPJMP,/* b x - (x==nil)? PC-=b */ |
| 97 | 100 | ||
| 101 | CLOSUREW,/* w c v_c...v_1 closure(CNST[w], v_c...v_1) */ | ||
| 98 | CLOSURE,/* b c v_c...v_1 closure(CNST[b], v_c...v_1) */ | 102 | CLOSURE,/* b c v_c...v_1 closure(CNST[b], v_c...v_1) */ |
| 99 | 103 | ||
| 100 | CALLFUNC,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */ | 104 | CALLFUNC,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */ |
| @@ -107,8 +111,6 @@ LONGARG /* b (add b*(1<<16) to arg of next instruction) */ | |||
| 107 | } OpCode; | 111 | } OpCode; |
| 108 | 112 | ||
| 109 | 113 | ||
| 110 | #define NUMOFFSET 100 /* offset for immediate numbers */ | ||
| 111 | |||
| 112 | #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ | 114 | #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ |
| 113 | #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) */ | 115 | #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) */ |
| 114 | 116 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lparser.c,v 1.17 1999/02/08 17:07:59 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.18 1999/02/08 18:54:19 roberto Exp roberto $ |
| 3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -267,9 +267,11 @@ static int real_constant (FuncState *fs, real r) { | |||
| 267 | 267 | ||
| 268 | 268 | ||
| 269 | static void code_number (LexState *ls, real f) { | 269 | static void code_number (LexState *ls, real f) { |
| 270 | if (-NUMOFFSET <= f && f <= (real)(MAX_WORD-NUMOFFSET) && | 270 | real af = (f<0) ? -f : f; |
| 271 | (int)f == f) /* f+NUMOFFSET has a short integer value? */ | 271 | if (0 <= af && af <= (real)MAX_WORD && (int)af == af) { |
| 272 | code_oparg(ls, PUSHNUMBER, (int)f+NUMOFFSET, 1); | 272 | /* abs(f) has a short integer value */ |
| 273 | code_oparg(ls, (f<0) ? PUSHNEG : PUSHNUMBER, (int)af, 1); | ||
| 274 | } | ||
| 273 | else | 275 | else |
| 274 | code_constant(ls, real_constant(ls->fs, f)); | 276 | code_constant(ls, real_constant(ls->fs, f)); |
| 275 | } | 277 | } |
| @@ -474,7 +476,7 @@ static void lua_pushvar (LexState *ls, vardesc *var) { | |||
| 474 | 476 | ||
| 475 | /* to be used by "storevar" and assignment */ | 477 | /* to be used by "storevar" and assignment */ |
| 476 | static OpCode set_pop[] = {SETLOCAL, SETGLOBAL, SETTABLEPOP, SETTABLE}; | 478 | static OpCode set_pop[] = {SETLOCAL, SETGLOBAL, SETTABLEPOP, SETTABLE}; |
| 477 | static OpCode set_dup[] = {SETLOCALDUP, SETGLOBALDUP, SETTABPPDUP, | 479 | static OpCode set_dup[] = {SETLOCALDUP, SETGLOBALDUP, SETTABLEPOPDUP, |
| 478 | SETTABLEDUP}; | 480 | SETTABLEDUP}; |
| 479 | 481 | ||
| 480 | 482 | ||
| @@ -563,6 +565,7 @@ static void init_state (LexState *ls, FuncState *fs, TaggedString *filename) { | |||
| 563 | incr_top; | 565 | incr_top; |
| 564 | } | 566 | } |
| 565 | 567 | ||
| 568 | |||
| 566 | static void close_func (LexState *ls) { | 569 | static void close_func (LexState *ls) { |
| 567 | FuncState *fs = ls->fs; | 570 | FuncState *fs = ls->fs; |
| 568 | TProtoFunc *f = fs->f; | 571 | TProtoFunc *f = fs->f; |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 1.46 1999/02/08 17:07:59 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 1.47 1999/02/08 18:54:19 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 | */ |
| @@ -355,7 +355,14 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | |||
| 355 | case PUSHNUMBERW: aux += highbyte(*pc++); | 355 | case PUSHNUMBERW: aux += highbyte(*pc++); |
| 356 | case PUSHNUMBER: aux += *pc++; | 356 | case PUSHNUMBER: aux += *pc++; |
| 357 | ttype(S->top) = LUA_T_NUMBER; | 357 | ttype(S->top) = LUA_T_NUMBER; |
| 358 | nvalue(S->top) = aux-NUMOFFSET; | 358 | nvalue(S->top) = aux; |
| 359 | S->top++; | ||
| 360 | break; | ||
| 361 | |||
| 362 | case PUSHNEGW: aux += highbyte(*pc++); | ||
| 363 | case PUSHNEG: aux += *pc++; | ||
| 364 | ttype(S->top) = LUA_T_NUMBER; | ||
| 365 | nvalue(S->top) = -aux; | ||
| 359 | S->top++; | 366 | S->top++; |
| 360 | break; | 367 | break; |
| 361 | 368 | ||
| @@ -429,7 +436,7 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | |||
| 429 | S->top -= 2; /* pop table and index */ | 436 | S->top -= 2; /* pop table and index */ |
| 430 | break; | 437 | break; |
| 431 | 438 | ||
| 432 | case SETTABPPDUP: { | 439 | case SETTABLEPOPDUP: { |
| 433 | TObject temp = *(S->top-1); | 440 | TObject temp = *(S->top-1); |
| 434 | luaV_settable(S->top-3); | 441 | luaV_settable(S->top-3); |
| 435 | S->top--; /* pop index (temp goes into "table" position) */ | 442 | S->top--; /* pop index (temp goes into "table" position) */ |
| @@ -605,7 +612,8 @@ StkId luaV_execute (Closure *cl, TProtoFunc *tf, StkId base) { | |||
| 605 | if (ttype(--S->top) == LUA_T_NIL) pc -= aux; | 612 | if (ttype(--S->top) == LUA_T_NIL) pc -= aux; |
| 606 | break; | 613 | break; |
| 607 | 614 | ||
| 608 | case CLOSURE: aux = *pc++; | 615 | case CLOSUREW: aux += highbyte(*pc++); |
| 616 | case CLOSURE: aux += *pc++; | ||
| 609 | *S->top++ = consts[aux]; | 617 | *S->top++ = consts[aux]; |
| 610 | luaV_closure(*pc++); | 618 | luaV_closure(*pc++); |
| 611 | luaC_checkGC(); | 619 | luaC_checkGC(); |
