aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-02-09 13:59:10 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1999-02-09 13:59:10 -0200
commitad6c7b0dd4b31965ccf6f1c02448f4c306cc316b (patch)
treee1f3cb627bcf327578bfcbd8cefdf55d66802ae4
parent8b2d97d1871147c730a986656907837458b601f8 (diff)
downloadlua-ad6c7b0dd4b31965ccf6f1c02448f4c306cc316b.tar.gz
lua-ad6c7b0dd4b31965ccf6f1c02448f4c306cc316b.tar.bz2
lua-ad6c7b0dd4b31965ccf6f1c02448f4c306cc316b.zip
small corrections in opcodes.
-rw-r--r--lopcodes.h18
-rw-r--r--lparser.c13
-rw-r--r--lvm.c16
3 files changed, 30 insertions, 17 deletions
diff --git a/lopcodes.h b/lopcodes.h
index 9a2ef6a5..faae8597 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -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,/* - - - */
21RETCODE,/* b - - */ 21RETCODE,/* b - - */
22 22
23PUSHNIL,/* b - nil_0...nil_b */ 23PUSHNIL,/* b - nil_0...nil_b */
24POP,/* b - - TOP-=(b+1) */ 24POP,/* b - - TOP-=b */
25POPDUP,/* b v v TOP-=(b+1) */ 25POPDUP,/* b v v TOP-=b */
26 26
27PUSHNUMBERW,/* w - (float)(w-NUMOFFSET) */ 27PUSHNUMBERW,/* w - (float)w */
28PUSHNUMBER,/* b - (float)(b-NUMOFFSET) */ 28PUSHNUMBER,/* b - (float)b */
29
30PUSHNEGW,/* w - (float)-w */
31PUSHNEG,/* b - (float)-b */
29 32
30PUSHCONSTANTW,/*w - CNST[w] */ 33PUSHCONSTANTW,/*w - CNST[w] */
31PUSHCONSTANT,/* b - CNST[b] */ 34PUSHCONSTANT,/* b - CNST[b] */
@@ -57,7 +60,7 @@ SETGLOBALDUPW,/*w x x VAR[CNST[w]]=x */
57SETGLOBALDUP,/* b x x VAR[CNST[b]]=x */ 60SETGLOBALDUP,/* b x x VAR[CNST[b]]=x */
58 61
59SETTABLEPOP,/* - v i t - t[i]=v */ 62SETTABLEPOP,/* - v i t - t[i]=v */
60SETTABPPDUP,/* - v i t v t[i]=v */ 63SETTABLEPOPDUP,/* - v i t v t[i]=v */
61 64
62SETTABLE,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */ 65SETTABLE,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */
63SETTABLEDUP,/* b v a_b...a_1 i t v a_b...a_1 i t t[i]=v */ 66SETTABLEDUP,/* 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 */
95IFFUPJMPW,/* w x - (x==nil)? PC-=w */ 98IFFUPJMPW,/* w x - (x==nil)? PC-=w */
96IFFUPJMP,/* b x - (x==nil)? PC-=b */ 99IFFUPJMP,/* b x - (x==nil)? PC-=b */
97 100
101CLOSUREW,/* w c v_c...v_1 closure(CNST[w], v_c...v_1) */
98CLOSURE,/* b c v_c...v_1 closure(CNST[b], v_c...v_1) */ 102CLOSURE,/* b c v_c...v_1 closure(CNST[b], v_c...v_1) */
99 103
100CALLFUNC,/* b c v_c...v_1 f r_b...r_1 f(v1,...,v_c) */ 104CALLFUNC,/* 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
diff --git a/lparser.c b/lparser.c
index be44c693..c41f8b49 100644
--- a/lparser.c
+++ b/lparser.c
@@ -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
269static void code_number (LexState *ls, real f) { 269static 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 */
476static OpCode set_pop[] = {SETLOCAL, SETGLOBAL, SETTABLEPOP, SETTABLE}; 478static OpCode set_pop[] = {SETLOCAL, SETGLOBAL, SETTABLEPOP, SETTABLE};
477static OpCode set_dup[] = {SETLOCALDUP, SETGLOBALDUP, SETTABPPDUP, 479static 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
566static void close_func (LexState *ls) { 569static 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;
diff --git a/lvm.c b/lvm.c
index f321cb83..1cc025df 100644
--- a/lvm.c
+++ b/lvm.c
@@ -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();