MVP #1

Merged
jbwdevries merged 73 commits from idea_crc32 into master 2022-08-21 12:59:21 +00:00
2 changed files with 41 additions and 0 deletions
Showing only changes of commit 249c00f6a2 - Show all commits

View File

@ -91,6 +91,24 @@ class Visitor:
]
))
# We create functions for these special instructions
# We'll let a future inline optimizer clean this up for us
# TODO: Either a) make a sqrt32 and a sqrt64;
# or b) decide to make the whole language auto-cast
module.functions.append(wasm.Function(
'sqrt',
False,
[
('z', self._type_map['f32']),
],
[],
self._type_map['f32'],
[
wasm.Statement('local.get', '$z'),
wasm.Statement('f32.sqrt'),
]
))
# Do a check first for all function definitions
# to get their types. Otherwise you cannot call
# a method that you haven't defined just yet,
@ -404,6 +422,10 @@ class Visitor:
yield wasm.Statement('{}.add'.format(exp_type.to_wasm()))
return
if isinstance(node.op, ast.Mult):
yield wasm.Statement('{}.mul'.format(exp_type.to_wasm()))
return
if isinstance(node.op, ast.Sub):
yield wasm.Statement('{}.sub'.format(exp_type.to_wasm()))
return

View File

@ -334,3 +334,22 @@ def helper(vector: Tuple[i32, i32, i32]) -> i32:
assert 161 == result.returned_value
assert [] == result.log_int32_list
@pytest.mark.integration_test
def test_tuple_float():
code_py = """
@exported
def testEntry() -> f32:
return helper((1, 2, 3, ))
def helper(v: Tuple[f32, f32, f32]) -> f32:
# sqrt is guaranteed by wasm, so we can use it
# ATM it's a 32 bit variant, but that might change.
return sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2])
"""
result = Suite(code_py, 'test_call').run_code()
assert 3.74 < result.returned_value < 3.75
assert [] == result.log_int32_list