Skip to content

makepad-stitch evaluates an incorrect result #3

@Robbepop

Description

@Robbepop

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions