aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-08-04 16:15:05 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-08-04 16:15:05 -0300
commitdd1aa28390ca1acc389a91f5c64a916f0339e594 (patch)
treeb9b23515091875df7de6082a5e833774c9d434c9
parentabbf14cd32bf83d5ea5ab70977e0653a03b455c5 (diff)
downloadlua-dd1aa28390ca1acc389a91f5c64a916f0339e594.tar.gz
lua-dd1aa28390ca1acc389a91f5c64a916f0339e594.tar.bz2
lua-dd1aa28390ca1acc389a91f5c64a916f0339e594.zip
small optimization in opcodes for "and" and "or"
-rw-r--r--lua.stx6
-rw-r--r--opcode.c6
-rw-r--r--opcode.h15
-rw-r--r--undump.c19
4 files changed, 16 insertions, 30 deletions
diff --git a/lua.stx b/lua.stx
index 45dbb7ee..7c1b748e 100644
--- a/lua.stx
+++ b/lua.stx
@@ -1,6 +1,6 @@
1%{ 1%{
2 2
3char *rcs_luastx = "$Id: lua.stx,v 3.49 1997/07/30 22:00:50 roberto Exp roberto $"; 3char *rcs_luastx = "$Id: lua.stx,v 3.50 1997/07/31 20:46:59 roberto Exp roberto $";
4 4
5#include <stdlib.h> 5#include <stdlib.h>
6 6
@@ -660,12 +660,12 @@ expr : '(' expr ')' { $$ = $2; }
660 | NIL {code_byte(PUSHNIL); $$ = 0; } 660 | NIL {code_byte(PUSHNIL); $$ = 0; }
661 | functioncall { $$ = $1; } 661 | functioncall { $$ = $1; }
662 | NOT expr1 { code_byte(NOTOP); $$ = 0;} 662 | NOT expr1 { code_byte(NOTOP); $$ = 0;}
663 | expr1 AND PrepJump {code_byte(POP); } expr1 663 | expr1 AND PrepJump expr1
664 { 664 {
665 code_shortcircuit($3, ONFJMP); 665 code_shortcircuit($3, ONFJMP);
666 $$ = 0; 666 $$ = 0;
667 } 667 }
668 | expr1 OR PrepJump {code_byte(POP); } expr1 668 | expr1 OR PrepJump expr1
669 { 669 {
670 code_shortcircuit($3, ONTJMP); 670 code_shortcircuit($3, ONTJMP);
671 $$ = 0; 671 $$ = 0;
diff --git a/opcode.c b/opcode.c
index a5ade2cf..e569d284 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 4.20 1997/07/30 22:00:50 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 4.21 1997/07/31 19:37:37 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -1384,6 +1384,7 @@ static StkId lua_execute (TFunc *func, StkId base)
1384 Word w; 1384 Word w;
1385 get_word(w,pc); 1385 get_word(w,pc);
1386 if (ttype(top-1) != LUA_T_NIL) pc += w; 1386 if (ttype(top-1) != LUA_T_NIL) pc += w;
1387 else top--;
1387 } 1388 }
1388 break; 1389 break;
1389 1390
@@ -1392,6 +1393,7 @@ static StkId lua_execute (TFunc *func, StkId base)
1392 Word w; 1393 Word w;
1393 get_word(w,pc); 1394 get_word(w,pc);
1394 if (ttype(top-1) == LUA_T_NIL) pc += w; 1395 if (ttype(top-1) == LUA_T_NIL) pc += w;
1396 else top--;
1395 } 1397 }
1396 break; 1398 break;
1397 1399
@@ -1429,8 +1431,6 @@ static StkId lua_execute (TFunc *func, StkId base)
1429 } 1431 }
1430 break; 1432 break;
1431 1433
1432 case POP: --top; break;
1433
1434 case CALLFUNC: 1434 case CALLFUNC:
1435 { 1435 {
1436 int nParams = *(pc++); 1436 int nParams = *(pc++);
diff --git a/opcode.h b/opcode.h
index 386cec36..406ff971 100644
--- a/opcode.h
+++ b/opcode.h
@@ -1,6 +1,6 @@
1/* 1/*
2** TeCGraf - PUC-Rio 2** TeCGraf - PUC-Rio
3** $Id: opcode.h,v 3.36 1997/07/29 20:38:06 roberto Exp roberto $ 3** $Id: opcode.h,v 3.37 1997/07/30 22:00:50 roberto Exp roberto $
4*/ 4*/
5 5
6#ifndef opcode_h 6#ifndef opcode_h
@@ -60,7 +60,7 @@ PUSHLOCAL9,/* - LOC[9] */
60PUSHLOCAL,/* b - LOC[b] */ 60PUSHLOCAL,/* b - LOC[b] */
61PUSHGLOBAL,/* w - VAR[w] */ 61PUSHGLOBAL,/* w - VAR[w] */
62PUSHINDEXED,/* i t t[i] */ 62PUSHINDEXED,/* i t t[i] */
63PUSHSELF,/* w t t t[STR[w]] */ 63PUSHSELF,/* w t t t[CNST[w]] */
64STORELOCAL0,/* x - LOC[0]=x */ 64STORELOCAL0,/* x - LOC[0]=x */
65STORELOCAL1,/* x - LOC[1]=x */ 65STORELOCAL1,/* x - LOC[1]=x */
66STORELOCAL2,/* x - LOC[2]=x */ 66STORELOCAL2,/* 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 */
78STORELIST0,/* b v_b...v_1 t - t[i]=v_i */ 78STORELIST0,/* b v_b...v_1 t - t[i]=v_i */
79STORELIST,/* b c v_b...v_1 t - t[i+c*FPF]=v_i */ 79STORELIST,/* b c v_b...v_1 t - t[i+c*FPF]=v_i */
80STORERECORD,/* b 80STORERECORD,/* b
81 w_b...w_1 v_b...v_1 t - t[STR[w_i]]=v_i */ 81 w_b...w_1 v_b...v_1 t - t[CNST[w_i]]=v_i */
82ADJUST0,/* - - TOP=BASE */ 82ADJUST0,/* - - TOP=BASE */
83ADJUST,/* b - - TOP=BASE+b */ 83ADJUST,/* b - - TOP=BASE+b */
84CREATEARRAY,/* w - newarray(size = w) */ 84CREATEARRAY,/* w - newarray(size = w) */
@@ -95,21 +95,20 @@ POWOP,/* y x x^y */
95CONCOP,/* y x x..y */ 95CONCOP,/* y x x..y */
96MINUSOP,/* x -x */ 96MINUSOP,/* x -x */
97NOTOP,/* x (x==nil)? 1 : nil */ 97NOTOP,/* x (x==nil)? 1 : nil */
98ONTJMP,/* w x - (x!=nil)? PC+=w */ 98ONTJMP,/* w x (x!=nil)? x : - (x!=nil)? PC+=w */
99ONFJMP,/* w x - (x==nil)? PC+=w */ 99ONFJMP,/* w x (x==nil)? x : - (x==nil)? PC+=w */
100JMP,/* w - - PC+=w */ 100JMP,/* w - - PC+=w */
101UPJMP,/* w - - PC-=w */ 101UPJMP,/* w - - PC-=w */
102IFFJMP,/* w x - (x==nil)? PC+=w */ 102IFFJMP,/* w x - (x==nil)? PC+=w */
103IFFUPJMP,/* w x - (x==nil)? PC-=w */ 103IFFUPJMP,/* w x - (x==nil)? PC-=w */
104POP,/* x - */
105CALLFUNC,/* b c v_b...v_1 f r_c...r_1 f(v1,...,v_b) */ 104CALLFUNC,/* b c v_b...v_1 f r_c...r_1 f(v1,...,v_b) */
106RETCODE0, 105RETCODE0,
107RETCODE,/* b - - */ 106RETCODE,/* b - - */
108SETLINE,/* w - - LINE=w */ 107SETLINE,/* w - - LINE=w */
109VARARGS,/* b v_b...v_1 {v_1...v_b;n=b} */ 108VARARGS,/* b v_b...v_1 {v_1...v_b;n=b} */
110STOREMAP,/* b v_b k_b ...v_1 k_1 t - t[k_i]=v_i */ 109STOREMAP,/* b v_b k_b ...v_1 k_1 t - t[k_i]=v_i */
111PUSHCONSTANTB,/*b - const[b] */ 110PUSHCONSTANTB,/*b - CNST[b] */
112PUSHCONSTANT,/* w - const[w] */ 111PUSHCONSTANT,/* w - CNST[w] */
113ENDCODE = 127 112ENDCODE = 127
114} OpCode; 113} OpCode;
115 114
diff --git a/undump.c b/undump.c
index 0d1ca1a4..80f131de 100644
--- a/undump.c
+++ b/undump.c
@@ -3,7 +3,7 @@
3** load bytecodes from files 3** load bytecodes from files
4*/ 4*/
5 5
6char* rcs_undump="$Id: undump.c,v 1.24 1997/06/17 18:19:17 roberto Exp roberto $"; 6char* rcs_undump="$Id: undump.c,v 1.25 1997/07/29 19:44:02 roberto Exp roberto $";
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
@@ -67,7 +67,6 @@ static void FixCode(Byte* code, Byte* end) /* swap words */
67 case CONCOP: 67 case CONCOP:
68 case MINUSOP: 68 case MINUSOP:
69 case NOTOP: 69 case NOTOP:
70 case POP:
71 case RETCODE0: 70 case RETCODE0:
72 p++; 71 p++;
73 break; 72 break;
@@ -86,9 +85,6 @@ static void FixCode(Byte* code, Byte* end) /* swap words */
86 case CALLFUNC: 85 case CALLFUNC:
87 p+=3; 86 p+=3;
88 break; 87 break;
89 case PUSHFUNCTION:
90 p+=5; /* TODO: use sizeof(TFunc*) or old? */
91 break;
92 case PUSHWORD: 88 case PUSHWORD:
93 case PUSHSELF: 89 case PUSHSELF:
94 case CREATEARRAY: 90 case CREATEARRAY:
@@ -99,7 +95,6 @@ static void FixCode(Byte* code, Byte* end) /* swap words */
99 case IFFJMP: 95 case IFFJMP:
100 case IFFUPJMP: 96 case IFFUPJMP:
101 case SETLINE: 97 case SETLINE:
102 case PUSHSTRING:
103 case PUSHGLOBAL: 98 case PUSHGLOBAL:
104 case STOREGLOBAL: 99 case STOREGLOBAL:
105 { 100 {
@@ -108,14 +103,6 @@ static void FixCode(Byte* code, Byte* end) /* swap words */
108 p+=3; 103 p+=3;
109 break; 104 break;
110 } 105 }
111 case PUSHFLOAT: /* assumes sizeof(float)==4 */
112 {
113 Byte t;
114 t=p[1]; p[1]=p[4]; p[4]=t;
115 t=p[2]; p[2]=p[3]; p[3]=t;
116 p+=5;
117 break;
118 }
119 case STORERECORD: 106 case STORERECORD:
120 { 107 {
121 int n=*++p; 108 int n=*++p;
@@ -226,7 +213,7 @@ static void LoadFunction(ZIO* Z)
226 { 213 {
227 int i=LoadWord(Z); 214 int i=LoadWord(Z);
228 char* s=LoadString(Z); 215 char* s=LoadString(Z);
229 int v=luaI_findconstantbyname(s); 216 int v; /*=luaI_findconstantbyname(s); ??????? */
230 Unthread(tf->code,i,v); 217 Unthread(tf->code,i,v);
231 } 218 }
232 else 219 else
@@ -324,7 +311,7 @@ int luaI_undump(ZIO* Z)
324 while ((m=luaI_undump1(Z))) 311 while ((m=luaI_undump1(Z)))
325 { 312 {
326 int status=luaI_dorun(m); 313 int status=luaI_dorun(m);
327 luaI_freefunc(m); 314/* luaI_freefunc(m); ???*/
328 if (status!=0) return status; 315 if (status!=0) return status;
329 } 316 }
330 return 0; 317 return 0;