issue #98 make the normal parser consistent with the new typechecker

pull/168/head
Dibyendu Majumdar 5 years ago
parent 6b5315366a
commit 99d9fcbdd2

@ -1705,6 +1705,28 @@ compile(x)
x()
print 'Test 75 OK'
-- Test that % of ints results in int
function x(a: integer, b:integer)
return a%b == 0
end
check(x, 'TOINT', 'TOINT', 'MOD',
'EQ_II', 'JMP', 'LOADBOOL', 'LOADBOOL', 'RETURN', 'RETURN')
assert(x(10,5))
compile(x)
assert(x(10,5))
print 'Test 76 OK'
-- Test that ^ applied to numbers results in a number
function x(a:number, b:number)
local c:number = a^b
return c
end
check(x, 'TOFLT', 'TOFLT', 'POW', 'RETURN', 'RETURN')
assert(x(2,3) == 2^3)
compile(x)
assert(x(2,3) == 2^3)
print 'Test 77 OK'
for k,v in pairs(opcodes_coverage)
do
print(k, v)

@ -1390,6 +1390,11 @@ static void codebinexpval (FuncState *fs, OpCode op,
&& (e1->ravi_type == RAVI_TNUMINT || e1->ravi_type == RAVI_TNUMFLT)
&& (e2->ravi_type == RAVI_TNUMINT || e2->ravi_type == RAVI_TNUMFLT))
e1->ravi_type = RAVI_TNUMINT;
else if (op == OP_POW && (e1->ravi_type == RAVI_TNUMFLT || e1->ravi_type == RAVI_TNUMINT) &&
(e2->ravi_type == RAVI_TNUMFLT || e2->ravi_type == RAVI_TNUMINT))
e1->ravi_type = RAVI_TNUMFLT;
else if (op == OP_MOD && (e1->ravi_type == RAVI_TNUMINT && e2->ravi_type == RAVI_TNUMINT))
e1->ravi_type = RAVI_TNUMINT;
else
e1->ravi_type = RAVI_TANY;
luaK_fixline(fs, line);

@ -129,9 +129,6 @@ static void typecheck_binaryop(struct ast_node *function, struct ast_node *node)
case OPR_MOD:
if (e1->common_expr.type.type_code == RAVI_TNUMINT && e2->common_expr.type.type_code == RAVI_TNUMINT)
set_typecode(node->binary_expr.type, RAVI_TNUMINT);
else if ((e1->common_expr.type.type_code == RAVI_TNUMINT && e2->common_expr.type.type_code == RAVI_TNUMFLT) ||
(e1->common_expr.type.type_code == RAVI_TNUMFLT && e2->common_expr.type.type_code == RAVI_TNUMINT))
set_typecode(node->binary_expr.type, RAVI_TNUMFLT);
break;
default:
set_typecode(node->binary_expr.type, RAVI_TANY);

Loading…
Cancel
Save