File: adapter.wast

package info (click to toggle)
rust-wasmtime 26.0.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 48,492 kB
  • sloc: ansic: 4,003; sh: 561; javascript: 542; cpp: 254; asm: 175; ml: 96; makefile: 55
file content (135 lines) | stat: -rw-r--r-- 2,960 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
;; basic function lifting
(component
  (core module $m
    (func (export ""))
  )
  (core instance $i (instantiate $m))

  (func (export "thunk")
    (canon lift (core func $i ""))
  )
)

;; use an aliased type
(component $c
  (core module $m
    (func (export ""))
  )
  (core instance $i (instantiate $m))

  (type $to_alias (func))
  (alias outer $c $to_alias (type $alias))

  (func (export "thunk") (type $alias)
    (canon lift (core func $i ""))
  )
)

;; test out some various canonical abi
(component $c
  (core module $m
    (func (export "") (param i32 i32))
    (memory (export "memory") 1)
    (func (export "realloc") (param i32 i32 i32 i32) (result i32)
      unreachable)
  )
  (core instance $i (instantiate $m))

  (func (export "thunk") (param "a" string)
    (canon lift
      (core func $i "")
      (memory $i "memory")
      (realloc (func $i "realloc"))
    )
  )

  (func (export "thunk8") (param "a" string)
    (canon lift
      (core func $i "")
      string-encoding=utf8
      (memory $i "memory")
      (realloc (func $i "realloc"))
    )
  )

  (func (export "thunk16") (param "a" string)
    (canon lift
      (core func $i "")
      string-encoding=utf16
      (memory $i "memory")
      (realloc (func $i "realloc"))
    )
  )

  (func (export "thunklatin16") (param "a" string)
    (canon lift
      (core func $i "")
      string-encoding=latin1+utf16
      (memory $i "memory")
      (realloc (func $i "realloc"))
    )
  )
)

;; lower something then immediately lift it
(component $c
  (import "host-return-two" (func $f (result u32)))

  (core func $f_lower
    (canon lower (func $f))
  )
  (func $f2 (result s32)
    (canon lift (core func $f_lower))
  )
  (export "f" (func $f2))
)

;; valid, but odd
(component
  (core module $m (func (export "")))
  (core instance $m (instantiate $m))

  (func $f1 (canon lift (core func $m "")))
  (core func $f2 (canon lower (func $f1)))
)
(assert_trap
  (component
    (core module $m (func (export "")))
    (core instance $m (instantiate $m))

    (func $f1 (canon lift (core func $m "")))
    (core func $f2 (canon lower (func $f1)))

    (core module $m2
      (import "" "" (func $f))
      (func $start
        call $f)
      (start $start)
    )
    (core instance (instantiate $m2
      (with "" (instance (export "" (func $f2))))
    ))
  )
  "degenerate component adapter called")

;; fiddling with 0-sized lists
(component $c
  (core module $m
    (func (export "x") (param i32 i32))
    (func (export "realloc") (param i32 i32 i32 i32) (result i32)
      i32.const -1)
    (memory (export "memory") 0)
  )
  (core instance $m (instantiate $m))
  (type $t' (result))
  (export $t "t" (type $t'))
  (func $f (param "a" (list $t))
    (canon lift
      (core func $m "x")
      (realloc (func $m "realloc"))
      (memory $m "memory")
    )
  )
  (export "empty-list" (func $f))
)
(assert_trap (invoke "empty-list" (list.const)) "realloc return: beyond end of memory")