The makepad-stitch interpreter evaluates the following .wast script incorrectly:
(module
(func (export "run") (param $cond i32) (param $x i32) (result i32)
(drop
(i32.add
(local.get $x)
(i32.const 10)
)
)
(local.get $x)
(block
(local.get $cond)
(br_if 0)
(local.set $x (i32.const 1))
)
)
)
(assert_return
(invoke "run" (i32.const 1) (i32.const 42))
(i32.const 42)
)
What happens:
(local.get $x) puts $x on the stack.
(br_if 0) breaks out of block before (local.set $x (i32.const 1)) since $cond is 1
- thus it is expected that
$x is still on the stack. however, makepad-stitch always just returns 0.
- for
$cond = 0 makepad-stitch actually returns $x back.
I have looked into makepad-stitch's code and think it might have to do with the fact that not all local variables on the stack are preserved (copied to temp stack slots) when entering a control frame such as block, if and loop.
I tested this manually with makepad-stitch's CLI tool installed via cargo install makepad-stitch.
cc @ejpbruel2
The
makepad-stitchinterpreter evaluates the following.wastscript incorrectly:What happens:
(local.get $x)puts$xon the stack.(br_if 0)breaks out ofblockbefore(local.set $x (i32.const 1))since$condis1$xis still on the stack. however,makepad-stitchalways just returns0.$cond = 0makepad-stitchactually returns$xback.I have looked into
makepad-stitch's code and think it might have to do with the fact that not all local variables on the stack are preserved (copied to temp stack slots) when entering a control frame such asblock,ifandloop.I tested this manually with
makepad-stitch's CLI tool installed viacargo install makepad-stitch.cc @ejpbruel2