diff options
-rw-r--r-- | lopcodes.c | 6 | ||||
-rw-r--r-- | lopcodes.h | 4 | ||||
-rw-r--r-- | ltm.c | 16 | ||||
-rw-r--r-- | ltm.h | 4 | ||||
-rw-r--r-- | lvm.c | 53 |
5 files changed, 71 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.c,v 1.68 2017/11/16 12:59:14 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.69 2017/11/22 18:41:20 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 | */ |
@@ -68,6 +68,8 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { | |||
68 | "LE", | 68 | "LE", |
69 | "EQK", | 69 | "EQK", |
70 | "EQI", | 70 | "EQI", |
71 | "LTI", | ||
72 | "LEI", | ||
71 | "TEST", | 73 | "TEST", |
72 | "TESTSET", | 74 | "TESTSET", |
73 | "CALL", | 75 | "CALL", |
@@ -137,6 +139,8 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
137 | ,opmode(1, 0, iABC) /* OP_LE */ | 139 | ,opmode(1, 0, iABC) /* OP_LE */ |
138 | ,opmode(1, 0, iABC) /* OP_EQK */ | 140 | ,opmode(1, 0, iABC) /* OP_EQK */ |
139 | ,opmode(1, 0, iABC) /* OP_EQI */ | 141 | ,opmode(1, 0, iABC) /* OP_EQI */ |
142 | ,opmode(1, 0, iABC) /* OP_LTI */ | ||
143 | ,opmode(1, 0, iABC) /* OP_LEI */ | ||
140 | ,opmode(1, 0, iABC) /* OP_TEST */ | 144 | ,opmode(1, 0, iABC) /* OP_TEST */ |
141 | ,opmode(1, 1, iABC) /* OP_TESTSET */ | 145 | ,opmode(1, 1, iABC) /* OP_TESTSET */ |
142 | ,opmode(0, 1, iABC) /* OP_CALL */ | 146 | ,opmode(0, 1, iABC) /* OP_CALL */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.169 2017/11/22 18:41:20 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.170 2017/11/22 19:15:44 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 | */ |
@@ -242,6 +242,8 @@ OP_LE,/* A B C if ((R(A) <= R(C)) ~= B) then pc++ */ | |||
242 | 242 | ||
243 | OP_EQK,/* A B C if ((R(A) == K(C)) ~= B) then pc++ */ | 243 | OP_EQK,/* A B C if ((R(A) == K(C)) ~= B) then pc++ */ |
244 | OP_EQI,/* A B C if ((R(A) == C) ~= B) then pc++ */ | 244 | OP_EQI,/* A B C if ((R(A) == C) ~= B) then pc++ */ |
245 | OP_LTI,/* A B C if ((R(A) < C) ~= B) then pc++ */ | ||
246 | OP_LEI,/* A B C if ((R(A) <= C) ~= B) then pc++ */ | ||
245 | 247 | ||
246 | OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ | 248 | OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ |
247 | OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ | 249 | OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 2.48 2017/11/08 14:50:23 roberto Exp $ | 2 | ** $Id: ltm.c,v 2.49 2017/11/23 19:18:10 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -196,6 +196,20 @@ int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, | |||
196 | } | 196 | } |
197 | 197 | ||
198 | 198 | ||
199 | int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, | ||
200 | int inv, TMS event) { | ||
201 | TValue aux; const TValue *p2; | ||
202 | setivalue(&aux, v2); | ||
203 | if (inv) { /* arguments were exchanged? */ | ||
204 | p2 = p1; p1 = &aux; /* correct them */ | ||
205 | event = (event == TM_LE) ? TM_LT : TM_LE; | ||
206 | } | ||
207 | else | ||
208 | p2 = &aux; | ||
209 | return (luaT_callorderTM(L, p1, p2, event) != inv); | ||
210 | } | ||
211 | |||
212 | |||
199 | void luaT_adjustvarargs (lua_State *L, Proto *p, int actual) { | 213 | void luaT_adjustvarargs (lua_State *L, Proto *p, int actual) { |
200 | int i; | 214 | int i; |
201 | Table *vtab; | 215 | Table *vtab; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.h,v 2.25 2017/06/29 15:06:44 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 2.26 2017/09/27 18:59:08 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -72,6 +72,8 @@ LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2, | |||
72 | int inv, StkId res, TMS event); | 72 | int inv, StkId res, TMS event); |
73 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, | 73 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, |
74 | const TValue *p2, TMS event); | 74 | const TValue *p2, TMS event); |
75 | LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, | ||
76 | int inv, TMS event); | ||
75 | 77 | ||
76 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, Proto *p, int actual); | 78 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, Proto *p, int actual); |
77 | LUAI_FUNC void luaT_getvarargs (lua_State *L, TValue *t, StkId where, | 79 | LUAI_FUNC void luaT_getvarargs (lua_State *L, TValue *t, StkId where, |
@@ -1,9 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | <<<<<<< lvm.c | 2 | ** $Id: lvm.c,v 2.317 2017/11/23 19:18:10 roberto Exp roberto $ |
3 | ** $Id: lvm.c,v 2.316 2017/11/23 16:41:16 roberto Exp roberto $ | ||
4 | ======= | ||
5 | ** $Id: lvm.c,v 2.316 2017/11/23 16:41:16 roberto Exp roberto $ | ||
6 | >>>>>>> 2.315 | ||
7 | ** Lua virtual machine | 3 | ** Lua virtual machine |
8 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
9 | */ | 5 | */ |
@@ -699,16 +695,21 @@ void luaV_finishOp (lua_State *L) { | |||
699 | setobjs2s(L, base + GETARG_A(inst), --L->top); | 695 | setobjs2s(L, base + GETARG_A(inst), --L->top); |
700 | break; | 696 | break; |
701 | } | 697 | } |
702 | case OP_LE: case OP_LT: case OP_EQ: { | 698 | case OP_LT: case OP_LE: |
699 | case OP_LTI: case OP_LEI: | ||
700 | case OP_EQ: { /* note that 'OP_EQI'/'OP_EQK' cannot yield */ | ||
703 | int res = !l_isfalse(s2v(L->top - 1)); | 701 | int res = !l_isfalse(s2v(L->top - 1)); |
704 | L->top--; | 702 | L->top--; |
705 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ | 703 | if (ci->callstatus & CIST_LEQ) { /* "<=" using "<" instead? */ |
706 | lua_assert(op == OP_LE); | 704 | lua_assert(op == OP_LE || |
705 | (op == OP_LEI && !(GETARG_B(inst) & 2)) || | ||
706 | (op == OP_LTI && GETARG_B(inst) & 2)); | ||
707 | ci->callstatus ^= CIST_LEQ; /* clear mark */ | 707 | ci->callstatus ^= CIST_LEQ; /* clear mark */ |
708 | res = !res; /* negate result */ | 708 | res = !res; /* negate result */ |
709 | } | 709 | } |
710 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); | 710 | lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP); |
711 | if (res != GETARG_B(inst)) /* condition failed? */ | 711 | if (GETARG_B(inst) & 2) res = !res; |
712 | if (res != (GETARG_B(inst) & 1)) /* condition failed? */ | ||
712 | ci->u.l.savedpc++; /* skip jump instruction */ | 713 | ci->u.l.savedpc++; /* skip jump instruction */ |
713 | break; | 714 | break; |
714 | } | 715 | } |
@@ -1383,6 +1384,42 @@ void luaV_execute (lua_State *L) { | |||
1383 | donextjump(ci); | 1384 | donextjump(ci); |
1384 | vmbreak; | 1385 | vmbreak; |
1385 | } | 1386 | } |
1387 | vmcase(OP_LTI) { | ||
1388 | int res; | ||
1389 | int ic = GETARG_sC(i); | ||
1390 | if (ttisinteger(s2v(ra))) | ||
1391 | res = (ivalue(s2v(ra)) < ic); | ||
1392 | else if (ttisfloat(s2v(ra))) { | ||
1393 | lua_Number f = fltvalue(s2v(ra)); | ||
1394 | res = (!luai_numisnan(f)) ? luai_numlt(f, cast_num(ic)) | ||
1395 | : GETARG_B(i) >> 1; /* NaN? */ | ||
1396 | } | ||
1397 | else | ||
1398 | Protect(res = luaT_callorderiTM(L, s2v(ra), ic, GETARG_B(i) >> 1, TM_LT)); | ||
1399 | if (res != (GETARG_B(i) & 1)) | ||
1400 | pc++; | ||
1401 | else | ||
1402 | donextjump(ci); | ||
1403 | vmbreak; | ||
1404 | } | ||
1405 | vmcase(OP_LEI) { | ||
1406 | int res; | ||
1407 | int ic = GETARG_sC(i); | ||
1408 | if (ttisinteger(s2v(ra))) | ||
1409 | res = (ivalue(s2v(ra)) <= ic); | ||
1410 | else if (ttisfloat(s2v(ra))) { | ||
1411 | lua_Number f = fltvalue(s2v(ra)); | ||
1412 | res = (!luai_numisnan(f)) ? luai_numle(f, cast_num(ic)) | ||
1413 | : GETARG_B(i) >> 1; /* NaN? */ | ||
1414 | } | ||
1415 | else | ||
1416 | Protect(res = luaT_callorderiTM(L, s2v(ra), ic, GETARG_B(i) >> 1, TM_LE)); | ||
1417 | if (res != (GETARG_B(i) & 1)) | ||
1418 | pc++; | ||
1419 | else | ||
1420 | donextjump(ci); | ||
1421 | vmbreak; | ||
1422 | } | ||
1386 | vmcase(OP_TEST) { | 1423 | vmcase(OP_TEST) { |
1387 | if (GETARG_C(i) ? l_isfalse(s2v(ra)) : !l_isfalse(s2v(ra))) | 1424 | if (GETARG_C(i) ? l_isfalse(s2v(ra)) : !l_isfalse(s2v(ra))) |
1388 | pc++; | 1425 | pc++; |