Skip to content

Commit

Permalink
issue #163 fix bugs - wrong type associated with the LLVM definition …
Browse files Browse the repository at this point in the history
…of raviV_op_defer()
  • Loading branch information
dibyendumajumdar committed Oct 12, 2019
1 parent d6c70d2 commit 67970bc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
44 changes: 44 additions & 0 deletions ravi-tests/ravi_tests1.ravi
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ opcodes_coverage.TOTYPE = 0
opcodes_coverage.TOSTRING = 0
opcodes_coverage.TOCLOSURE = 0
opcodes_coverage.SELF_SK = 0
opcodes_coverage.DEFER = 0

local compile = function(f)
if ravi.jit() then
Expand Down Expand Up @@ -1727,6 +1728,49 @@ compile(x)
assert(x(2,3) == 2^3)
print 'Test 77 OK'

-- Test defer statement
y = 0
function x()
defer y = y + 1 end
defer y = y + 1 end
end
check(x, 'DEFER', 'CLOSURE', 'DEFER', 'CLOSURE', 'RETURN')
x()
assert(y == 2)
compile(x)
x()
assert(y == 4)
print 'Test 78 OK'

-- Test defer statement
y = 0
function x()
defer y = y + 1 end
error('raise error')
defer y = y + 2 end -- will not be called
end
pcall(x)
assert(y == 1)
compile(x)
pcall(x)
assert(y == 2)
print 'Test 79 OK'

-- Test defer statement
y = 0
function x()
defer y = y + 1 end
defer y = y + 2; error('err') end
defer y = y + 3 end
end
pcall(x)
assert(y == 6)
compile(x)
pcall(x)
assert(y == 12)
print 'Test 80 OK'


for k,v in pairs(opcodes_coverage)
do
print(k, v)
Expand Down
1 change: 1 addition & 0 deletions ravi-tests/ravi_tests2.ravi
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ opcodes_coverage.TABLE_SELF_SK = 0
opcodes_coverage.TOTYPE = 0
opcodes_coverage.TOSTRING = 0
opcodes_coverage.TOCLOSURE = 0
opcodes_coverage.DEFER = 0

--ravi.verbosity(1)

Expand Down
2 changes: 1 addition & 1 deletion src/ravi_llvmcodegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ void RaviCodeGenerator::emit_extern_declarations(RaviFunctionDef *def) {
def->types->raviV_op_totypeT, reinterpret_cast<void *>(&raviV_op_totype),
"raviV_op_totype");
def->raviV_op_deferF = def->raviF->addExternFunction(
def->types->raviV_op_totypeT, reinterpret_cast<void *>(&raviV_op_defer),
def->types->raviV_op_deferT, reinterpret_cast<void *>(&raviV_op_defer),
"raviV_op_defer");

def->ravi_dump_valueF = def->raviF->addExternFunction(
Expand Down

0 comments on commit 67970bc

Please sign in to comment.