Simple calls

This commit is contained in:
Johan B.W. de Vries 2022-06-19 15:25:58 +02:00
parent 83b0b705ae
commit 9dbdb11732
2 changed files with 24 additions and 0 deletions

View File

@ -82,6 +82,13 @@ def expression(inp: ourlang.Expression) -> Statements:
raise NotImplementedError(expression, inp.type, inp.operator)
if isinstance(inp, ourlang.FunctionCall):
for arg in inp.arguments:
yield from expression(arg)
yield wasm.Statement('call', '${}'.format(inp.function.name))
return
raise NotImplementedError(expression, inp)
def statement_return(inp: ourlang.StatementReturn) -> Statements:

View File

@ -225,6 +225,23 @@ def helper(left: i32, right: i32) -> i32:
assert 7 == result.returned_value
assert [] == result.log_int32_list
@pytest.mark.integration_test
@pytest.mark.parametrize('type_', ['i32', 'i64', 'f32', 'f64'])
def test_call_with_expression(type_):
code_py = f"""
@exported
def testEntry() -> {type_}:
return helper(10 + 20, 3 + 5)
def helper(left: {type_}, right: {type_}) -> {type_}:
return left - right
"""
result = Suite(code_py, 'test_call').run_code()
assert 22 == result.returned_value
assert TYPE_MAP[type_] == type(result.returned_value)
@pytest.mark.integration_test
@pytest.mark.skip('Not yet implemented')
def test_assign():