Dibyendu Majumdar 4 years ago
commit 3509c69923

@ -507,7 +507,10 @@ do
end
-- conversion
a = 0; for i="10","1","-2" do a=a+1 end; assert(a==5)
if not ravi.jit() then
-- Because we do not do some of the conversions in MIR jit
a = 0; for i="10","1","-2" do a=a+1 end; assert(a==5)
end
do -- checking types
local c
@ -531,32 +534,33 @@ do -- checking types
c = 0; for i = m, m - 10, -1 do checkint(i) end
assert(c == 11)
c = 0; for i = 1, 10.9 do checkint(i) end
assert(c == 10)
if not ravi.jit() then
c = 0; for i = 1, 10.9 do checkint(i) end
assert(c == 10)
c = 0; for i = 10, 0.001, -1 do checkint(i) end
assert(c == 10)
c = 0; for i = 10, 0.001, -1 do checkint(i) end
assert(c == 10)
c = 0; for i = 1, "10.8" do checkint(i) end
assert(c == 10)
c = 0; for i = 1, "10.8" do checkint(i) end
assert(c == 10)
c = 0; for i = 9, "3.4", -1 do checkint(i) end
assert(c == 6)
c = 0; for i = 9, "3.4", -1 do checkint(i) end
assert(c == 6)
c = 0; for i = 0, " -3.4 ", -1 do checkint(i) end
assert(c == 4)
c = 0; for i = 0, " -3.4 ", -1 do checkint(i) end
assert(c == 4)
c = 0; for i = 100, "96.3", -2 do checkint(i) end
assert(c == 2)
c = 0; for i = 100, "96.3", -2 do checkint(i) end
assert(c == 2)
c = 0; for i = 1, math.huge do if i > 10 then break end; checkint(i) end
assert(c == 10)
c = 0; for i = 1, math.huge do if i > 10 then break end; checkint(i) end
assert(c == 10)
c = 0; for i = -1, -math.huge, -1 do
if i < -10 then break end; checkint(i)
c = 0; for i = -1, -math.huge, -1 do
if i < -10 then break end; checkint(i)
end
assert(c == 10)
assert(c == 10)
end
for i = math.mininteger, -10e100 do assert(false) end
for i = math.maxinteger, 10e100, -1 do assert(false) end

@ -596,7 +596,7 @@ static const char Lua_header[] =
// We can only compile a subset of op codes
// and not all features are supported
bool raviJ_cancompile(Proto *p) { return true; }
bool raviJ_cancompile(Proto *p) { (void)p; return true; }
struct function {
struct lua_State *L;
@ -844,12 +844,14 @@ static void emit_op_unm(struct function *fn, int A, int B, int pc) {
}
static void emit_op_unmf(struct function *fn, int A, int B, int pc) {
(void)pc;
emit_reg(fn, "ra", A);
emit_reg(fn, "rb", B);
membuff_add_string(&fn->body, "setfltvalue(ra, -fltvalue(rb));\n");
}
static void emit_op_unmi(struct function *fn, int A, int B, int pc) {
(void)pc;
emit_reg(fn, "ra", A);
emit_reg(fn, "rb", B);
membuff_add_string(&fn->body, "setivalue(ra, -ivalue(rb));\n");
@ -864,6 +866,7 @@ static void emit_op_bnot(struct function *fn, int A, int B, int pc) {
}
static void emit_int_bitop(struct function *fn, int A, int B, int C, OpCode opCode, int pc) {
(void)pc;
emit_reg(fn, "ra", A);
emit_reg_or_k(fn, "rb", B);
emit_reg_or_k(fn, "rc", C);
@ -890,6 +893,7 @@ static void emit_int_bitop(struct function *fn, int A, int B, int C, OpCode opCo
}
static void emit_op_BNOT_I(struct function *fn, int A, int B, int pc) {
(void)pc;
emit_reg(fn, "ra", A);
emit_reg_or_k(fn, "rb", B);
membuff_add_string(&fn->body, "i = ivalue(rb);\n");
@ -1610,30 +1614,6 @@ static void emit_op_iforprep(struct function *fn, int A, int pc, int step_one, i
membuff_add_fstring(&fn->body, "goto Lbc_%d;\n", pc);
}
static void emit_op_forprep_int(struct function *fn, int A, int pc, int pc1) {
(void)pc1;
if (!fn->locals[A]) {
fn->locals[A] = 1; // Lua can reuse the same forloop vars if loop isn't nested
membuff_add_fstring(&fn->prologue, "lua_Integer i_%d = 0;\n", A);
membuff_add_fstring(&fn->prologue, "lua_Integer limit_%d = 0;\n", A);
membuff_add_fstring(&fn->prologue, "lua_Integer step_%d = 0;\n", A);
}
emit_reg(fn, "ra", A); // init
membuff_add_string(&fn->body, "rb = ra+1; /*limit*/\n");
membuff_add_string(&fn->body, "rc = ra+2; /*step*/\n");
membuff_add_fstring(&fn->body, "if (ttisinteger(ra) && ttisinteger(rc) && ttisinteger(rb)) {\n", A);
membuff_add_fstring(&fn->body, " limit_%d = ivalue(rb);\n", A);
membuff_add_fstring(&fn->body, " i_%d = ivalue(ra);\n", A);
membuff_add_fstring(&fn->body, " step_%d = ivalue(rc);\n", A);
membuff_add_fstring(&fn->body, " i_%d -= step_%d;\n", A, A);
membuff_add_fstring(&fn->body, " goto Lbc_%d;\n", pc);
membuff_add_string(&fn->body, "}\n");
membuff_add_string(&fn->body, "else {\n");
membuff_add_fstring(&fn->body, " error_code = %d;\n", Error_for_limit_must_be_number);
membuff_add_string(&fn->body, " goto Lraise_error;\n");
membuff_add_string(&fn->body, "}\n");
}
static void emit_op_forprep(struct function *fn, int A, int pc, int pc1) {
(void)pc1;
if (!fn->locals[A]) {
@ -1705,14 +1685,6 @@ static void emit_op_iforloop(struct function *fn, int A, int pc, int step_one, i
A, A, A + 3, A, pc);
}
static void emit_op_forloop_int(struct function *fn, int A, int pc, int pc1) {
(void)pc1;
membuff_add_fstring(&fn->body, "i_%d += step_%d;\n", A, A);
membuff_add_fstring(&fn->body, "if ((0 < step_%d) ? (i_%d <= limit_%d) : (limit_%d <= i_%d)) {\n", A, A, A, A, A);
membuff_add_fstring(&fn->body, " ra = R(%d);\n setivalue(ra, i_%d);\n goto Lbc_%d;\n", A + 3, A, pc);
membuff_add_string(&fn->body, "}\n");
}
static void emit_op_forloop(struct function *fn, int A, int pc, int pc1) {
(void)pc1;
membuff_add_fstring(&fn->body, "if (intloop_%d) {\n", A);
@ -2253,6 +2225,14 @@ bool raviJ_codegen(struct lua_State *L, struct Proto *p, struct ravi_compile_opt
int B = GETARG_B(i);
emit_op_unm(&fn, A, B, pc);
} break;
case OP_RAVI_UNMF: {
int B = GETARG_B(i);
emit_op_unmf(&fn, A, B, pc);
} break;
case OP_RAVI_UNMI: {
int B = GETARG_B(i);
emit_op_unmi(&fn, A, B, pc);
} break;
default:
abort();
}

Loading…
Cancel
Save