test.wat 858 B

12345678910111213141516171819202122232425262728293031
  1. ;; define different reference types
  2. (type $struct_a (struct (field (mut i32))))
  3. (type $struct_b (struct (field (mut i64))))
  4. (type $struct_c (struct (field (mut i32)) (field (mut i32))))
  5. (func $main
  6. ;; prepare parameters: i32, ref_a, i32, ref_b
  7. (i32.const 10)
  8. (struct.new $struct_a (i32.const 100))
  9. (i32.const 20)
  10. (struct.new $struct_b (i64.const 200))
  11. ;; block with interleaved parameters: i32, ref_a, i32, ref_b -> ref_c
  12. (block (param i32 (ref $struct_a) i32 (ref $struct_b)) (result (ref $struct_c))
  13. ;; clean up parameters from stack
  14. drop ;; drop ref_b
  15. drop ;; drop i32
  16. drop ;; drop ref_a
  17. drop ;; drop i32
  18. ;; return new type reference struct_c
  19. (struct.new $struct_c (i32.const 300) (i32.const 400))
  20. )
  21. ;; drop return value
  22. drop
  23. )
  24. (memory 1)
  25. (export "memory" (memory 0))
  26. (export "_start" (func $main))