Updated main, buffer, added test
This commit is contained in:
parent
750f8806b6
commit
2ab574706f
@ -3,5 +3,5 @@ def index(inp: bytes, idx: u32) -> u8:
|
|||||||
return inp[idx]
|
return inp[idx]
|
||||||
|
|
||||||
@exported
|
@exported
|
||||||
def length(inp: bytes) -> i32:
|
def length(inp: bytes) -> u32:
|
||||||
return len(inp)
|
return len(inp)
|
||||||
|
|||||||
@ -5,6 +5,7 @@ Functions for using this module from CLI
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from .parser import phasm_parse
|
from .parser import phasm_parse
|
||||||
|
from .type3.entry import phasm_type3
|
||||||
from .compiler import phasm_compile
|
from .compiler import phasm_compile
|
||||||
|
|
||||||
def main(source: str, sink: str) -> int:
|
def main(source: str, sink: str) -> int:
|
||||||
@ -16,6 +17,7 @@ def main(source: str, sink: str) -> int:
|
|||||||
code_py = fil.read()
|
code_py = fil.read()
|
||||||
|
|
||||||
our_module = phasm_parse(code_py)
|
our_module = phasm_parse(code_py)
|
||||||
|
phasm_type3(our_module, verbose=False)
|
||||||
wasm_module = phasm_compile(our_module)
|
wasm_module = phasm_compile(our_module)
|
||||||
code_wat = wasm_module.to_wat()
|
code_wat = wasm_module.to_wat()
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,7 @@ class Suite:
|
|||||||
def __init__(self, code_py):
|
def __init__(self, code_py):
|
||||||
self.code_py = code_py
|
self.code_py = code_py
|
||||||
|
|
||||||
def run_code(self, *args, runtime='pywasm3', imports=None):
|
def run_code(self, *args, runtime='pywasm3', func_name='testEntry', imports=None):
|
||||||
"""
|
"""
|
||||||
Compiles the given python code into wasm and
|
Compiles the given python code into wasm and
|
||||||
then runs it
|
then runs it
|
||||||
@ -74,7 +74,7 @@ class Suite:
|
|||||||
runner.interpreter_dump_memory(sys.stderr)
|
runner.interpreter_dump_memory(sys.stderr)
|
||||||
|
|
||||||
result = SuiteResult()
|
result = SuiteResult()
|
||||||
result.returned_value = runner.call('testEntry', *wasm_args)
|
result.returned_value = runner.call(func_name, *wasm_args)
|
||||||
|
|
||||||
write_header(sys.stderr, 'Memory (post run)')
|
write_header(sys.stderr, 'Memory (post run)')
|
||||||
runner.interpreter_dump_memory(sys.stderr)
|
runner.interpreter_dump_memory(sys.stderr)
|
||||||
|
|||||||
19
tests/integration/test_examples/test_buffer.py
Normal file
19
tests/integration/test_examples/test_buffer.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from ..helpers import Suite
|
||||||
|
|
||||||
|
@pytest.mark.slow_integration_test
|
||||||
|
def test_index():
|
||||||
|
with open('examples/buffer.py', 'r', encoding='ASCII') as fil:
|
||||||
|
code_py = "\n" + fil.read()
|
||||||
|
|
||||||
|
result = Suite(code_py).run_code(b'Hello, world!', 5, func_name='index', runtime='wasmtime')
|
||||||
|
assert 44 == result.returned_value
|
||||||
|
|
||||||
|
@pytest.mark.slow_integration_test
|
||||||
|
def test_length():
|
||||||
|
with open('examples/buffer.py', 'r', encoding='ASCII') as fil:
|
||||||
|
code_py = "\n" + fil.read()
|
||||||
|
|
||||||
|
result = Suite(code_py).run_code(b'Hello, world!', func_name='length')
|
||||||
|
assert 13 == result.returned_value
|
||||||
Loading…
x
Reference in New Issue
Block a user