|
16 | 16 | (import "" "stream.new" (func $stream.new (result i64))) |
17 | 17 | (import "" "stream.read" (func $stream.read (param i32 i32 i32) (result i32))) |
18 | 18 | (import "" "stream.write" (func $stream.write (param i32 i32 i32) (result i32))) |
| 19 | + (import "" "future.newb" (func $future.newb (result i64))) |
| 20 | + (import "" "future.readb" (func $future.readb (param i32 i32) (result i32))) |
| 21 | + (import "" "future.writeb" (func $future.writeb (param i32 i32) (result i32))) |
| 22 | + (import "" "stream.newb" (func $stream.newb (result i64))) |
| 23 | + (import "" "stream.readb" (func $stream.readb (param i32 i32 i32) (result i32))) |
| 24 | + (import "" "stream.writeb" (func $stream.writeb (param i32 i32 i32) (result i32))) |
19 | 25 | (import "" "future.newc" (func $future.newc (result i64))) |
20 | 26 | (import "" "future.readc" (func $future.readc (param i32 i32) (result i32))) |
21 | 27 | (import "" "future.writec" (func $future.writec (param i32 i32) (result i32))) |
|
74 | 80 | (i32.const 42) |
75 | 81 | ) |
76 | 82 |
|
| 83 | + (func $test-stream (param $srcp i32) (param $dstp i32) |
| 84 | + (local $ret i32) (local $ret64 i64) |
| 85 | + (local $rx i32) (local $tx i32) |
| 86 | + |
| 87 | + ;; test stream reader then writer |
| 88 | + (i64.store (local.get $dstp) (i64.const 0)) |
| 89 | + (i64.store (local.get $srcp) (i64.const 0x0123456789abcdef)) |
| 90 | + (local.set $ret64 (call $stream.newb)) |
| 91 | + (local.set $rx (i32.wrap_i64 (local.get $ret64))) |
| 92 | + (local.set $tx (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32)))) |
| 93 | + (local.set $ret (call $stream.readb (local.get $rx) (local.get $dstp) (i32.const 8))) |
| 94 | + (if (i32.ne (i32.const -1 (; BLOCKED ;)) (local.get $ret)) |
| 95 | + (then unreachable)) |
| 96 | + (local.set $ret (call $stream.writeb (local.get $tx) (local.get $srcp) (i32.const 8))) |
| 97 | + (if (i32.ne (i32.const 0x80 (; COMPLETED=0 | (8<<4) ;)) (local.get $ret)) |
| 98 | + (then unreachable)) |
| 99 | + (if (i64.ne (i64.load (local.get $dstp)) (i64.const 0x0123456789abcdef)) |
| 100 | + (then unreachable)) |
| 101 | + |
| 102 | + ;; test stream writer than reader |
| 103 | + (i64.store (local.get $dstp) (i64.const 0)) |
| 104 | + (i64.store (local.get $srcp) (i64.const 0x0123456789abcdef)) |
| 105 | + (local.set $ret64 (call $stream.newb)) |
| 106 | + (local.set $rx (i32.wrap_i64 (local.get $ret64))) |
| 107 | + (local.set $tx (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32)))) |
| 108 | + (local.set $ret (call $stream.writeb (local.get $tx) (local.get $srcp) (i32.const 8))) |
| 109 | + (if (i32.ne (i32.const -1 (; BLOCKED ;)) (local.get $ret)) |
| 110 | + (then unreachable)) |
| 111 | + (local.set $ret (call $stream.readb (local.get $rx) (local.get $dstp) (i32.const 8))) |
| 112 | + (if (i32.ne (i32.const 0x80 (; COMPLETED=0 | (8<<4) ;)) (local.get $ret)) |
| 113 | + (then unreachable)) |
| 114 | + (if (i64.ne (i64.load (local.get $dstp)) (i64.const 0x0123456789abcdef)) |
| 115 | + (then unreachable)) |
| 116 | + ) |
| 117 | + |
| 118 | + (func (export "test-bytes") (result i32) |
| 119 | + (local $ret i32) (local $ret64 i64) |
| 120 | + (local $rx i32) (local $tx i32) |
| 121 | + (local $dstp i32) (local $srcp i32) |
| 122 | + |
| 123 | + ;; because pointers must be aligned and futures are single-element, |
| 124 | + ;; it's not possible to test the interesting overlap case |
| 125 | + (local.set $srcp (i32.const 16)) |
| 126 | + (local.set $dstp (i32.const 17)) |
| 127 | + (i32.store8 (local.get $dstp) (i32.const 0)) |
| 128 | + (i32.store8 (local.get $srcp) (i32.const 42)) |
| 129 | + |
| 130 | + ;; test future reader then writer |
| 131 | + (local.set $ret64 (call $future.newb)) |
| 132 | + (local.set $rx (i32.wrap_i64 (local.get $ret64))) |
| 133 | + (local.set $tx (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32)))) |
| 134 | + (local.set $ret (call $future.readb (local.get $rx) (local.get $dstp))) |
| 135 | + (if (i32.ne (i32.const -1 (; BLOCKED ;)) (local.get $ret)) |
| 136 | + (then unreachable)) |
| 137 | + (local.set $ret (call $future.writeb (local.get $tx) (local.get $srcp))) |
| 138 | + (if (i32.ne (i32.const 0 (; COMPLETED ;)) (local.get $ret)) |
| 139 | + (then unreachable)) |
| 140 | + (if (i32.ne (i32.load8_u (local.get $dstp)) (i32.const 42)) |
| 141 | + (then unreachable)) |
| 142 | + |
| 143 | + ;; reset memory and then test future writer than reader |
| 144 | + (i32.store8 (local.get $dstp) (i32.const 0)) |
| 145 | + (i32.store8 (local.get $srcp) (i32.const 42)) |
| 146 | + (local.set $ret64 (call $future.newb)) |
| 147 | + (local.set $rx (i32.wrap_i64 (local.get $ret64))) |
| 148 | + (local.set $tx (i32.wrap_i64 (i64.shr_u (local.get $ret64) (i64.const 32)))) |
| 149 | + (local.set $ret (call $future.writeb (local.get $tx) (local.get $srcp))) |
| 150 | + (if (i32.ne (i32.const -1 (; BLOCKED ;)) (local.get $ret)) |
| 151 | + (then unreachable)) |
| 152 | + (local.set $ret (call $future.readb (local.get $rx) (local.get $dstp))) |
| 153 | + (if (i32.ne (i32.const 0 (; COMPLETED ;)) (local.get $ret)) |
| 154 | + (then unreachable)) |
| 155 | + (if (i32.ne (i32.load8_u (local.get $dstp)) (i32.const 42)) |
| 156 | + (then unreachable)) |
| 157 | + |
| 158 | + ;; test a bunch of different overlapping cases |
| 159 | + (call $test-stream (i32.const 16) (i32.const 8)) |
| 160 | + (call $test-stream (i32.const 16) (i32.const 9)) |
| 161 | + (call $test-stream (i32.const 16) (i32.const 10)) |
| 162 | + (call $test-stream (i32.const 16) (i32.const 11)) |
| 163 | + (call $test-stream (i32.const 16) (i32.const 12)) |
| 164 | + (call $test-stream (i32.const 16) (i32.const 13)) |
| 165 | + (call $test-stream (i32.const 16) (i32.const 14)) |
| 166 | + (call $test-stream (i32.const 16) (i32.const 15)) |
| 167 | + (call $test-stream (i32.const 16) (i32.const 16)) |
| 168 | + (call $test-stream (i32.const 16) (i32.const 17)) |
| 169 | + (call $test-stream (i32.const 16) (i32.const 18)) |
| 170 | + (call $test-stream (i32.const 16) (i32.const 19)) |
| 171 | + (call $test-stream (i32.const 16) (i32.const 20)) |
| 172 | + (call $test-stream (i32.const 16) (i32.const 21)) |
| 173 | + (call $test-stream (i32.const 16) (i32.const 22)) |
| 174 | + (call $test-stream (i32.const 16) (i32.const 23)) |
| 175 | + (call $test-stream (i32.const 16) (i32.const 24)) |
| 176 | + |
| 177 | + (i32.const 43) |
| 178 | + ) |
| 179 | + |
77 | 180 | (func (export "test-no-read-char") |
78 | 181 | (local $ret i32) (local $ret64 i64) |
79 | 182 | (local $rx i32) (local $tx i32) |
|
102 | 205 | ) |
103 | 206 | (type $FT (future)) |
104 | 207 | (type $ST (stream)) |
| 208 | + (type $FTB (future u8)) |
| 209 | + (type $STB (stream u8)) |
105 | 210 | (type $FTC (future char)) |
106 | 211 | (type $STC (stream char)) |
107 | 212 | (canon waitable.join (core func $waitable.join)) |
|
111 | 216 | (canon future.read $FT async (core func $future.read)) |
112 | 217 | (canon future.write $FT async (core func $future.write)) |
113 | 218 | (canon stream.new $ST (core func $stream.new)) |
114 | | - (canon stream.read $ST async (core func $stream.read)) |
115 | | - (canon stream.write $ST async (core func $stream.write)) |
| 219 | + (canon stream.read $ST async (memory $memory "mem") (core func $stream.read)) ;; TODO: shouldn't need (memory) immediate |
| 220 | + (canon stream.write $ST async (memory $memory "mem") (core func $stream.write)) ;; TODO: shouldn't need (memory) immediate |
| 221 | + (canon future.new $FTB (core func $future.newb)) |
| 222 | + (canon future.read $FTB async (memory $memory "mem") (core func $future.readb)) |
| 223 | + (canon future.write $FTB async (memory $memory "mem") (core func $future.writeb)) |
| 224 | + (canon stream.new $STB (core func $stream.newb)) |
| 225 | + (canon stream.read $STB async (memory $memory "mem") (core func $stream.readb)) |
| 226 | + (canon stream.write $STB async (memory $memory "mem") (core func $stream.writeb)) |
116 | 227 | (canon future.new $FTC (core func $future.newc)) |
117 | 228 | (canon future.read $FTC async (memory $memory "mem") (core func $future.readc)) |
118 | 229 | (canon future.write $FTC async (memory $memory "mem") (core func $future.writec)) |
|
130 | 241 | (export "stream.new" (func $stream.new)) |
131 | 242 | (export "stream.read" (func $stream.read)) |
132 | 243 | (export "stream.write" (func $stream.write)) |
| 244 | + (export "future.newb" (func $future.newb)) |
| 245 | + (export "future.readb" (func $future.readb)) |
| 246 | + (export "future.writeb" (func $future.writeb)) |
| 247 | + (export "stream.newb" (func $stream.newb)) |
| 248 | + (export "stream.readb" (func $stream.readb)) |
| 249 | + (export "stream.writeb" (func $stream.writeb)) |
133 | 250 | (export "future.newc" (func $future.newc)) |
134 | 251 | (export "future.readc" (func $future.readc)) |
135 | 252 | (export "future.writec" (func $future.writec)) |
|
138 | 255 | (export "stream.writec" (func $stream.writec)) |
139 | 256 | )))) |
140 | 257 | (func (export "test-empty") (result u32) (canon lift (core func $m "test-empty"))) |
| 258 | + (func (export "test-bytes") (result u32) (canon lift (core func $m "test-bytes"))) |
141 | 259 | (func (export "test-no-read-char") (canon lift (core func $m "test-no-read-char"))) |
142 | 260 | (func (export "test-no-write-char") (canon lift (core func $m "test-no-write-char"))) |
143 | 261 | ) |
144 | 262 | (component instance $i $Tester) |
145 | 263 | (assert_return (invoke "test-empty") (u32.const 42)) |
146 | 264 | (component instance $i $Tester) |
| 265 | +(assert_return (invoke "test-bytes") (u32.const 43)) |
| 266 | +(component instance $i $Tester) |
147 | 267 | (assert_trap (invoke "test-no-read-char") "cannot read from and write to intra-component future") |
148 | 268 | (component instance $i $Tester) |
149 | 269 | (assert_trap (invoke "test-no-write-char") "cannot read from and write to intra-component future") |
0 commit comments