aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c390
1 files changed, 198 insertions, 192 deletions
diff --git a/ltests.c b/ltests.c
index 65e2ad26..a0bd3b9e 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.166 2014/02/18 13:46:26 roberto Exp roberto $ 2** $Id: ltests.c,v 2.167 2014/02/19 13:51:09 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*/
@@ -1000,153 +1000,152 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
1000 else if EQ("absindex") { 1000 else if EQ("absindex") {
1001 lua_pushnumber(L1, lua_absindex(L1, getindex)); 1001 lua_pushnumber(L1, lua_absindex(L1, getindex));
1002 } 1002 }
1003 else if EQ("isnumber") { 1003 else if EQ("append") {
1004 lua_pushboolean(L1, lua_isnumber(L1, getindex)); 1004 int t = getindex;
1005 } 1005 int i = lua_rawlen(L1, t);
1006 else if EQ("isstring") { 1006 lua_rawseti(L1, t, i + 1);
1007 lua_pushboolean(L1, lua_isstring(L1, getindex));
1008 }
1009 else if EQ("istable") {
1010 lua_pushboolean(L1, lua_istable(L1, getindex));
1011 }
1012 else if EQ("iscfunction") {
1013 lua_pushboolean(L1, lua_iscfunction(L1, getindex));
1014 }
1015 else if EQ("isfunction") {
1016 lua_pushboolean(L1, lua_isfunction(L1, getindex));
1017 }
1018 else if EQ("isuserdata") {
1019 lua_pushboolean(L1, lua_isuserdata(L1, getindex));
1020 }
1021 else if EQ("isudataval") {
1022 lua_pushboolean(L1, lua_islightuserdata(L1, getindex));
1023 }
1024 else if EQ("isnil") {
1025 lua_pushboolean(L1, lua_isnil(L1, getindex));
1026 }
1027 else if EQ("isnull") {
1028 lua_pushboolean(L1, lua_isnone(L1, getindex));
1029 } 1007 }
1030 else if EQ("tonumber") { 1008 else if EQ("arith") {
1031 lua_pushnumber(L1, lua_tonumber(L1, getindex)); 1009 int op;
1010 skip(&pc);
1011 op = strchr(ops, *pc++) - ops;
1012 lua_arith(L1, op);
1032 } 1013 }
1033 else if EQ("topointer") { 1014 else if EQ("call") {
1034 lua_pushnumber(L1, cast(size_t, lua_topointer(L1, getindex))); 1015 int narg = getnum;
1016 int nres = getnum;
1017 lua_call(L1, narg, nres);
1035 } 1018 }
1036 else if EQ("tostring") { 1019 else if EQ("callk") {
1037 const char *s = lua_tostring(L1, getindex); 1020 int narg = getnum;
1038 const char *s1 = lua_pushstring(L1, s); 1021 int nres = getnum;
1039 lua_assert((s == NULL && s1 == NULL) || (strcmp)(s, s1) == 0); 1022 int i = getindex;
1023 lua_callk(L1, narg, nres, i, Cfunck);
1040 } 1024 }
1041 else if EQ("objsize") { 1025 else if EQ("checkstack") {
1042 lua_pushinteger(L1, lua_rawlen(L1, getindex)); 1026 int sz = getnum;
1027 luaL_checkstack(L1, sz, getstring);
1043 } 1028 }
1044 else if EQ("len") { 1029 else if EQ("compare") {
1045 lua_len(L1, getindex); 1030 int a = getindex;
1031 int b = getindex;
1032 lua_pushboolean(L1, lua_compare(L1, a, b, getnum));
1046 } 1033 }
1047 else if EQ("Llen") { 1034 else if EQ("concat") {
1048 lua_pushinteger(L1, luaL_len(L1, getindex)); 1035 lua_concat(L1, getnum);
1049 } 1036 }
1050 else if EQ("tocfunction") { 1037 else if EQ("copy") {
1051 lua_pushcfunction(L1, lua_tocfunction(L1, getindex)); 1038 int f = getindex;
1039 lua_copy(L1, f, getindex);
1052 } 1040 }
1053 else if EQ("func2num") { 1041 else if EQ("func2num") {
1054 lua_CFunction func = lua_tocfunction(L1, getindex); 1042 lua_CFunction func = lua_tocfunction(L1, getindex);
1055 lua_pushnumber(L1, cast(size_t, func)); 1043 lua_pushnumber(L1, cast(size_t, func));
1056 } 1044 }
1057 else if EQ("return") { 1045 else if EQ("getctx") {
1058 int n = getnum; 1046 int i = 0;
1059 if (L1 != L) { 1047 int s = lua_getctx(L1, &i);
1060 int i; 1048 pushcode(L1, s);
1061 for (i = 0; i < n; i++) 1049 lua_pushinteger(L1, i);
1062 lua_pushstring(L, lua_tostring(L1, -(n - i)));
1063 }
1064 return n;
1065 }
1066 else if EQ("gettop") {
1067 lua_pushinteger(L1, lua_gettop(L1));
1068 } 1050 }
1069 else if EQ("settop") { 1051 else if EQ("getfield") {
1070 lua_settop(L1, getnum); 1052 int t = getindex;
1053 lua_getfield(L1, t, getstring);
1071 } 1054 }
1072 else if EQ("pop") { 1055 else if EQ("getglobal") {
1073 lua_pop(L1, getnum); 1056 lua_getglobal(L1, getstring);
1074 } 1057 }
1075 else if EQ("pushnum") { 1058 else if EQ("getmetatable") {
1076 lua_pushnumber(L1, (lua_Number)getnum); 1059 if (lua_getmetatable(L1, getindex) == 0)
1060 lua_pushnil(L1);
1077 } 1061 }
1078 else if EQ("pushint") { 1062 else if EQ("gettable") {
1079 lua_pushinteger(L1, getnum); 1063 lua_gettable(L1, getindex);
1080 } 1064 }
1081 else if EQ("pushstring") { 1065 else if EQ("gettop") {
1082 lua_pushstring(L1, getstring); 1066 lua_pushinteger(L1, lua_gettop(L1));
1083 } 1067 }
1084 else if EQ("pushnil") { 1068 else if EQ("gsub") {
1085 lua_pushnil(L1); 1069 int a = getnum; int b = getnum; int c = getnum;
1070 luaL_gsub(L1, lua_tostring(L1, a),
1071 lua_tostring(L1, b),
1072 lua_tostring(L1, c));
1086 } 1073 }
1087 else if EQ("pushbool") { 1074 else if EQ("insert") {
1088 lua_pushboolean(L1, getnum); 1075 lua_insert(L1, getnum);
1089 } 1076 }
1090 else if EQ("newtable") { 1077 else if EQ("iscfunction") {
1091 lua_newtable(L1); 1078 lua_pushboolean(L1, lua_iscfunction(L1, getindex));
1092 } 1079 }
1093 else if EQ("newuserdata") { 1080 else if EQ("isfunction") {
1094 lua_newuserdata(L1, getnum); 1081 lua_pushboolean(L1, lua_isfunction(L1, getindex));
1095 } 1082 }
1096 else if EQ("tobool") { 1083 else if EQ("isnil") {
1097 lua_pushboolean(L1, lua_toboolean(L1, getindex)); 1084 lua_pushboolean(L1, lua_isnil(L1, getindex));
1098 } 1085 }
1099 else if EQ("pushvalue") { 1086 else if EQ("isnull") {
1100 lua_pushvalue(L1, getindex); 1087 lua_pushboolean(L1, lua_isnone(L1, getindex));
1101 } 1088 }
1102 else if EQ("pushcclosure") { 1089 else if EQ("isnumber") {
1103 lua_pushcclosure(L1, testC, getnum); 1090 lua_pushboolean(L1, lua_isnumber(L1, getindex));
1104 } 1091 }
1105 else if EQ("pushupvalueindex") { 1092 else if EQ("isstring") {
1106 lua_pushinteger(L1, lua_upvalueindex(getnum)); 1093 lua_pushboolean(L1, lua_isstring(L1, getindex));
1107 } 1094 }
1108 else if EQ("remove") { 1095 else if EQ("istable") {
1109 lua_remove(L1, getnum); 1096 lua_pushboolean(L1, lua_istable(L1, getindex));
1110 } 1097 }
1111 else if EQ("insert") { 1098 else if EQ("isudataval") {
1112 lua_insert(L1, getnum); 1099 lua_pushboolean(L1, lua_islightuserdata(L1, getindex));
1113 } 1100 }
1114 else if EQ("replace") { 1101 else if EQ("isuserdata") {
1115 lua_replace(L1, getindex); 1102 lua_pushboolean(L1, lua_isuserdata(L1, getindex));
1116 } 1103 }
1117 else if EQ("copy") { 1104 else if EQ("len") {
1118 int f = getindex; 1105 lua_len(L1, getindex);
1119 lua_copy(L1, f, getindex);
1120 } 1106 }
1121 else if EQ("gettable") { 1107 else if EQ("Llen") {
1122 lua_gettable(L1, getindex); 1108 lua_pushinteger(L1, luaL_len(L1, getindex));
1123 } 1109 }
1124 else if EQ("getglobal") { 1110 else if EQ("loadfile") {
1125 lua_getglobal(L1, getstring); 1111 luaL_loadfile(L1, luaL_checkstring(L1, getnum));
1126 } 1112 }
1127 else if EQ("getfield") { 1113 else if EQ("loadstring") {
1128 int t = getindex; 1114 size_t sl;
1129 lua_getfield(L1, t, getstring); 1115 const char *s = luaL_checklstring(L1, getnum, &sl);
1116 luaL_loadbuffer(L1, s, sl, s);
1130 } 1117 }
1131 else if EQ("setfield") { 1118 else if EQ("newmetatable") {
1132 int t = getindex; 1119 lua_pushboolean(L1, luaL_newmetatable(L1, getstring));
1133 lua_setfield(L1, t, getstring);
1134 } 1120 }
1135 else if EQ("rawgeti") { 1121 else if EQ("newtable") {
1136 int t = getindex; 1122 lua_newtable(L1);
1137 lua_rawgeti(L1, t, getnum);
1138 } 1123 }
1139 else if EQ("settable") { 1124 else if EQ("newthread") {
1140 lua_settable(L1, getindex); 1125 lua_newthread(L1);
1141 } 1126 }
1142 else if EQ("setglobal") { 1127 else if EQ("newuserdata") {
1143 lua_setglobal(L1, getstring); 1128 lua_newuserdata(L1, getnum);
1144 } 1129 }
1145 else if EQ("next") { 1130 else if EQ("next") {
1146 lua_next(L1, -2); 1131 lua_next(L1, -2);
1147 } 1132 }
1148 else if EQ("concat") { 1133 else if EQ("objsize") {
1149 lua_concat(L1, getnum); 1134 lua_pushinteger(L1, lua_rawlen(L1, getindex));
1135 }
1136 else if EQ("pcall") {
1137 int narg = getnum;
1138 int nres = getnum;
1139 status = lua_pcall(L1, narg, nres, 0);
1140 }
1141 else if EQ("pcallk") {
1142 int narg = getnum;
1143 int nres = getnum;
1144 int i = getindex;
1145 status = lua_pcallk(L1, narg, nres, 0, i, Cfunck);
1146 }
1147 else if EQ("pop") {
1148 lua_pop(L1, getnum);
1150 } 1149 }
1151 else if EQ("print") { 1150 else if EQ("print") {
1152 int n = getnum; 1151 int n = getnum;
@@ -1164,117 +1163,81 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
1164 printf("\n"); 1163 printf("\n");
1165 } 1164 }
1166 } 1165 }
1167 else if EQ("arith") { 1166 else if EQ("pushbool") {
1168 int op; 1167 lua_pushboolean(L1, getnum);
1169 skip(&pc);
1170 op = strchr(ops, *pc++) - ops;
1171 lua_arith(L1, op);
1172 } 1168 }
1173 else if EQ("compare") { 1169 else if EQ("pushcclosure") {
1174 int a = getindex; 1170 lua_pushcclosure(L1, testC, getnum);
1175 int b = getindex;
1176 lua_pushboolean(L1, lua_compare(L1, a, b, getnum));
1177 } 1171 }
1178 else if EQ("call") { 1172 else if EQ("pushint") {
1179 int narg = getnum; 1173 lua_pushinteger(L1, getnum);
1180 int nres = getnum;
1181 lua_call(L1, narg, nres);
1182 } 1174 }
1183 else if EQ("pcall") { 1175 else if EQ("pushnil") {
1184 int narg = getnum; 1176 lua_pushnil(L1);
1185 int nres = getnum;
1186 status = lua_pcall(L1, narg, nres, 0);
1187 } 1177 }
1188 else if EQ("pcallk") { 1178 else if EQ("pushnum") {
1189 int narg = getnum; 1179 lua_pushnumber(L1, (lua_Number)getnum);
1190 int nres = getnum;
1191 int i = getindex;
1192 status = lua_pcallk(L1, narg, nres, 0, i, Cfunck);
1193 } 1180 }
1194 else if EQ("callk") { 1181 else if EQ("pushstatus") {
1195 int narg = getnum; 1182 pushcode(L1, status);
1196 int nres = getnum;
1197 int i = getindex;
1198 lua_callk(L1, narg, nres, i, Cfunck);
1199 } 1183 }
1200 else if EQ("yield") { 1184 else if EQ("pushstring") {
1201 return lua_yield(L1, getnum); 1185 lua_pushstring(L1, getstring);
1202 } 1186 }
1203 else if EQ("yieldk") { 1187 else if EQ("pushupvalueindex") {
1204 int nres = getnum; 1188 lua_pushinteger(L1, lua_upvalueindex(getnum));
1205 int i = getindex;
1206 return lua_yieldk(L1, nres, i, Cfunck);
1207 } 1189 }
1208 else if EQ("newthread") { 1190 else if EQ("pushvalue") {
1209 lua_newthread(L1); 1191 lua_pushvalue(L1, getindex);
1192 }
1193 else if EQ("rawgeti") {
1194 int t = getindex;
1195 lua_rawgeti(L1, t, getnum);
1196 }
1197 else if EQ("remove") {
1198 lua_remove(L1, getnum);
1199 }
1200 else if EQ("replace") {
1201 lua_replace(L1, getindex);
1210 } 1202 }
1211 else if EQ("resume") { 1203 else if EQ("resume") {
1212 int i = getindex; 1204 int i = getindex;
1213 status = lua_resume(lua_tothread(L1, i), L, getnum); 1205 status = lua_resume(lua_tothread(L1, i), L, getnum);
1214 } 1206 }
1215 else if EQ("pushstatus") { 1207 else if EQ("return") {
1216 pushcode(L1, status); 1208 int n = getnum;
1209 if (L1 != L) {
1210 int i;
1211 for (i = 0; i < n; i++)
1212 lua_pushstring(L, lua_tostring(L1, -(n - i)));
1213 }
1214 return n;
1217 } 1215 }
1218 else if EQ("xmove") { 1216 else if EQ("setfield") {
1219 int f = getindex;
1220 int t = getindex; 1217 int t = getindex;
1221 lua_State *fs = (f == 0) ? L1 : lua_tothread(L1, f); 1218 lua_setfield(L1, t, getstring);
1222 lua_State *ts = (t == 0) ? L1 : lua_tothread(L1, t);
1223 int n = getnum;
1224 if (n == 0) n = lua_gettop(fs);
1225 lua_xmove(fs, ts, n);
1226 } 1219 }
1227 else if EQ("loadstring") { 1220 else if EQ("setglobal") {
1228 size_t sl; 1221 lua_setglobal(L1, getstring);
1229 const char *s = luaL_checklstring(L1, getnum, &sl);
1230 luaL_loadbuffer(L1, s, sl, s);
1231 } 1222 }
1232 else if EQ("loadfile") { 1223 else if EQ("sethook") {
1233 luaL_loadfile(L1, luaL_checkstring(L1, getnum)); 1224 int mask = getnum;
1225 int count = getnum;
1226 sethookaux(L1, mask, count, getstring);
1234 } 1227 }
1235 else if EQ("setmetatable") { 1228 else if EQ("setmetatable") {
1236 lua_setmetatable(L1, getindex); 1229 lua_setmetatable(L1, getindex);
1237 } 1230 }
1238 else if EQ("getmetatable") { 1231 else if EQ("settable") {
1239 if (lua_getmetatable(L1, getindex) == 0) 1232 lua_settable(L1, getindex);
1240 lua_pushnil(L1);
1241 }
1242 else if EQ("type") {
1243 lua_pushstring(L1, luaL_typename(L1, getnum));
1244 }
1245 else if EQ("append") {
1246 int t = getindex;
1247 int i = lua_rawlen(L1, t);
1248 lua_rawseti(L1, t, i + 1);
1249 }
1250 else if EQ("getctx") {
1251 int i = 0;
1252 int s = lua_getctx(L1, &i);
1253 pushcode(L1, s);
1254 lua_pushinteger(L1, i);
1255 }
1256 else if EQ("checkstack") {
1257 int sz = getnum;
1258 luaL_checkstack(L1, sz, getstring);
1259 } 1233 }
1260 else if EQ("newmetatable") { 1234 else if EQ("settop") {
1261 lua_pushboolean(L1, luaL_newmetatable(L1, getstring)); 1235 lua_settop(L1, getnum);
1262 } 1236 }
1263 else if EQ("testudata") { 1237 else if EQ("testudata") {
1264 int i = getindex; 1238 int i = getindex;
1265 lua_pushboolean(L1, luaL_testudata(L1, i, getstring) != NULL); 1239 lua_pushboolean(L1, luaL_testudata(L1, i, getstring) != NULL);
1266 } 1240 }
1267 else if EQ("gsub") {
1268 int a = getnum; int b = getnum; int c = getnum;
1269 luaL_gsub(L1, lua_tostring(L1, a),
1270 lua_tostring(L1, b),
1271 lua_tostring(L1, c));
1272 }
1273 else if EQ("sethook") {
1274 int mask = getnum;
1275 int count = getnum;
1276 sethookaux(L1, mask, count, getstring);
1277 }
1278 else if EQ("throw") { 1241 else if EQ("throw") {
1279#if defined(__cplusplus) 1242#if defined(__cplusplus)
1280static struct X { int x; } x; 1243static struct X { int x; } x;
@@ -1284,6 +1247,49 @@ static struct X { int x; } x;
1284#endif 1247#endif
1285 break; 1248 break;
1286 } 1249 }
1250 else if EQ("tobool") {
1251 lua_pushboolean(L1, lua_toboolean(L1, getindex));
1252 }
1253 else if EQ("tocfunction") {
1254 lua_pushcfunction(L1, lua_tocfunction(L1, getindex));
1255 }
1256 else if EQ("tointeger") {
1257 lua_pushinteger(L1, lua_tointeger(L1, getindex));
1258 }
1259 else if EQ("tonumber") {
1260 lua_pushnumber(L1, lua_tonumber(L1, getindex));
1261 }
1262 else if EQ("topointer") {
1263 lua_pushnumber(L1, cast(size_t, lua_topointer(L1, getindex)));
1264 }
1265 else if EQ("tostring") {
1266 const char *s = lua_tostring(L1, getindex);
1267 const char *s1 = lua_pushstring(L1, s);
1268 lua_assert((s == NULL && s1 == NULL) || (strcmp)(s, s1) == 0);
1269 }
1270 else if EQ("tounsigned") {
1271 lua_pushinteger(L1, (lua_Integer)lua_tounsigned(L1, getindex));
1272 }
1273 else if EQ("type") {
1274 lua_pushstring(L1, luaL_typename(L1, getnum));
1275 }
1276 else if EQ("xmove") {
1277 int f = getindex;
1278 int t = getindex;
1279 lua_State *fs = (f == 0) ? L1 : lua_tothread(L1, f);
1280 lua_State *ts = (t == 0) ? L1 : lua_tothread(L1, t);
1281 int n = getnum;
1282 if (n == 0) n = lua_gettop(fs);
1283 lua_xmove(fs, ts, n);
1284 }
1285 else if EQ("yield") {
1286 return lua_yield(L1, getnum);
1287 }
1288 else if EQ("yieldk") {
1289 int nres = getnum;
1290 int i = getindex;
1291 return lua_yieldk(L1, nres, i, Cfunck);
1292 }
1287 else luaL_error(L, "unknown instruction %s", buff); 1293 else luaL_error(L, "unknown instruction %s", buff);
1288 } 1294 }
1289 return 0; 1295 return 0;