diff options
-rw-r--r-- | ltests.c | 59 |
1 files changed, 40 insertions, 19 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 1.26 2000/06/21 17:05:49 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 1.27 2000/06/26 19:28:31 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 | */ |
@@ -17,6 +17,7 @@ | |||
17 | #include "lauxlib.h" | 17 | #include "lauxlib.h" |
18 | #include "lcode.h" | 18 | #include "lcode.h" |
19 | #include "ldo.h" | 19 | #include "ldo.h" |
20 | #include "lfunc.h" | ||
20 | #include "lmem.h" | 21 | #include "lmem.h" |
21 | #include "lopcodes.h" | 22 | #include "lopcodes.h" |
22 | #include "lstate.h" | 23 | #include "lstate.h" |
@@ -62,22 +63,28 @@ static const char *const instrname[NUM_OPCODES] = { | |||
62 | }; | 63 | }; |
63 | 64 | ||
64 | 65 | ||
65 | static int pushop (Instruction i) { | 66 | static int pushop (Proto *p, int pc) { |
66 | char buff[100]; | 67 | char buff[100]; |
68 | Instruction i = p->code[pc]; | ||
67 | OpCode o = GET_OPCODE(i); | 69 | OpCode o = GET_OPCODE(i); |
68 | const char *name = instrname[o]; | 70 | const char *name = instrname[o]; |
71 | int *line = p->lines; | ||
72 | if (line) | ||
73 | sprintf(buff, "%5d - ", line[pc]); | ||
74 | else | ||
75 | strcpy(buff, " "); | ||
69 | switch ((enum Mode)luaK_opproperties[o].mode) { | 76 | switch ((enum Mode)luaK_opproperties[o].mode) { |
70 | case iO: | 77 | case iO: |
71 | sprintf(buff, "%s", name); | 78 | sprintf(buff+8, "%s", name); |
72 | break; | 79 | break; |
73 | case iU: | 80 | case iU: |
74 | sprintf(buff, "%-12s%4u", name, GETARG_U(i)); | 81 | sprintf(buff+8, "%-12s%4u", name, GETARG_U(i)); |
75 | break; | 82 | break; |
76 | case iS: | 83 | case iS: |
77 | sprintf(buff, "%-12s%4d", name, GETARG_S(i)); | 84 | sprintf(buff+8, "%-12s%4d", name, GETARG_S(i)); |
78 | break; | 85 | break; |
79 | case iAB: | 86 | case iAB: |
80 | sprintf(buff, "%-12s%4d %4d", name, GETARG_A(i), GETARG_B(i)); | 87 | sprintf(buff+8, "%-12s%4d %4d", name, GETARG_A(i), GETARG_B(i)); |
81 | break; | 88 | break; |
82 | } | 89 | } |
83 | lua_pushstring(buff); | 90 | lua_pushstring(buff); |
@@ -88,18 +95,18 @@ static int pushop (Instruction i) { | |||
88 | static void listcode (void) { | 95 | static void listcode (void) { |
89 | lua_Object o = luaL_nonnullarg(1); | 96 | lua_Object o = luaL_nonnullarg(1); |
90 | lua_Object t = lua_createtable(); | 97 | lua_Object t = lua_createtable(); |
91 | Instruction *pc; | 98 | int pc; |
92 | Proto *p; | 99 | Proto *p; |
93 | int res; | 100 | int res; |
94 | luaL_arg_check(ttype(o) == TAG_LCLOSURE, 1, "Lua function expected"); | 101 | luaL_arg_check(ttype(o) == TAG_LCLOSURE, 1, "Lua function expected"); |
95 | p = clvalue(o)->f.l; | 102 | p = clvalue(o)->f.l; |
96 | setnameval(t, "maxstack", p->maxstacksize); | 103 | setnameval(t, "maxstack", p->maxstacksize); |
97 | setnameval(t, "numparams", p->numparams); | 104 | setnameval(t, "numparams", p->numparams); |
98 | pc = p->code; | 105 | pc = 0; |
99 | do { | 106 | do { |
100 | lua_pushobject(t); | 107 | lua_pushobject(t); |
101 | lua_pushnumber(pc - p->code + 1); | 108 | lua_pushnumber(pc+1); |
102 | res = pushop(*pc++); | 109 | res = pushop(p, pc++); |
103 | lua_settable(); | 110 | lua_settable(); |
104 | } while (res); | 111 | } while (res); |
105 | lua_pushobject(t); | 112 | lua_pushobject(t); |
@@ -123,27 +130,40 @@ static void liststrings (void) { | |||
123 | } | 130 | } |
124 | 131 | ||
125 | 132 | ||
133 | static void listlocals (void) { | ||
134 | lua_Object o = luaL_nonnullarg(1); | ||
135 | Proto *p; | ||
136 | int pc = luaL_check_int(2) - 1; | ||
137 | int i = 1; | ||
138 | const char *name; | ||
139 | luaL_arg_check(ttype(o) == TAG_LCLOSURE, 1, "Lua function expected"); | ||
140 | p = clvalue(o)->f.l; | ||
141 | while ((name = luaF_getlocalname(p, i++, pc)) != NULL) | ||
142 | lua_pushstring(name); | ||
143 | } | ||
144 | |||
126 | /* }====================================================== */ | 145 | /* }====================================================== */ |
127 | 146 | ||
128 | 147 | ||
129 | 148 | ||
130 | static void get_limits (void) { | 149 | static void get_limits (void) { |
131 | lua_Object t = lua_createtable(); | 150 | lua_Object t = lua_createtable(); |
132 | setnameval(t, "SIZE_OP", SIZE_OP); | 151 | setnameval(t, "BITS_INT", BITS_INT); |
133 | setnameval(t, "SIZE_U", SIZE_U); | 152 | setnameval(t, "LFPF", LFIELDS_PER_FLUSH); |
134 | setnameval(t, "SIZE_A", SIZE_A); | ||
135 | setnameval(t, "SIZE_B", SIZE_B); | ||
136 | setnameval(t, "MAXARG_U", MAXARG_U); | ||
137 | setnameval(t, "MAXARG_S", MAXARG_S); | ||
138 | setnameval(t, "MAXARG_A", MAXARG_A); | 153 | setnameval(t, "MAXARG_A", MAXARG_A); |
139 | setnameval(t, "MAXARG_B", MAXARG_B); | 154 | setnameval(t, "MAXARG_B", MAXARG_B); |
140 | setnameval(t, "MAXSTACK", MAXSTACK); | 155 | setnameval(t, "MAXARG_S", MAXARG_S); |
156 | setnameval(t, "MAXARG_U", MAXARG_U); | ||
141 | setnameval(t, "MAXLOCALS", MAXLOCALS); | 157 | setnameval(t, "MAXLOCALS", MAXLOCALS); |
158 | setnameval(t, "MAXPARAMS", MAXPARAMS); | ||
159 | setnameval(t, "MAXSTACK", MAXSTACK); | ||
142 | setnameval(t, "MAXUPVALUES", MAXUPVALUES); | 160 | setnameval(t, "MAXUPVALUES", MAXUPVALUES); |
143 | setnameval(t, "MAXVARSLH", MAXVARSLH); | 161 | setnameval(t, "MAXVARSLH", MAXVARSLH); |
144 | setnameval(t, "MAXPARAMS", MAXPARAMS); | ||
145 | setnameval(t, "LFPF", LFIELDS_PER_FLUSH); | ||
146 | setnameval(t, "RFPF", RFIELDS_PER_FLUSH); | 162 | setnameval(t, "RFPF", RFIELDS_PER_FLUSH); |
163 | setnameval(t, "SIZE_A", SIZE_A); | ||
164 | setnameval(t, "SIZE_B", SIZE_B); | ||
165 | setnameval(t, "SIZE_OP", SIZE_OP); | ||
166 | setnameval(t, "SIZE_U", SIZE_U); | ||
147 | lua_pushobject(t); | 167 | lua_pushobject(t); |
148 | } | 168 | } |
149 | 169 | ||
@@ -397,6 +417,7 @@ static const struct luaL_reg tests_funcs[] = { | |||
397 | {"limits", (lua_CFunction)get_limits}, | 417 | {"limits", (lua_CFunction)get_limits}, |
398 | {"listcode", (lua_CFunction)listcode}, | 418 | {"listcode", (lua_CFunction)listcode}, |
399 | {"liststrings", (lua_CFunction)liststrings}, | 419 | {"liststrings", (lua_CFunction)liststrings}, |
420 | {"listlocals", (lua_CFunction)listlocals}, | ||
400 | {"querystr", (lua_CFunction)string_query}, | 421 | {"querystr", (lua_CFunction)string_query}, |
401 | {"querytab", (lua_CFunction)table_query}, | 422 | {"querytab", (lua_CFunction)table_query}, |
402 | {"testC", (lua_CFunction)testC}, | 423 | {"testC", (lua_CFunction)testC}, |