aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-06-28 16:58:57 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-06-28 16:58:57 -0300
commit2a4afb97c8a3f64dccad86fa848855616ea2c254 (patch)
treee343fd15c387e6975b7a680130ee09735666ea2d
parent87a5fae45322dde56306de92d8eb8050506fb9ba (diff)
downloadlua-2a4afb97c8a3f64dccad86fa848855616ea2c254.tar.gz
lua-2a4afb97c8a3f64dccad86fa848855616ea2c254.tar.bz2
lua-2a4afb97c8a3f64dccad86fa848855616ea2c254.zip
new module lopcodes.c for tables describing opcodes
-rw-r--r--ldebug.c51
-rw-r--r--ldebug.h21
-rw-r--r--lopcodes.h29
-rw-r--r--ltests.c47
-rw-r--r--ltests.h4
5 files changed, 35 insertions, 117 deletions
diff --git a/ldebug.c b/ldebug.c
index 473d63f5..3e73d374 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 1.84 2001/06/26 13:20:45 roberto Exp roberto $ 2** $Id: ldebug.c,v 1.85 2001/06/28 14:57:17 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -563,52 +563,3 @@ void luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) {
563 luaO_verror(L, l_s("attempt to compare %.10s with %.10s"), t1, t2); 563 luaO_verror(L, l_s("attempt to compare %.10s with %.10s"), t1, t2);
564} 564}
565 565
566
567
568#define opmode(t,a,b,c,sa,k,m) (((t)<<OpModeT) | \
569 ((b)<<OpModeBreg) | ((c)<<OpModeCreg) | \
570 ((sa)<<OpModesetA) | ((k)<<OpModeK) | (m))
571
572
573const lu_byte luaG_opmodes[] = {
574/* T J B C sA K mode opcode */
575 opmode(0,0,1,0, 1,0,iABC), /* OP_MOVE */
576 opmode(0,0,0,0, 1,1,iABc), /* OP_LOADK */
577 opmode(0,0,0,0, 1,0,iAsBc), /* OP_LOADINT */
578 opmode(0,0,1,0, 1,0,iABC), /* OP_LOADNIL */
579 opmode(0,0,0,0, 1,0,iABc), /* OP_LOADUPVAL */
580 opmode(0,0,0,0, 1,1,iABc), /* OP_GETGLOBAL */
581 opmode(0,0,1,1, 1,0,iABC), /* OP_GETTABLE */
582 opmode(0,0,0,0, 0,1,iABc), /* OP_SETGLOBAL */
583 opmode(0,0,1,1, 0,0,iABC), /* OP_SETTABLE */
584 opmode(0,0,0,0, 1,0,iABc), /* OP_NEWTABLE */
585 opmode(0,0,1,1, 1,0,iABC), /* OP_SELF */
586 opmode(0,0,1,1, 1,0,iABC), /* OP_ADD */
587 opmode(0,0,1,1, 1,0,iABC), /* OP_SUB */
588 opmode(0,0,1,1, 1,0,iABC), /* OP_MUL */
589 opmode(0,0,1,1, 1,0,iABC), /* OP_DIV */
590 opmode(0,0,1,1, 1,0,iABC), /* OP_POW */
591 opmode(0,0,1,0, 1,0,iABC), /* OP_UNM */
592 opmode(0,0,1,0, 1,0,iABC), /* OP_NOT */
593 opmode(0,0,1,1, 1,0,iABC), /* OP_CONCAT */
594 opmode(0,1,0,0, 0,0,iAsBc), /* OP_JMP */
595 opmode(0,1,0,0, 0,0,iAsBc), /* OP_CJMP */
596 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTEQ */
597 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTNE */
598 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTLT */
599 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTLE */
600 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTGT */
601 opmode(1,0,0,1, 0,0,iABC), /* OP_TESTGE */
602 opmode(1,0,1,0, 1,0,iABC), /* OP_TESTT */
603 opmode(1,0,1,0, 1,0,iABC), /* OP_TESTF */
604 opmode(0,0,0,0, 1,0,iAsBc), /* OP_NILJMP */
605 opmode(0,0,0,0, 0,0,iABC), /* OP_CALL */
606 opmode(0,0,0,0, 0,0,iABC), /* OP_RETURN */
607 opmode(0,0,0,0, 0,0,iAsBc), /* OP_FORPREP */
608 opmode(0,0,0,0, 0,0,iAsBc), /* OP_FORLOOP */
609 opmode(0,1,0,0, 0,0,iAsBc), /* OP_TFORPREP */
610 opmode(0,1,0,0, 0,0,iAsBc), /* OP_TFORLOOP */
611 opmode(0,0,0,0, 0,0,iABc), /* OP_SETLIST */
612 opmode(0,0,0,0, 0,0,iABc), /* OP_SETLIST0 */
613 opmode(0,0,0,0, 0,0,iABc) /* OP_CLOSURE */
614};
diff --git a/ldebug.h b/ldebug.h
index 678ef1ce..b1320301 100644
--- a/ldebug.h
+++ b/ldebug.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.h,v 1.13 2001/06/06 17:50:36 roberto Exp roberto $ 2** $Id: ldebug.h,v 1.14 2001/06/11 14:56:42 roberto Exp roberto $
3** Auxiliary functions from Debug Interface module 3** Auxiliary functions from Debug Interface module
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -12,25 +12,6 @@
12#include "luadebug.h" 12#include "luadebug.h"
13 13
14 14
15enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */
16
17/*
18** masks for instruction properties
19*/
20enum OpModeMask {
21 OpModeBreg = 2, /* B is a register */
22 OpModeCreg, /* C is a register/constant */
23 OpModesetA, /* instruction set register A */
24 OpModeK, /* Bc is a constant */
25 OpModeT /* operator is a test */
26};
27
28extern const lu_byte luaG_opmodes[];
29
30#define getOpMode(m) ((enum OpMode)(luaG_opmodes[m] & 3))
31#define testOpMode(m, b) (luaG_opmodes[m] & (1 << (b)))
32
33
34void luaG_typeerror (lua_State *L, StkId o, const l_char *op); 15void luaG_typeerror (lua_State *L, StkId o, const l_char *op);
35void luaG_concaterror (lua_State *L, StkId p1, StkId p2); 16void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
36void luaG_aritherror (lua_State *L, StkId p1, TObject *p2); 17void luaG_aritherror (lua_State *L, StkId p1, TObject *p2);
diff --git a/lopcodes.h b/lopcodes.h
index 45674257..b0881213 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.74 2001/06/08 19:00:57 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.75 2001/06/11 14:56:42 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*/
@@ -28,6 +28,9 @@
28===========================================================================*/ 28===========================================================================*/
29 29
30 30
31enum OpMode {iABC, iABc, iAsBc}; /* basic instruction format */
32
33
31/* 34/*
32** size and position of opcode arguments. 35** size and position of opcode arguments.
33*/ 36*/
@@ -198,4 +201,28 @@ OP_CLOSURE /* A Bc R(A) := closure(KPROTO[Bc], R(A), ... ,R(A+n)) */
198===========================================================================*/ 201===========================================================================*/
199 202
200 203
204
205/*
206** masks for instruction properties
207*/
208enum OpModeMask {
209 OpModeBreg = 2, /* B is a register */
210 OpModeCreg, /* C is a register/constant */
211 OpModesetA, /* instruction set register A */
212 OpModeK, /* Bc is a constant */
213 OpModeT /* operator is a test */
214};
215
216extern const lu_byte luaP_opmodes[];
217
218#define getOpMode(m) ((enum OpMode)(luaP_opmodes[m] & 3))
219#define testOpMode(m, b) (luaP_opmodes[m] & (1 << (b)))
220
221
222/*
223** opcode names (only included when compiled with LUA_OPNAMES)
224*/
225extern const l_char *const luaP_opnames[];
226
227
201#endif 228#endif
diff --git a/ltests.c b/ltests.c
index 580caf85..8e7c2930 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.84 2001/06/26 13:20:45 roberto Exp roberto $ 2** $Id: ltests.c,v 1.85 2001/06/28 15:06:20 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -139,53 +139,10 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
139*/ 139*/
140 140
141 141
142static const l_char *const instrname[NUM_OPCODES] = {
143 l_s("OP_MOVE"),
144 l_s("OP_LOADK"),
145 l_s("OP_LOADINT"),
146 l_s("OP_LOADNIL"),
147 l_s("OP_LOADUPVAL"),
148 l_s("OP_GETGLOBAL"),
149 l_s("OP_GETTABLE"),
150 l_s("OP_SETGLOBAL"),
151 l_s("OP_SETTABLE"),
152 l_s("OP_NEWTABLE"),
153 l_s("OP_SELF"),
154 l_s("OP_ADD"),
155 l_s("OP_SUB"),
156 l_s("OP_MUL"),
157 l_s("OP_DIV"),
158 l_s("OP_POW"),
159 l_s("OP_UNM"),
160 l_s("OP_NOT"),
161 l_s("OP_CONCAT"),
162 l_s("OP_JMP"),
163 l_s("OP_CJMP"),
164 l_s("OP_TESTEQ"),
165 l_s("OP_TESTNE"),
166 l_s("OP_TESTLT"),
167 l_s("OP_TESTLE"),
168 l_s("OP_TESTGT"),
169 l_s("OP_TESTGE"),
170 l_s("OP_TESTT"),
171 l_s("OP_TESTF"),
172 l_s("OP_NILJMP"),
173 l_s("OP_CALL"),
174 l_s("OP_RETURN"),
175 l_s("OP_FORPREP"),
176 l_s("OP_FORLOOP"),
177 l_s("OP_LFORPREP"),
178 l_s("OP_LFORLOOP"),
179 l_s("OP_SETLIST"),
180 l_s("OP_SETLIST0"),
181 l_s("OP_CLOSURE")
182};
183
184
185static l_char *buildop (Proto *p, int pc, l_char *buff) { 142static l_char *buildop (Proto *p, int pc, l_char *buff) {
186 Instruction i = p->code[pc]; 143 Instruction i = p->code[pc];
187 OpCode o = GET_OPCODE(i); 144 OpCode o = GET_OPCODE(i);
188 const l_char *name = instrname[o]; 145 const l_char *name = luaP_opnames[o];
189 sprintf(buff, l_s("%4d - "), pc); 146 sprintf(buff, l_s("%4d - "), pc);
190 switch (getOpMode(o)) { 147 switch (getOpMode(o)) {
191 case iABC: 148 case iABC:
diff --git a/ltests.h b/ltests.h
index 6cbb9810..3fc03cc1 100644
--- a/ltests.h
+++ b/ltests.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.h,v 1.5 2001/02/12 15:42:44 roberto Exp roberto $ 2** $Id: ltests.h,v 1.6 2001/03/02 17:27:50 roberto Exp roberto $
3** Internal Header for Debugging of the Lua Implementation 3** Internal Header for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -13,6 +13,8 @@
13 13
14#define LUA_DEBUG 14#define LUA_DEBUG
15 15
16#define LUA_OPNAMES
17
16#undef NDEBUG 18#undef NDEBUG
17#include <assert.h> 19#include <assert.h>
18#define lua_assert(c) assert(c) 20#define lua_assert(c) assert(c)