Learning about stacks and locals [skip-ci]
This commit is contained in:
parent
541b3a3b62
commit
6932741ac5
@ -7,13 +7,13 @@ from pywasm import Runtime
|
||||
|
||||
from .helpers import wat2wasm
|
||||
|
||||
@pytest.mark.parametrize('size,offset,output', [
|
||||
@pytest.mark.parametrize('size,offset,exp_out_put', [
|
||||
('32', 0, 0x3020100),
|
||||
('32', 1, 0x4030201),
|
||||
('64', 0, 0x706050403020100),
|
||||
('64', 2, 0x908070605040302),
|
||||
])
|
||||
def test_i32_64_load(size, offset, output):
|
||||
def test_i32_64_load(size, offset, exp_out_put):
|
||||
code_wat = f"""
|
||||
(module
|
||||
(memory 1)
|
||||
@ -30,4 +30,40 @@ def test_i32_64_load(size, offset, output):
|
||||
runtime = Runtime(module, {}, {})
|
||||
|
||||
out_put = runtime.exec('testEntry', [])
|
||||
assert output == out_put
|
||||
assert exp_out_put == out_put
|
||||
|
||||
def test_load_then_store():
|
||||
code_wat = """
|
||||
(module
|
||||
(memory 1)
|
||||
(data (memory 0) (i32.const 0) "\\04\\00\\00\\00")
|
||||
|
||||
(func (export "testEntry") (result i32) (local $my_memory_value i32)
|
||||
;; Load i32 from address 0
|
||||
i32.const 0
|
||||
i32.load
|
||||
|
||||
;; Add 8 to the loaded value
|
||||
i32.const 8
|
||||
i32.add
|
||||
|
||||
local.set $my_memory_value
|
||||
|
||||
;; Store back to the memory
|
||||
i32.const 0
|
||||
local.get $my_memory_value
|
||||
i32.store
|
||||
|
||||
;; Return something
|
||||
i32.const 9
|
||||
return ))
|
||||
"""
|
||||
code_wasm = wat2wasm(code_wat)
|
||||
module = binary.Module.from_reader(io.BytesIO(code_wasm))
|
||||
|
||||
runtime = Runtime(module, {}, {})
|
||||
|
||||
out_put = runtime.exec('testEntry', [])
|
||||
assert 9 == out_put
|
||||
|
||||
assert (b'\x0c'+ b'\00' * 23) == runtime.store.mems[0].data[:24]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user