diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-08-04 16:15:05 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-08-04 16:15:05 -0300 |
commit | dd1aa28390ca1acc389a91f5c64a916f0339e594 (patch) | |
tree | b9b23515091875df7de6082a5e833774c9d434c9 | |
parent | abbf14cd32bf83d5ea5ab70977e0653a03b455c5 (diff) | |
download | lua-github-dd1aa28390ca1acc389a91f5c64a916f0339e594.tar.gz |
small optimization in opcodes for "and" and "or"
-rw-r--r-- | lua.stx | 6 | ||||
-rw-r--r-- | opcode.c | 6 | ||||
-rw-r--r-- | opcode.h | 15 | ||||
-rw-r--r-- | undump.c | 19 |
4 files changed, 16 insertions, 30 deletions
@@ -1,6 +1,6 @@ %{ -char *rcs_luastx = "$Id: lua.stx,v 3.49 1997/07/30 22:00:50 roberto Exp roberto $"; +char *rcs_luastx = "$Id: lua.stx,v 3.50 1997/07/31 20:46:59 roberto Exp roberto $"; #include <stdlib.h> @@ -660,12 +660,12 @@ expr : '(' expr ')' { $$ = $2; } | NIL {code_byte(PUSHNIL); $$ = 0; } | functioncall { $$ = $1; } | NOT expr1 { code_byte(NOTOP); $$ = 0;} - | expr1 AND PrepJump {code_byte(POP); } expr1 + | expr1 AND PrepJump expr1 { code_shortcircuit($3, ONFJMP); $$ = 0; } - | expr1 OR PrepJump {code_byte(POP); } expr1 + | expr1 OR PrepJump expr1 { code_shortcircuit($3, ONTJMP); $$ = 0; @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 4.20 1997/07/30 22:00:50 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 4.21 1997/07/31 19:37:37 roberto Exp roberto $"; #include <setjmp.h> #include <stdio.h> @@ -1384,6 +1384,7 @@ static StkId lua_execute (TFunc *func, StkId base) Word w; get_word(w,pc); if (ttype(top-1) != LUA_T_NIL) pc += w; + else top--; } break; @@ -1392,6 +1393,7 @@ static StkId lua_execute (TFunc *func, StkId base) Word w; get_word(w,pc); if (ttype(top-1) == LUA_T_NIL) pc += w; + else top--; } break; @@ -1429,8 +1431,6 @@ static StkId lua_execute (TFunc *func, StkId base) } break; - case POP: --top; break; - case CALLFUNC: { int nParams = *(pc++); @@ -1,6 +1,6 @@ /* ** TeCGraf - PUC-Rio -** $Id: opcode.h,v 3.36 1997/07/29 20:38:06 roberto Exp roberto $ +** $Id: opcode.h,v 3.37 1997/07/30 22:00:50 roberto Exp roberto $ */ #ifndef opcode_h @@ -60,7 +60,7 @@ PUSHLOCAL9,/* - LOC[9] */ PUSHLOCAL,/* b - LOC[b] */ PUSHGLOBAL,/* w - VAR[w] */ PUSHINDEXED,/* i t t[i] */ -PUSHSELF,/* w t t t[STR[w]] */ +PUSHSELF,/* w t t t[CNST[w]] */ STORELOCAL0,/* x - LOC[0]=x */ STORELOCAL1,/* x - LOC[1]=x */ STORELOCAL2,/* x - LOC[2]=x */ @@ -78,7 +78,7 @@ STOREINDEXED,/* b v a_b...a_1 i t a_b...a_1 i t t[i]=v */ STORELIST0,/* b v_b...v_1 t - t[i]=v_i */ STORELIST,/* b c v_b...v_1 t - t[i+c*FPF]=v_i */ STORERECORD,/* b - w_b...w_1 v_b...v_1 t - t[STR[w_i]]=v_i */ + w_b...w_1 v_b...v_1 t - t[CNST[w_i]]=v_i */ ADJUST0,/* - - TOP=BASE */ ADJUST,/* b - - TOP=BASE+b */ CREATEARRAY,/* w - newarray(size = w) */ @@ -95,21 +95,20 @@ POWOP,/* y x x^y */ CONCOP,/* y x x..y */ MINUSOP,/* x -x */ NOTOP,/* x (x==nil)? 1 : nil */ -ONTJMP,/* w x - (x!=nil)? PC+=w */ -ONFJMP,/* w x - (x==nil)? PC+=w */ +ONTJMP,/* w x (x!=nil)? x : - (x!=nil)? PC+=w */ +ONFJMP,/* w x (x==nil)? x : - (x==nil)? PC+=w */ JMP,/* w - - PC+=w */ UPJMP,/* w - - PC-=w */ IFFJMP,/* w x - (x==nil)? PC+=w */ IFFUPJMP,/* w x - (x==nil)? PC-=w */ -POP,/* x - */ CALLFUNC,/* b c v_b...v_1 f r_c...r_1 f(v1,...,v_b) */ RETCODE0, RETCODE,/* b - - */ SETLINE,/* w - - LINE=w */ VARARGS,/* b v_b...v_1 {v_1...v_b;n=b} */ STOREMAP,/* b v_b k_b ...v_1 k_1 t - t[k_i]=v_i */ -PUSHCONSTANTB,/*b - const[b] */ -PUSHCONSTANT,/* w - const[w] */ +PUSHCONSTANTB,/*b - CNST[b] */ +PUSHCONSTANT,/* w - CNST[w] */ ENDCODE = 127 } OpCode; @@ -3,7 +3,7 @@ ** load bytecodes from files */ -char* rcs_undump="$Id: undump.c,v 1.24 1997/06/17 18:19:17 roberto Exp roberto $"; +char* rcs_undump="$Id: undump.c,v 1.25 1997/07/29 19:44:02 roberto Exp roberto $"; #include <stdio.h> #include <string.h> @@ -67,7 +67,6 @@ static void FixCode(Byte* code, Byte* end) /* swap words */ case CONCOP: case MINUSOP: case NOTOP: - case POP: case RETCODE0: p++; break; @@ -86,9 +85,6 @@ static void FixCode(Byte* code, Byte* end) /* swap words */ case CALLFUNC: p+=3; break; - case PUSHFUNCTION: - p+=5; /* TODO: use sizeof(TFunc*) or old? */ - break; case PUSHWORD: case PUSHSELF: case CREATEARRAY: @@ -99,7 +95,6 @@ static void FixCode(Byte* code, Byte* end) /* swap words */ case IFFJMP: case IFFUPJMP: case SETLINE: - case PUSHSTRING: case PUSHGLOBAL: case STOREGLOBAL: { @@ -108,14 +103,6 @@ static void FixCode(Byte* code, Byte* end) /* swap words */ p+=3; break; } - case PUSHFLOAT: /* assumes sizeof(float)==4 */ - { - Byte t; - t=p[1]; p[1]=p[4]; p[4]=t; - t=p[2]; p[2]=p[3]; p[3]=t; - p+=5; - break; - } case STORERECORD: { int n=*++p; @@ -226,7 +213,7 @@ static void LoadFunction(ZIO* Z) { int i=LoadWord(Z); char* s=LoadString(Z); - int v=luaI_findconstantbyname(s); + int v; /*=luaI_findconstantbyname(s); ??????? */ Unthread(tf->code,i,v); } else @@ -324,7 +311,7 @@ int luaI_undump(ZIO* Z) while ((m=luaI_undump1(Z))) { int status=luaI_dorun(m); - luaI_freefunc(m); +/* luaI_freefunc(m); ???*/ if (status!=0) return status; } return 0; |