(module

  ;; import js func print (op1, op2, op, result)  

  (func $print (import "js" "print") (param $op1 i32) (param $op2 i32) (param $op i32) (param $result i32))

  ;; int32 add (int32 x, int32 y)
  (func $add (param $x i32) (param $y i32) (result i32)
    local.get $x
    local.get $y
    i32.add)


  ;; int32 sub(int32 x, int32 y)
  (func $sub (param $x i32) (param $y i32) (result i32)
    local.get $x
    local.get $y
    i32.sub)


  ;; int32 mul(int32 x, int32 y)
  (func $mul (param $x i32) (param $y i32) (result i32)
    local.get $x
    local.get $y
    i32.mul)


   ;; int32 div(int32 x, int32 y)
   (func $div (param $x i32) (param $y i32) (result i32)
    local.get $x
    local.get $y
    i32.div_u)

   (func $main
    ;; call print(1, 2, add(1,2), 1)
    i32.const 1
    i32.const 2
    i32.const 1

    i32.const 1
    i32.const 2
    call $add
    call $print

    ;; call print(1, 2, sub(1,2), 2)
    i32.const 1
    i32.const 2
    i32.const 2

    i32.const 1
    i32.const 2
    call $sub
    call $print

    ;; call print(1, 2, mul(1,2), 3)
    i32.const 1
    i32.const 2
    i32.const 3

    i32.const 1
    i32.const 2
    call $mul
    call $print

    ;; call print(1, 2, div(1,2), 4)
    i32.const 1
    i32.const 2
    i32.const 4

    i32.const 1
    i32.const 2
    call $div
    call $print
   )

   (start $main)
)

