aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c133
1 files changed, 56 insertions, 77 deletions
diff --git a/ltests.c b/ltests.c
index 77fc6048..95d7813d 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 1.79 2001/04/17 17:35:54 roberto Exp roberto $ 2** $Id: ltests.c,v 1.80 2001/04/23 16:35:45 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*/
@@ -140,77 +140,65 @@ void *debug_realloc (void *block, size_t oldsize, size_t size) {
140 140
141 141
142static const l_char *const instrname[NUM_OPCODES] = { 142static const l_char *const instrname[NUM_OPCODES] = {
143 l_s("RETURN"), 143 l_s("OP_MOVE"),
144 l_s("CALL"), 144 l_s("OP_LOADK"),
145 l_s("PUSHNIL"), 145 l_s("OP_LOADINT"),
146 l_s("POP"), 146 l_s("OP_LOADNIL"),
147 l_s("PUSHINT"), 147 l_s("OP_LOADUPVAL"),
148 l_s("PUSHSTRING"), 148 l_s("OP_GETGLOBAL"),
149 l_s("PUSHNUM"), 149 l_s("OP_GETTABLE"),
150 l_s("PUSHNEGNUM"), 150 l_s("OP_SETGLOBAL"),
151 l_s("PUSHUPVALUE"), 151 l_s("OP_SETTABLE"),
152 l_s("GETLOCAL"), 152 l_s("OP_NEWTABLE"),
153 l_s("GETGLOBAL"), 153 l_s("OP_SELF"),
154 l_s("GETTABLE"), 154 l_s("OP_ADD"),
155 l_s("GETDOTTED"), 155 l_s("OP_SUB"),
156 l_s("GETINDEXED"), 156 l_s("OP_MUL"),
157 l_s("PUSHSELF"), 157 l_s("OP_DIV"),
158 l_s("CREATETABLE"), 158 l_s("OP_POW"),
159 l_s("SETLOCAL"), 159 l_s("OP_UNM"),
160 l_s("SETGLOBAL"), 160 l_s("OP_NOT"),
161 l_s("SETTABLE"), 161 l_s("OP_CONCAT"),
162 l_s("SETLIST"), 162 l_s("OP_JMP"),
163 l_s("SETMAP"), 163 l_s("OP_CJMP"),
164 l_s("ADD"), 164 l_s("OP_TESTEQ"),
165 l_s("ADDI"), 165 l_s("OP_TESTNE"),
166 l_s("SUB"), 166 l_s("OP_TESTLT"),
167 l_s("MULT"), 167 l_s("OP_TESTLE"),
168 l_s("DIV"), 168 l_s("OP_TESTGT"),
169 l_s("POW"), 169 l_s("OP_TESTGE"),
170 l_s("CONCAT"), 170 l_s("OP_TESTT"),
171 l_s("MINUS"), 171 l_s("OP_TESTF"),
172 l_s("NOT"), 172 l_s("OP_NILJMP"),
173 l_s("JMPNE"), 173 l_s("OP_CALL"),
174 l_s("JMPEQ"), 174 l_s("OP_RETURN"),
175 l_s("JMPLT"), 175 l_s("OP_FORPREP"),
176 l_s("JMPLE"), 176 l_s("OP_FORLOOP"),
177 l_s("JMPGT"), 177 l_s("OP_LFORPREP"),
178 l_s("JMPGE"), 178 l_s("OP_LFORLOOP"),
179 l_s("JMPT"), 179 l_s("OP_SETLIST"),
180 l_s("JMPF"), 180 l_s("OP_CLOSURE")
181 l_s("JMPONT"),
182 l_s("JMPONF"),
183 l_s("JMP"),
184 l_s("PUSHNILJMP"),
185 l_s("FORPREP"),
186 l_s("FORLOOP"),
187 l_s("LFORPREP"),
188 l_s("LFORLOOP"),
189 l_s("CLOSURE")
190}; 181};
191 182
192 183
193static void pushop (lua_State *L, Proto *p, int pc) { 184static l_char *buildop (Proto *p, int pc, l_char *buff) {
194 l_char buff[100];
195 Instruction i = p->code[pc]; 185 Instruction i = p->code[pc];
196 OpCode o = GET_OPCODE(i); 186 OpCode o = GET_OPCODE(i);
197 const l_char *name = instrname[o]; 187 const l_char *name = instrname[o];
198 sprintf(buff, l_s("%5d - "), luaG_getline(p->lineinfo, pc, 1, NULL)); 188 sprintf(buff, l_s("%4d - "), pc);
199 switch ((enum Mode)luaK_opproperties[o].mode) { 189 switch (getOpMode(o)) {
200 case iO: 190 case iABC:
201 sprintf(buff+8, l_s("%-12s"), name); 191 sprintf(buff+strlen(buff), l_s("%-12s%4d %4d %4d"), name,
192 GETARG_A(i), GETARG_B(i), GETARG_C(i));
202 break; 193 break;
203 case iU: 194 case iABc:
204 sprintf(buff+8, l_s("%-12s%4u"), name, GETARG_U(i)); 195 sprintf(buff+strlen(buff), l_s("%-12s%4d %4d"), name, GETARG_A(i), GETARG_Bc(i));
205 break; 196 break;
206 case iS: 197 case iAsBc:
207 sprintf(buff+8, l_s("%-12s%4d"), name, GETARG_S(i)); 198 sprintf(buff+strlen(buff), l_s("%-12s%4d %4d"), name, GETARG_A(i), GETARG_sBc(i));
208 break;
209 case iAB:
210 sprintf(buff+8, l_s("%-12s%4d %4d"), name, GETARG_A(i), GETARG_B(i));
211 break; 199 break;
212 } 200 }
213 lua_pushstring(L, buff); 201 return buff;
214} 202}
215 203
216 204
@@ -224,24 +212,25 @@ static int listcode (lua_State *L) {
224 setnameval(L, l_s("maxstack"), p->maxstacksize); 212 setnameval(L, l_s("maxstack"), p->maxstacksize);
225 setnameval(L, l_s("numparams"), p->numparams); 213 setnameval(L, l_s("numparams"), p->numparams);
226 for (pc=0; pc<p->sizecode; pc++) { 214 for (pc=0; pc<p->sizecode; pc++) {
215 l_char buff[100];
227 lua_pushnumber(L, pc+1); 216 lua_pushnumber(L, pc+1);
228 pushop(L, p, pc); 217 lua_pushstring(L, buildop(p, pc, buff));
229 lua_settable(L, -3); 218 lua_settable(L, -3);
230 } 219 }
231 return 1; 220 return 1;
232} 221}
233 222
234 223
235static int liststrings (lua_State *L) { 224static int listk (lua_State *L) {
236 Proto *p; 225 Proto *p;
237 int i; 226 int i;
238 luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1), 227 luaL_arg_check(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
239 1, l_s("Lua function expected")); 228 1, l_s("Lua function expected"));
240 p = clvalue(luaA_index(L, 1))->f.l; 229 p = clvalue(luaA_index(L, 1))->f.l;
241 lua_newtable(L); 230 lua_newtable(L);
242 for (i=0; i<p->sizekstr; i++) { 231 for (i=0; i<p->sizek; i++) {
243 lua_pushnumber(L, i+1); 232 lua_pushnumber(L, i+1);
244 lua_pushstring(L, getstr(p->kstr[i])); 233 luaA_pushobject(L, p->k+i);
245 lua_settable(L, -3); 234 lua_settable(L, -3);
246 } 235 }
247 return 1; 236 return 1;
@@ -276,20 +265,10 @@ static int get_limits (lua_State *L) {
276 lua_newtable(L); 265 lua_newtable(L);
277 setnameval(L, l_s("BITS_INT"), BITS_INT); 266 setnameval(L, l_s("BITS_INT"), BITS_INT);
278 setnameval(L, l_s("LFPF"), LFIELDS_PER_FLUSH); 267 setnameval(L, l_s("LFPF"), LFIELDS_PER_FLUSH);
279 setnameval(L, l_s("MAXARG_A"), MAXARG_A);
280 setnameval(L, l_s("MAXARG_B"), MAXARG_B);
281 setnameval(L, l_s("MAXARG_S"), MAXARG_S);
282 setnameval(L, l_s("MAXARG_U"), MAXARG_U);
283 setnameval(L, l_s("MAXLOCALS"), MAXLOCALS); 268 setnameval(L, l_s("MAXLOCALS"), MAXLOCALS);
284 setnameval(L, l_s("MAXPARAMS"), MAXPARAMS); 269 setnameval(L, l_s("MAXPARAMS"), MAXPARAMS);
285 setnameval(L, l_s("MAXSTACK"), MAXSTACK); 270 setnameval(L, l_s("MAXSTACK"), MAXSTACK);
286 setnameval(L, l_s("MAXUPVALUES"), MAXUPVALUES); 271 setnameval(L, l_s("MAXUPVALUES"), MAXUPVALUES);
287 setnameval(L, l_s("MAXVARSLH"), MAXVARSLH);
288 setnameval(L, l_s("RFPF"), RFIELDS_PER_FLUSH);
289 setnameval(L, l_s("SIZE_A"), SIZE_A);
290 setnameval(L, l_s("SIZE_B"), SIZE_B);
291 setnameval(L, l_s("SIZE_OP"), SIZE_OP);
292 setnameval(L, l_s("SIZE_U"), SIZE_U);
293 return 1; 272 return 1;
294} 273}
295 274
@@ -700,7 +679,7 @@ static const struct luaL_reg tests_funcs[] = {
700 {l_s("hash"), hash_query}, 679 {l_s("hash"), hash_query},
701 {l_s("limits"), get_limits}, 680 {l_s("limits"), get_limits},
702 {l_s("listcode"), listcode}, 681 {l_s("listcode"), listcode},
703 {l_s("liststrings"), liststrings}, 682 {l_s("listk"), listk},
704 {l_s("listlocals"), listlocals}, 683 {l_s("listlocals"), listlocals},
705 {l_s("loadlib"), loadlib}, 684 {l_s("loadlib"), loadlib},
706 {l_s("querystr"), string_query}, 685 {l_s("querystr"), string_query},