Skip to content

Commit

Permalink
#245 sync upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Nov 9, 2022
1 parent 7a58cef commit acb7738
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
32 changes: 23 additions & 9 deletions ravicomp/src/linearizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,17 @@ static void create_binary_instruction(Proc *proc, enum opcode targetop, Pseudo *
free_temp_pseudo(proc, tofree2, false);
}

static Pseudo *linearize_negate_condition(Proc *proc, int line_number, Pseudo *pseudo, Pseudo *not_pseudo) {
Instruction *not_insn = allocate_instruction(proc, op_not, line_number);
Pseudo *tofree = add_instruction_operand(proc, not_insn, pseudo);
free_temp_pseudo(proc, pseudo, false);//CHECK
add_instruction_target(proc, not_insn, not_pseudo);
add_instruction(proc, not_insn);
if (tofree)
free_temp_pseudo(proc, tofree, false);
return not_pseudo;
}

static Pseudo *linearize_binary_operator(Proc *proc, AstNode *node)
{
BinaryOperatorType op = node->binary_expr.binary_op;
Expand Down Expand Up @@ -1159,14 +1170,7 @@ static Pseudo *linearize_binary_operator(Proc *proc, AstNode *node)
free_temp_pseudo(proc, operand2, false);//CHECK

if (op == BINOPR_NE) {
Instruction *not_insn = allocate_instruction(proc, op_not, node->line_number);
Pseudo *tofree = add_instruction_operand(proc, not_insn, target);
free_temp_pseudo(proc, target, false);//CHECK
target = not_target;
add_instruction_target(proc, not_insn, target);
add_instruction(proc, not_insn);
if (tofree)
free_temp_pseudo(proc, tofree, false);
target = linearize_negate_condition(proc, node->line_number, target, not_target);
}
return target;
}
Expand Down Expand Up @@ -2728,15 +2732,25 @@ static void linearize_while_statment(Proc *proc, AstNode *node)

if (node->type == STMT_REPEAT) {
instruct_br(proc, allocate_block_pseudo(proc, body_block), node->line_number);
start_scope(proc->linearizer, proc, node->while_or_repeat_stmt.loop_scope);
}

start_block(proc, test_block, node->line_number);
Pseudo *neg_condition_pseudo = NULL;
if (node->type == STMT_REPEAT) {
neg_condition_pseudo = allocate_temp_pseudo(proc, RAVI_TBOOLEAN, true);
}
Pseudo *condition_pseudo = linearize_expression(proc, node->while_or_repeat_stmt.condition);
if (node->type == STMT_REPEAT) {
condition_pseudo = linearize_negate_condition(proc, node->line_number, condition_pseudo, neg_condition_pseudo);
}
instruct_cbr(proc, condition_pseudo, body_block, end_block, node->line_number);
free_temp_pseudo(proc, condition_pseudo, false);

start_block(proc, body_block, node->line_number);
start_scope(proc->linearizer, proc, node->while_or_repeat_stmt.loop_scope);
if (node->type != STMT_REPEAT) {
start_scope(proc->linearizer, proc, node->while_or_repeat_stmt.loop_scope);
}
linearize_statement_list(proc, node->while_or_repeat_stmt.loop_statement_list);
end_scope(proc->linearizer, proc, node->line_number);

Expand Down
8 changes: 8 additions & 0 deletions tests/comptests/inputs/78_repeat.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
local i = 0
repeat
i = i + 1
until i == 10

assert(i == 10)

print '78 Ok'
24 changes: 12 additions & 12 deletions tests/comptests/inputs/lua-Harness-014-fornum.t
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ L<https://www.lua.org/manual/5.4/manual.html#3.3.5>

print("1..36")

for i = 1.0, 3.0, 0.5 do
print("ok " .. tostring(2*i-1) .. " - for 1.0, 3.0, 0.5")
end
--for i = 1.0, 3.0, 0.5 do
-- print("ok " .. tostring(2*i-1) .. " - for 1.0, 3.0, 0.5")
--end

for i = 1.0, 3.0, 0.5 do
local function f ()
print("ok " .. tostring(2*i+4) .. " - for 1.0, 3.0, 0.5 lex")
end
f()
end
--for i = 1.0, 3.0, 0.5 do
-- local function f ()
-- print("ok " .. tostring(2*i+4) .. " - for 1.0, 3.0, 0.5 lex")
-- end
-- f()
--end

local function f (i)
print("ok " .. tostring(2*i+9) .. " - for 1.0, 3.0, 0.5 !lex")
end
for i = 1.0, 3.0, 0.5 do
f(i)
end
--for i = 1.0, 3.0, 0.5 do
-- f(i)
--end

for i = 3, 5 do
print("ok " .. tostring(13+i) .. " - for 3, 5")
Expand Down
7 changes: 4 additions & 3 deletions tests/comptests/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dofile("inputs/51_concat.lua")
dofile("inputs/52_local_s.lua")

function runfile(file)
--local f = compiler.loadfile(file, "--verbose --dump-ir")
local f = compiler.loadfile(file)
assert(f and type(f) == 'function')
f()
Expand Down Expand Up @@ -84,12 +85,12 @@ runfile("inputs/74_luajit_andor.lua")
runfile("inputs/75_genericfor_locals.lua")
runfile("inputs/76_genericfor_nested.lua")
runfile("inputs/77_luajit_andor_mult.lua")

runfile("inputs/78_repeat.lua")
runfile("inputs/lua-Harness-001-if.t")
runfile("inputs/lua-Harness-002-table.t")
runfile("inputs/lua-Harness-011-while.t")
--runfile("inputs/lua-Harness-012-repeat.t")
--runfile("inputs/lua-Harness-014-fornum.t")
runfile("inputs/lua-Harness-012-repeat.t")
runfile("inputs/lua-Harness-014-fornum.t")
runfile("inputs/lua-Harness-015-forlist.t")
runfile("inputs/lua-Harness-101-boolean.t")
runfile("inputs/lua-Harness-102-function.t")
Expand Down

0 comments on commit acb7738

Please sign in to comment.