1(component 2 (type string) 3 (type (func (param "a" string))) 4 (type $r (record (field "x" (result)) (field "y" string))) 5 (type $u (variant (case "r" $r) (case "s" string))) 6 (type $e (result $u (error u32))) 7 (type (result $u)) 8 (type (result (error $u))) 9 (type (result)) 10 11 (type (func (param "a" $e) (result (option $r)))) 12 13 (type (variant 14 (case "a" string) 15 (case "b" u32) 16 (case "c" float32) 17 (case "d" float64) 18 )) 19 20 (type $errno (enum "a" "b" "e")) 21 (type (list $errno)) 22 (type $oflags (flags "read" "write" "exclusive")) 23 (type (tuple $oflags $errno $r)) 24 25 ;; primitives in functions 26 (type (func 27 (param "a" bool) 28 (param "b" u8) 29 (param "c" s8) 30 (param "d" u16) 31 (param "e" s16) 32 (param "f" u32) 33 (param "g" s32) 34 (param "h" u64) 35 (param "i" s64) 36 (param "j" char) 37 (param "k" string) 38 )) 39 40 ;; primitives in types 41 (type bool) 42 (type u8) 43 (type s8) 44 (type u16) 45 (type s16) 46 (type u32) 47 (type s32) 48 (type u64) 49 (type s64) 50 (type char) 51 (type string) 52) 53 54(component 55 (type $empty (func)) 56 (type (func (param "a" string) (result u32))) 57 (type (component)) 58 (core type (module)) 59 (core type (func)) 60 (type (instance)) 61 62 (type (component 63 (import "x" (func (type $empty))) 64 (import "y" (func)) 65 (import "z" (component)) 66 67 (type $t (instance)) 68 69 (export "a" (core module)) 70 (export "b" (instance (type $t))) 71 )) 72 73 (type (instance 74 (export "x" (func (type $empty))) 75 (export "y" (func)) 76 (export "z" (component)) 77 78 (type $t (instance)) 79 80 (export "a" (core module)) 81 (export "b" (instance (type $t))) 82 )) 83 84 (core type (module 85 (import "" "" (func (param i32))) 86 (import "" "1" (func (result i32))) 87 (export "1" (global i32)) 88 (export "2" (memory 1)) 89 (export "3" (table 1 funcref)) 90 )) 91) 92 93;; outer core aliases work 94(component $C 95 (core type $f (func)) 96 (core type $m (module)) 97 98 (component $C2 99 (alias outer $C $f (core type $my_f)) 100 (import "a" (core module (type $m))) 101 (import "x" (core module 102 (alias outer $C2 $my_f (type $my_f)) 103 (import "" "1" (func (type $my_f))) 104 )) 105 ) 106) 107 108;; type exports work 109(component $C 110 (component $C2 111 (type string) 112 (export "x" (type 0)) 113 ) 114 (instance (instantiate 0)) 115 (alias export 0 "x" (type)) 116 (export "x" (type 0)) 117) 118 119(component 120 (core module $m (func (export "") (param i32) (result i32) local.get 0)) 121 (core instance $m (instantiate $m)) 122 (func (export "i-to-b") (param "a" u32) (result bool) (canon lift (core func $m ""))) 123 (func (export "i-to-u8") (param "a" u32) (result u8) (canon lift (core func $m ""))) 124 (func (export "i-to-s8") (param "a" u32) (result s8) (canon lift (core func $m ""))) 125 (func (export "i-to-u16") (param "a" u32) (result u16) (canon lift (core func $m ""))) 126 (func (export "i-to-s16") (param "a" u32) (result s16) (canon lift (core func $m ""))) 127) 128(assert_return (invoke "i-to-b" (u32.const 0)) (bool.const false)) 129(assert_return (invoke "i-to-b" (u32.const 1)) (bool.const true)) 130(assert_return (invoke "i-to-b" (u32.const 2)) (bool.const true)) 131(assert_return (invoke "i-to-u8" (u32.const 0x00)) (u8.const 0)) 132(assert_return (invoke "i-to-u8" (u32.const 0x01)) (u8.const 1)) 133(assert_return (invoke "i-to-u8" (u32.const 0xf01)) (u8.const 1)) 134(assert_return (invoke "i-to-u8" (u32.const 0xf00)) (u8.const 0)) 135(assert_return (invoke "i-to-s8" (u32.const 0xffffffff)) (s8.const -1)) 136(assert_return (invoke "i-to-s8" (u32.const 127)) (s8.const 127)) 137(assert_return (invoke "i-to-u16" (u32.const 0)) (u16.const 0)) 138(assert_return (invoke "i-to-u16" (u32.const 1)) (u16.const 1)) 139(assert_return (invoke "i-to-u16" (u32.const 0xffffffff)) (u16.const 0xffff)) 140(assert_return (invoke "i-to-s16" (u32.const 0)) (s16.const 0)) 141(assert_return (invoke "i-to-s16" (u32.const 1)) (s16.const 1)) 142(assert_return (invoke "i-to-s16" (u32.const 0xffffffff)) (s16.const -1)) 143 144(assert_invalid 145 (component 146 (type $t1 string) 147 (type $t2 (list $t1)) 148 (type $t3 (list $t2)) 149 (type $t4 (list $t3)) 150 (type $t5 (list $t4)) 151 (type $t6 (list $t5)) 152 (type $t7 (list $t6)) 153 (type $t8 (list $t7)) 154 (type $t9 (list $t8)) 155 (type $t10 (list $t9)) 156 (type $t11 (list $t10)) 157 (type $t12 (list $t11)) 158 (type $t13 (list $t12)) 159 (type $t14 (list $t13)) 160 (type $t15 (list $t14)) 161 (type $t16 (list $t15)) 162 (type $t17 (list $t16)) 163 (type $t18 (list $t17)) 164 (type $t19 (list $t18)) 165 (type $t20 (list $t19)) 166 (type $t21 (list $t20)) 167 (type $t22 (list $t21)) 168 (type $t23 (list $t22)) 169 (type $t24 (list $t23)) 170 (type $t25 (list $t24)) 171 (type $t26 (list $t25)) 172 (type $t27 (list $t26)) 173 (type $t28 (list $t27)) 174 (type $t29 (list $t28)) 175 (type $t30 (list $t29)) 176 (type $t31 (list $t30)) 177 (type $t32 (list $t31)) 178 (type $t33 (list $t32)) 179 (type $t34 (list $t33)) 180 (type $t35 (list $t34)) 181 (type $t36 (list $t35)) 182 (type $t37 (list $t36)) 183 (type $t38 (list $t37)) 184 (type $t39 (list $t38)) 185 (type $t40 (list $t39)) 186 (type $t41 (list $t40)) 187 (type $t42 (list $t41)) 188 (type $t43 (list $t42)) 189 (type $t44 (list $t43)) 190 (type $t45 (list $t44)) 191 (type $t46 (list $t45)) 192 (type $t47 (list $t46)) 193 (type $t48 (list $t47)) 194 (type $t49 (list $t48)) 195 (type $t50 (list $t49)) 196 (type $t51 (list $t50)) 197 (type $t52 (list $t51)) 198 (type $t53 (list $t52)) 199 (type $t54 (list $t53)) 200 (type $t55 (list $t54)) 201 (type $t56 (list $t55)) 202 (type $t57 (list $t56)) 203 (type $t58 (list $t57)) 204 (type $t59 (list $t58)) 205 (type $t60 (list $t59)) 206 (type $t61 (list $t60)) 207 (type $t62 (list $t61)) 208 (type $t63 (list $t62)) 209 (type $t64 (list $t63)) 210 (type $t65 (list $t64)) 211 (type $t66 (list $t65)) 212 (type $t67 (list $t66)) 213 (type $t68 (list $t67)) 214 (type $t69 (list $t68)) 215 (type $t70 (list $t69)) 216 (type $t71 (list $t70)) 217 (type $t72 (list $t71)) 218 (type $t73 (list $t72)) 219 (type $t74 (list $t73)) 220 (type $t75 (list $t74)) 221 (type $t76 (list $t75)) 222 (type $t77 (list $t76)) 223 (type $t78 (list $t77)) 224 (type $t79 (list $t78)) 225 (type $t80 (list $t79)) 226 (type $t81 (list $t80)) 227 (type $t82 (list $t81)) 228 (type $t83 (list $t82)) 229 (type $t84 (list $t83)) 230 (type $t85 (list $t84)) 231 (type $t86 (list $t85)) 232 (type $t87 (list $t86)) 233 (type $t88 (list $t87)) 234 (type $t89 (list $t88)) 235 (type $t90 (list $t89)) 236 (type $t91 (list $t90)) 237 (type $t92 (list $t91)) 238 (type $t93 (list $t92)) 239 (type $t94 (list $t93)) 240 (type $t95 (list $t94)) 241 (type $t96 (list $t95)) 242 (type $t97 (list $t96)) 243 (type $t98 (list $t97)) 244 (type $t99 (list $t98)) 245 (type $t100 (list $t99)) 246 (type $t101 (list $t100)) 247 (export "t" (type $t101)) 248 ) 249 "type nesting is too deep") 250 251(component 252 (type (instance 253 (export "x" (instance $x 254 (type $t u32) 255 (export "y" (type (eq $t))) 256 )) 257 (alias export $x "y" (type $t)) 258 (export "my-y" (type (eq $t))) 259 )) 260 261 (type (component 262 (import "x" (instance $x 263 (type $t u32) 264 (export "y" (type (eq $t))) 265 )) 266 (alias export $x "y" (type $t)) 267 (export "my-y" (type (eq $t))) 268 )) 269) 270 271(component 272 (type $t u32) 273 (export $t2 "t" (type $t)) 274 (type $r (record (field "x" $t2))) 275 (export "r" (type $r)) 276) 277 278(component 279 (component 280 (import "x" (instance $i 281 (type $i u32) 282 (export "i" (type (eq $i))) 283 )) 284 (alias export $i "i" (type $i)) 285 (export "i" (type $i)) 286 ) 287) 288 289(component 290 (type $u u32) 291 (instance $i 292 (export "i" (type $u)) 293 ) 294 (alias export $i "i" (type $i)) 295 (export "i" (type $i)) 296) 297 298(component 299 (component $c 300 (type $t u32) 301 (export "t" (type $t)) 302 ) 303 (instance $c (instantiate $c)) 304 (export "i" (type $c "t")) 305) 306 307(component 308 (component $c 309 (import "x" (component $c 310 (type $t u32) 311 (export "t" (type (eq $t))) 312 )) 313 (instance $c (instantiate $c)) 314 (export "i" (type $c "t")) 315 ) 316 317 (component $x 318 (type $t u32) 319 (export "t" (type $t)) 320 ) 321 322 (instance $c (instantiate $c (with "x" (component $x)))) 323) 324 325(component 326 (type $t1 u64) 327 (import "a" (type $t2 (eq $t1))) 328 (import "b" (type $t3 (eq $t2))) 329) 330 331(component 332 (import "a" (instance 333 (type $t1 u64) 334 (export "a" (type $t2 (eq $t1))) 335 (export "b" (type (eq $t2))) 336 )) 337) 338 339(component 340 (type (export "x") (component 341 (type $t' (instance 342 (export "r" (type (sub resource))) 343 )) 344 (export "t" (instance $t (type $t'))) 345 )) 346) 347 348(component 349 (type (export "x") (instance 350 (type $t' (instance 351 (export "r" (type (sub resource))) 352 )) 353 (export "t" (instance $t (type $t'))) 354 )) 355) 356 357(component definition $A 358 (type $t' (variant (case "a" u32) (case "b"))) 359 (export $t "t" (type $t')) 360 361 (core module $m 362 (memory (export "m") 1) 363 (func (export "f") (param i32) (result i32) 364 (i32.store8 365 (i32.const 0) 366 (local.get 0)) 367 i32.const 0) 368 ) 369 (core instance $m (instantiate $m)) 370 (func (export "f") (param "a" u32) (result $t) 371 (canon lift (core func $m "f") (memory $m "m")) 372 ) 373) 374 375(component instance $A $A) 376(assert_return (invoke "f" (u32.const 0)) (variant.const "a" (u32.const 0))) 377(assert_return (invoke "f" (u32.const 1)) (variant.const "b")) 378(assert_trap (invoke "f" (u32.const 2)) "discriminant 2 out of range [0..2)") 379