diff --git a/include/lopcodes.h b/include/lopcodes.h index 6da4b0d6..9a792dac 100644 --- a/include/lopcodes.h +++ b/include/lopcodes.h @@ -219,8 +219,8 @@ OP_RAVI_DIVII, /* A B C R(A) := RK(B) / RK(C) */ OP_RAVI_TOINT, /* A R(A) := toint(R(A)) */ OP_RAVI_TOFLT, /* A R(A) := tofloat(R(A)) */ -OP_RAVI_TOARRAYI, /* A R(A) := to_arrayi(R(A)) */ -OP_RAVI_TOARRAYF, /* A R(A) := to_arrayf(R(A)) */ +OP_RAVI_TOIARRAY, /* A R(A) := to_arrayi(R(A)) */ +OP_RAVI_TOFARRAY, /* A R(A) := to_arrayf(R(A)) */ OP_RAVI_TOTAB, /* A R(A) := to_table(R(A)) */ OP_RAVI_TOSTRING, OP_RAVI_TOCLOSURE, diff --git a/ravi-tests/ravi_tests1.ravi b/ravi-tests/ravi_tests1.ravi index aad4f268..d268a9c8 100644 --- a/ravi-tests/ravi_tests1.ravi +++ b/ravi-tests/ravi_tests1.ravi @@ -75,8 +75,8 @@ opcodes_coverage.DIVIF = 0 opcodes_coverage.DIVII = 0 opcodes_coverage.TOINT = 0 opcodes_coverage.TOFLT = 0 -opcodes_coverage.TOARRAYI = 0 -opcodes_coverage.TOARRAYF = 0 +opcodes_coverage.TOIARRAY = 0 +opcodes_coverage.TOFARRAY = 0 opcodes_coverage.MOVEI = 0 opcodes_coverage.MOVEF = 0 opcodes_coverage.MOVEAI = 0 diff --git a/ravi-tests/ravi_tests2.ravi b/ravi-tests/ravi_tests2.ravi index fa28f0ad..4d72a622 100644 --- a/ravi-tests/ravi_tests2.ravi +++ b/ravi-tests/ravi_tests2.ravi @@ -77,8 +77,8 @@ opcodes_coverage.DIVIF = 0 opcodes_coverage.DIVII = 0 opcodes_coverage.TOINT = 0 opcodes_coverage.TOFLT = 0 -opcodes_coverage.TOARRAYI = 0 -opcodes_coverage.TOARRAYF = 0 +opcodes_coverage.TOIARRAY = 0 +opcodes_coverage.TOFARRAY = 0 opcodes_coverage.MOVEI = 0 opcodes_coverage.MOVEF = 0 opcodes_coverage.MOVEAI = 0 @@ -256,5 +256,5 @@ end assert(ravitype(x()) == 'number[]') assert(x()[1] == 42.0) check(x, {'NEW_IARRAY', 'LOADK', 'SETLIST', 'TEST', - 'JMP', 'NEW_FARRAY', 'LOADK', 'SETLIST', 'TOARRAYF', + 'JMP', 'NEW_FARRAY', 'LOADK', 'SETLIST', 'TOFARRAY', 'RETURN', 'RETURN'}) diff --git a/readthedocs/ravi-internals.rst b/readthedocs/ravi-internals.rst index b7e27b74..eb403899 100644 --- a/readthedocs/ravi-internals.rst +++ b/readthedocs/ravi-internals.rst @@ -268,7 +268,7 @@ Parameter lists may have static type annotations as well, so when parsing parame } else if (tt == RAVI_TARRAYFLT || tt == RAVI_TARRAYINT) { /* code an instruction to convert in place */ - luaK_codeABC(ls->fs, tt == RAVI_TARRAYFLT ? OP_RAVI_TOARRAYF : OP_RAVI_TOARRAYI, i, 0, 0); + luaK_codeABC(ls->fs, tt == RAVI_TARRAYFLT ? OP_RAVI_TOFARRAY : OP_RAVI_TOIARRAY, i, 0, 0); } } } @@ -415,7 +415,7 @@ The main changes compared to ``explist()`` are the calls to ``ravi_typecheck()`` /* code an instruction to convert in place */ luaK_codeABC(ls->fs, vars[i] == RAVI_TARRAYFLT ? - OP_RAVI_TOARRAYF : OP_RAVI_TOARRAYI, + OP_RAVI_TOFARRAY : OP_RAVI_TOIARRAY, a + (i - n), 0, 0); } else if ((vars[n] == RAVI_TNUMFLT || vars[n] == RAVI_TNUMINT) && @@ -435,7 +435,7 @@ The simple case is when the type of the expression matches the variable. Secondly if the expression is a table initializer then we need to generate specialized opcodes if the target variable is supposed to be ``integer[]`` or ``number[]``. The specialized opcode sets up some information in the ``Table`` structure. The problem is that this requires us to modify ``OP_NEWTABLE`` instruction which has already been emitted. So we scan the generated instructions to find the last ``OP_NEWTABLE`` instruction that assigns to the register associated with the target variable. -Next bit of special handling is for function calls. If the assignment makes a function call then we perform type coercion on return values where these values are being assigned to variables with defined types. This means that if the target variable is ``integer`` or ``number`` we issue opcodes ``TOINT`` and ``TOFLT`` respectively. If the target variable is ``integer[]`` or ``number[]`` then we issue ``TOARRAYI`` and ``TOARRAYF`` respectively. These opcodes ensure that the values are of required type or can be cast to the required type. +Next bit of special handling is for function calls. If the assignment makes a function call then we perform type coercion on return values where these values are being assigned to variables with defined types. This means that if the target variable is ``integer`` or ``number`` we issue opcodes ``TOINT`` and ``TOFLT`` respectively. If the target variable is ``integer[]`` or ``number[]`` then we issue ``TOIARRAY`` and ``TOFARRAY`` respectively. These opcodes ensure that the values are of required type or can be cast to the required type. Note that any left over variables that are not assigned values, are set to 0 if they are of integer or number type, else they are set to nil as per Lua's default behavior. This is handled in ``localvar_adjust_assign()`` which is described later on. @@ -558,7 +558,7 @@ Note the use of ``register_to_localvar_index()`` in functions below. OP_RAVI_TOFLT : OP_RAVI_TOINT, i, 0, 0); else if (ravi_type == RAVI_TARRAYINT || ravi_type == RAVI_TARRAYFLT) luaK_codeABC(ls->fs, ravi_type == RAVI_TARRAYINT ? - OP_RAVI_TOARRAYI : OP_RAVI_TOARRAYF, i, 0, 0); + OP_RAVI_TOIARRAY : OP_RAVI_TOFARRAY, i, 0, 0); } } diff --git a/readthedocs/ravi-jit-status.rst b/readthedocs/ravi-jit-status.rst index 546a9cb1..9e86bd6d 100644 --- a/readthedocs/ravi-jit-status.rst +++ b/readthedocs/ravi-jit-status.rst @@ -194,9 +194,9 @@ Note that if a Lua functions contains a bytecode that cannot be be JITed then th +-------------------------+----------+--------------------------------------------------+ | OP_RAVI_TOFLT | YES | R(A) := tofloat(R(A)) | +-------------------------+----------+--------------------------------------------------+ -| OP_RAVI_TOARRAYI | YES | R(A) := to_arrayi(R(A)) | +| OP_RAVI_TOIARRAY | YES | R(A) := to_arrayi(R(A)) | +-------------------------+----------+--------------------------------------------------+ -| OP_RAVI_TOARRAYF | YES | R(A) := to_arrayf(R(A)) | +| OP_RAVI_TOFARRAY | YES | R(A) := to_arrayf(R(A)) | +-------------------------+----------+--------------------------------------------------+ | OP_RAVI_MOVEI | YES | R(A) := R(B), check R(B) is integer | +-------------------------+----------+--------------------------------------------------+ diff --git a/src/lcode.c b/src/lcode.c index 0ad03474..99fce79b 100644 --- a/src/lcode.c +++ b/src/lcode.c @@ -1505,7 +1505,7 @@ static void code_type_assertion(FuncState *fs, UnOpr op, expdesc *e, TString *us } return; } - opcode = OP_RAVI_TOARRAYI; + opcode = OP_RAVI_TOIARRAY; tt = RAVI_TARRAYINT; } else if (op == OPR_TO_NUMARRAY && e->ravi_type != RAVI_TARRAYFLT) { @@ -1518,7 +1518,7 @@ static void code_type_assertion(FuncState *fs, UnOpr op, expdesc *e, TString *us } return; } - opcode = OP_RAVI_TOARRAYF; + opcode = OP_RAVI_TOFARRAY; tt = RAVI_TARRAYFLT; } else if (op == OPR_TO_TABLE && e->ravi_type != RAVI_TTABLE) { diff --git a/src/lopcodes.c b/src/lopcodes.c index e79b6830..aad7ae76 100644 --- a/src/lopcodes.c +++ b/src/lopcodes.c @@ -107,8 +107,8 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { "TOINT", /* A R(A) := toint(R(A)) */ "TOFLT", /* A R(A) := tofloat(R(A)) */ - "TOARRAYI", /* A R(A) := to_arrayi(R(A)) */ - "TOARRAYF", /* A R(A) := to_arrayf(R(A)) */ + "TOIARRAY", /* A R(A) := to_arrayi(R(A)) */ + "TOFARRAY", /* A R(A) := to_arrayf(R(A)) */ "TOTAB", /* A R(A) := to_table(R(A)) */ "TOSTRING", "TOCLOSURE", @@ -248,8 +248,8 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { ,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOINT A R(A) := toint(R(A)) */ ,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOFLT A R(A) := tonumber(R(A)) */ - ,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOARRAYI A R(A) := check_array_of_int(R(A)) */ - ,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOARRAYF A R(A) := check_array_of_float(R(A)) */ + ,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOIARRAY A R(A) := check_array_of_int(R(A)) */ + ,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOFARRAY A R(A) := check_array_of_float(R(A)) */ ,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOTAB A R(A) := check_table(R(A)) */ ,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOSTRING */ ,opmode(0, 1, OpArgN, OpArgN, iABC) /* OP_RAVI_TOCLOSURE */ diff --git a/src/lparser.c b/src/lparser.c index 0c540ac9..2d2b7880 100644 --- a/src/lparser.c +++ b/src/lparser.c @@ -584,8 +584,8 @@ static void ravi_code_typecoersion(LexState *ls, int reg, ravitype_t ravi_type, ravi_type == RAVI_TNUMFLT ? OP_RAVI_TOFLT : OP_RAVI_TOINT, reg, 0, 0); else if (ravi_type == RAVI_TARRAYINT || ravi_type == RAVI_TARRAYFLT) - luaK_codeABC(ls->fs, ravi_type == RAVI_TARRAYINT ? OP_RAVI_TOARRAYI - : OP_RAVI_TOARRAYF, + luaK_codeABC(ls->fs, ravi_type == RAVI_TARRAYINT ? OP_RAVI_TOIARRAY + : OP_RAVI_TOFARRAY, reg, 0, 0); else if (ravi_type == RAVI_TTABLE) luaK_codeABC(ls->fs, OP_RAVI_TOTAB, diff --git a/src/lvm.c b/src/lvm.c index dcca4566..f75ed299 100644 --- a/src/lvm.c +++ b/src/lvm.c @@ -1211,8 +1211,8 @@ int luaV_execute (lua_State *L) { &&vmlabel(OP_RAVI_DIVII), &&vmlabel(OP_RAVI_TOINT), &&vmlabel(OP_RAVI_TOFLT), - &&vmlabel(OP_RAVI_TOARRAYI), - &&vmlabel(OP_RAVI_TOARRAYF), + &&vmlabel(OP_RAVI_TOIARRAY), + &&vmlabel(OP_RAVI_TOFARRAY), &&vmlabel(OP_RAVI_TOTAB), &&vmlabel(OP_RAVI_TOSTRING), &&vmlabel(OP_RAVI_TOCLOSURE), @@ -2413,12 +2413,12 @@ int luaV_execute (lua_State *L) { luaG_runerror(L, "table expected"); vmbreak; } - vmcase(OP_RAVI_TOARRAYI) { + vmcase(OP_RAVI_TOIARRAY) { if (RAVI_UNLIKELY(!ttisiarray(ra))) luaG_runerror(L, "integer[] expected"); vmbreak; } - vmcase(OP_RAVI_TOARRAYF) { + vmcase(OP_RAVI_TOFARRAY) { if (RAVI_UNLIKELY(!ttisfarray(ra))) luaG_runerror(L, "number[] expected"); vmbreak; diff --git a/src/ravi_jitshared.c b/src/ravi_jitshared.c index 02025e2d..755c97fe 100644 --- a/src/ravi_jitshared.c +++ b/src/ravi_jitshared.c @@ -681,8 +681,8 @@ bool raviJ_cancompile(Proto *p) { case OP_RAVI_MOVETAB: case OP_RAVI_TOINT: case OP_RAVI_TOFLT: - case OP_RAVI_TOARRAYI: - case OP_RAVI_TOARRAYF: + case OP_RAVI_TOIARRAY: + case OP_RAVI_TOFARRAY: case OP_RAVI_TOTAB: case OP_RAVI_NEW_IARRAY: case OP_RAVI_NEW_FARRAY: @@ -2120,10 +2120,10 @@ bool raviJ_codegen(struct lua_State *L, struct Proto *p, case OP_RAVI_TOTAB: { emit_op_totab(&fn, A, pc); } break; - case OP_RAVI_TOARRAYI: { + case OP_RAVI_TOIARRAY: { emit_op_toai(&fn, A, pc); } break; - case OP_RAVI_TOARRAYF: { + case OP_RAVI_TOFARRAY: { emit_op_toaf(&fn, A, pc); } break; case OP_RAVI_TOSTRING: { diff --git a/src/ravi_llvmcodegen.cpp b/src/ravi_llvmcodegen.cpp index f9763e15..f0bbcc20 100644 --- a/src/ravi_llvmcodegen.cpp +++ b/src/ravi_llvmcodegen.cpp @@ -1707,10 +1707,10 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p, case OP_RAVI_TOTAB: { emit_TOARRAY(def, A, RAVI_TTABLE, "table expected", pc); } break; - case OP_RAVI_TOARRAYI: { + case OP_RAVI_TOIARRAY: { emit_TOARRAY(def, A, RAVI_TARRAYINT, "integer[] expected", pc); } break; - case OP_RAVI_TOARRAYF: { + case OP_RAVI_TOFARRAY: { emit_TOARRAY(def, A, RAVI_TARRAYFLT, "number[] expected", pc); } break; case OP_RAVI_TOSTRING: { diff --git a/src/ravi_llvmtable.cpp b/src/ravi_llvmtable.cpp index 5fff48c9..6bd37b43 100644 --- a/src/ravi_llvmtable.cpp +++ b/src/ravi_llvmtable.cpp @@ -917,11 +917,11 @@ void RaviCodeGenerator::emit_TOARRAY(RaviFunctionDef *def, int A, LuaTypeCode expectedType = RAVI__TLTABLE; switch (array_type_expected) { case RAVI_TARRAYINT: - op = OP_RAVI_TOARRAYI; + op = OP_RAVI_TOIARRAY; expectedType = RAVI__TIARRAY; break; case RAVI_TARRAYFLT: - op = OP_RAVI_TOARRAYF; + op = OP_RAVI_TOFARRAY; expectedType = RAVI__TFARRAY; break; case RAVI_TTABLE: diff --git a/vmbuilder/src/buildvm.c b/vmbuilder/src/buildvm.c index 74832b1b..c1bc9311 100644 --- a/vmbuilder/src/buildvm.c +++ b/vmbuilder/src/buildvm.c @@ -485,8 +485,8 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES + 1] = "TOINT", /* A R(A) := toint(R(A)) */ "TOFLT", /* A R(A) := tofloat(R(A)) */ - "TOARRAYI", /* A R(A) := to_arrayi(R(A)) */ - "TOARRAYF", /* A R(A) := to_arrayf(R(A)) */ + "TOIARRAY", /* A R(A) := to_arrayi(R(A)) */ + "TOFARRAY", /* A R(A) := to_arrayf(R(A)) */ "TOTAB", /* A R(A) := to_table(R(A)) */ "TOSTRING", "TOCLOSURE",