nested_struct_field_any.wat 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. (module
  2. (type $struct_type (struct (field (mut i32)) (field (mut anyref))))
  3. (global $g_struct
  4. (mut (ref $struct_type))
  5. (struct.new $struct_type
  6. (i32.const 10)
  7. (struct.new $struct_type
  8. (i32.const 20)
  9. (struct.new_default $struct_type)
  10. )
  11. )
  12. )
  13. ;; assert_return(invoke "get_field1"), 10)
  14. (func (export "get_field1") (result i32)
  15. (struct.get $struct_type 0 (global.get $g_struct))
  16. )
  17. ;; assert_return(invoke "get_field1"), struct.new $struct_type ...)
  18. (func (export "get_field2") (result anyref)
  19. (struct.get $struct_type 1 (global.get $g_struct))
  20. )
  21. ;; assert_return(invoke "get_field2_field1"), 20)
  22. (func (export "get_field2_field1") (result i32)
  23. (struct.get $struct_type 0
  24. (ref.cast structref
  25. (struct.get $struct_type 1 (global.get $g_struct))
  26. )
  27. )
  28. )
  29. ;; assert_return(invoke "get_field2_field2"), struct.new_default $struct_type ...)
  30. (func (export "get_field2_field2") (result anyref)
  31. (struct.get $struct_type 1
  32. (ref.cast structref
  33. (struct.get $struct_type 1 (global.get $g_struct))
  34. )
  35. )
  36. )
  37. ;; assert_return(invoke "get_field2_field2_field1"), 0)
  38. (func (export "get_field2_field2_field1") (result i32)
  39. (struct.get $struct_type 0
  40. (ref.cast structref
  41. (struct.get $struct_type 1
  42. (ref.cast structref
  43. (struct.get $struct_type 1 (global.get $g_struct))
  44. )
  45. )
  46. )
  47. )
  48. )
  49. )