Skip to content

Commit

Permalink
#198 #244 fix issue with cbr when condition is range select pseudo
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Jun 12, 2022
1 parent 3818d9d commit 486bab4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ravicomp/src/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ size_t raviX_del_array_element(void *a, size_t element_size, size_t array_size,
assert(i + n <= array_size);
char *p = (char *)a;
char *dest = p + i * element_size;
char *src = p + (i + n) * element_size;
char const *src = p + (i + n) * element_size;
size_t count = element_size * (array_size - n - i);
memmove(dest, src, count);
size_t new_array_size = array_size - n;
Expand Down
2 changes: 1 addition & 1 deletion ravicomp/src/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ static int emit_op_cbr(Function *fn, Instruction *insn)
raviX_buffer_add_fstring(&fn->body, " != 0) goto L%d;", get_target(insn, 0)->block->index);
raviX_buffer_add_fstring(&fn->body, " else goto L%d; ", get_target(insn, 1)->block->index);
raviX_buffer_add_string(&fn->body, "}\n");
} else if (cond_pseudo->type == PSEUDO_TEMP_ANY || cond_pseudo->type == PSEUDO_SYMBOL) {
} else if (cond_pseudo->type == PSEUDO_TEMP_ANY || cond_pseudo->type == PSEUDO_SYMBOL || cond_pseudo->type == PSEUDO_RANGE_SELECT) {
raviX_buffer_add_string(&fn->body, "{\nconst TValue *src_reg = ");
emit_reg_accessor(fn, cond_pseudo, 0);
raviX_buffer_add_fstring(&fn->body, ";\nif (!l_isfalse(src_reg)) goto L%d;\n",
Expand Down
19 changes: 19 additions & 0 deletions tests/comptests/inputs/58_cbr.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function test()
local myPlayer = getMyPlayer()
if ( myPlayer:Alive() ) then
return true
end
return false
end

function getMyPlayer()
local player = {}
function player:Alive()
return 1
end
return player
end

assert(test())

print '58 Ok'
1 change: 1 addition & 0 deletions tests/comptests/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ runfile("inputs/54_embed_C.lua")
runfile("inputs/55_embed_C.lua")
runfile("inputs/56_embed_C.lua")
runfile("inputs/57_embed_C.lua")
runfile("inputs/58_cbr.lua")

print 'SUCCESS'

0 comments on commit 486bab4

Please sign in to comment.