Skip to content

Commit

Permalink
Implement stack functions like in Emscripten, fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jeroen Bobbeldijk <[email protected]>
  • Loading branch information
jerbob92 committed Aug 9, 2023
1 parent 140b7a1 commit f95ece8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
20 changes: 10 additions & 10 deletions imports/emscripten/emscripten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func TestInstantiateForModule(t *testing.T) {
expectedLog: `--> .call_v_i32(0)
==> env.invoke_i(index=0)
--> .stackSave()
<-- 0
<-- 65536
--> .v_i32()
<-- 42
<== 42
Expand All @@ -387,7 +387,7 @@ func TestInstantiateForModule(t *testing.T) {
expectedLog: `--> .call_i32_i32(2,42)
==> env.invoke_ii(index=2,a1=42)
--> .stackSave()
<-- 0
<-- 65536
--> .i32_i32(42)
<-- 42
<== 42
Expand All @@ -403,7 +403,7 @@ func TestInstantiateForModule(t *testing.T) {
expectedLog: `--> .call_i32i32_i32(4,1,2)
==> env.invoke_iii(index=4,a1=1,a2=2)
--> .stackSave()
<-- 0
<-- 65536
--> .i32i32_i32(1,2)
<-- 3
<== 3
Expand All @@ -419,7 +419,7 @@ func TestInstantiateForModule(t *testing.T) {
expectedLog: `--> .call_i32i32i32_i32(6,1,2,4)
==> env.invoke_iiii(index=6,a1=1,a2=2,a3=4)
--> .stackSave()
<-- 0
<-- 65536
--> .i32i32i32_i32(1,2,4)
<-- 7
<== 7
Expand All @@ -435,7 +435,7 @@ func TestInstantiateForModule(t *testing.T) {
expectedLog: `--> .calli32_i32i32i32i32_i32(8,1,2,4,8)
==> env.invoke_iiiii(index=8,a1=1,a2=2,a3=4,a4=8)
--> .stackSave()
<-- 0
<-- 65536
--> .i32i32i32i32_i32(1,2,4,8)
<-- 15
<== 15
Expand All @@ -449,7 +449,7 @@ func TestInstantiateForModule(t *testing.T) {
expectedLog: `--> .call_v_v(10)
==> env.invoke_v(index=10)
--> .stackSave()
<-- 0
<-- 65536
--> .v_v()
<--
<==
Expand All @@ -464,7 +464,7 @@ func TestInstantiateForModule(t *testing.T) {
expectedLog: `--> .call_i32_v(12,42)
==> env.invoke_vi(index=12,a1=42)
--> .stackSave()
<-- 0
<-- 65536
--> .i32_v(42)
<--
<==
Expand All @@ -479,7 +479,7 @@ func TestInstantiateForModule(t *testing.T) {
expectedLog: `--> .call_i32i32_v(14,1,2)
==> env.invoke_vii(index=14,a1=1,a2=2)
--> .stackSave()
<-- 0
<-- 65536
--> .i32i32_v(1,2)
<--
<==
Expand All @@ -494,7 +494,7 @@ func TestInstantiateForModule(t *testing.T) {
expectedLog: `--> .call_i32i32i32_v(16,1,2,4)
==> env.invoke_viii(index=16,a1=1,a2=2,a3=4)
--> .stackSave()
<-- 0
<-- 65536
--> .i32i32i32_v(1,2,4)
<--
<==
Expand All @@ -509,7 +509,7 @@ func TestInstantiateForModule(t *testing.T) {
expectedLog: `--> .calli32_i32i32i32i32_v(18,1,2,4,8)
==> env.invoke_viiii(index=18,a1=1,a2=2,a3=4,a4=8)
--> .stackSave()
<-- 0
<-- 65536
--> .i32i32i32i32_v(1,2,4,8)
<--
<==
Expand Down
Binary file modified imports/emscripten/testdata/invoke.wasm
Binary file not shown.
9 changes: 7 additions & 2 deletions imports/emscripten/testdata/invoke.wat
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@

(table 20 20 funcref)

(func $stackSave (export "stackSave") (result i32) (i32.const 0))
(func $stackRestore (export "stackRestore") (param i32))
(global $__stack_pointer (mut i32) (i32.const 65536))
(func $stackSave (export "stackSave") (result i32)
global.get $__stack_pointer)
(func $stackRestore (export "stackRestore") (param i32)
local.get 0
global.set $__stack_pointer)
(func $setThrew (export "setThrew") (param i32 i32))

(func $v_i32 (result i32) (i32.const 42))
(func $v_i32_unreachable (result i32) unreachable)
Expand Down

0 comments on commit f95ece8

Please sign in to comment.