1fcf62087SAlex Crichton(component 27d7ddcebSAlex Crichton (core module $m) 37d7ddcebSAlex Crichton (core instance (instantiate $m)) 4fcf62087SAlex Crichton) 5fcf62087SAlex Crichton 6fcf62087SAlex Crichton(component 77d7ddcebSAlex Crichton (core module $m 8fcf62087SAlex Crichton (func (export "")) 9fcf62087SAlex Crichton ) 107d7ddcebSAlex Crichton (core instance $i (instantiate $m)) 11fcf62087SAlex Crichton 127d7ddcebSAlex Crichton (core module $m2 13fcf62087SAlex Crichton (func (import "" "")) 14fcf62087SAlex Crichton ) 157d7ddcebSAlex Crichton (core instance (instantiate $m2 (with "" (instance $i)))) 16fcf62087SAlex Crichton) 17fcf62087SAlex Crichton 18fcf62087SAlex Crichton(component 197d7ddcebSAlex Crichton (core module $m 20fcf62087SAlex Crichton (func (export "a")) 21fcf62087SAlex Crichton ) 227d7ddcebSAlex Crichton (core instance $i (instantiate $m)) 23fcf62087SAlex Crichton 247d7ddcebSAlex Crichton (core module $m2 25fcf62087SAlex Crichton (func (import "" "b")) 26fcf62087SAlex Crichton ) 277d7ddcebSAlex Crichton (core instance (instantiate $m2 28fcf62087SAlex Crichton (with "" (instance (export "b" (func $i "a")))) 29fcf62087SAlex Crichton )) 30fcf62087SAlex Crichton) 31fcf62087SAlex Crichton 32fcf62087SAlex Crichton;; all kinds of imports for core wasm modules, and register a start function on 33fcf62087SAlex Crichton;; one module to ensure that everything is correct 34fcf62087SAlex Crichton(component 357d7ddcebSAlex Crichton (core module $m 36fcf62087SAlex Crichton (func (export "a")) 37fcf62087SAlex Crichton (table (export "b") 1 funcref) 38fcf62087SAlex Crichton (memory (export "c") 1) 39fcf62087SAlex Crichton (global (export "d") i32 i32.const 1) 40fcf62087SAlex Crichton ) 417d7ddcebSAlex Crichton (core instance $i (instantiate $m)) 42fcf62087SAlex Crichton 437d7ddcebSAlex Crichton (core module $m2 44fcf62087SAlex Crichton (import "" "a" (func $f)) 45fcf62087SAlex Crichton (import "" "b" (table 1 funcref)) 46fcf62087SAlex Crichton (import "" "c" (memory 1)) 47fcf62087SAlex Crichton (import "" "d" (global $g i32)) 48fcf62087SAlex Crichton 49fcf62087SAlex Crichton (func $start 50fcf62087SAlex Crichton global.get $g 51fcf62087SAlex Crichton i32.const 1 52fcf62087SAlex Crichton i32.ne 53fcf62087SAlex Crichton if 54fcf62087SAlex Crichton unreachable 55fcf62087SAlex Crichton end 56fcf62087SAlex Crichton 57fcf62087SAlex Crichton call $f 58fcf62087SAlex Crichton ) 59fcf62087SAlex Crichton 60fcf62087SAlex Crichton (start $start) 61fcf62087SAlex Crichton 62fcf62087SAlex Crichton (data (i32.const 0) "hello") 63fcf62087SAlex Crichton (elem (i32.const 0) $start) 64fcf62087SAlex Crichton ) 657d7ddcebSAlex Crichton (core instance (instantiate $m2 66fcf62087SAlex Crichton (with "" (instance $i)) 67fcf62087SAlex Crichton )) 68fcf62087SAlex Crichton) 69fcf62087SAlex Crichton 7080bd650bSPeter Huene;; Test to see if a component with a type export can be instantiated. 7180bd650bSPeter Huene(component 7280bd650bSPeter Huene (type string) 73b305f251SAlex Crichton (export "a" (type 0)) 7480bd650bSPeter Huene) 7580bd650bSPeter Huene 76fcf62087SAlex Crichton;; double-check the start function runs by ensuring that a trap shows up and it 77fcf62087SAlex Crichton;; sees the wrong value for the global import 78fcf62087SAlex Crichton(assert_trap 79fcf62087SAlex Crichton (component 807d7ddcebSAlex Crichton (core module $m 81fcf62087SAlex Crichton (global (export "g") i32 i32.const 1) 82fcf62087SAlex Crichton ) 837d7ddcebSAlex Crichton (core instance $i (instantiate $m)) 84fcf62087SAlex Crichton 857d7ddcebSAlex Crichton (core module $m2 86fcf62087SAlex Crichton (import "" "g" (global $g i32)) 87fcf62087SAlex Crichton 88fcf62087SAlex Crichton (func $start 89fcf62087SAlex Crichton global.get $g 90fcf62087SAlex Crichton i32.const 0 91fcf62087SAlex Crichton i32.ne 92fcf62087SAlex Crichton if 93fcf62087SAlex Crichton unreachable 94fcf62087SAlex Crichton end 95fcf62087SAlex Crichton ) 96fcf62087SAlex Crichton 97fcf62087SAlex Crichton (start $start) 98fcf62087SAlex Crichton ) 997d7ddcebSAlex Crichton (core instance (instantiate $m2 (with "" (instance $i)))) 100fcf62087SAlex Crichton ) 101fcf62087SAlex Crichton "unreachable") 102fcf62087SAlex Crichton 103fcf62087SAlex Crichton;; shuffle around imports to get to what the target core wasm module needs 104fcf62087SAlex Crichton(component 1057d7ddcebSAlex Crichton (core module $m 106fcf62087SAlex Crichton (func (export "1")) 107fcf62087SAlex Crichton (table (export "2") 1 funcref) 108fcf62087SAlex Crichton (memory (export "3") 1) 109fcf62087SAlex Crichton (global (export "4") i32 i32.const 1) 110fcf62087SAlex Crichton ) 1117d7ddcebSAlex Crichton (core instance $i (instantiate $m)) 112fcf62087SAlex Crichton 1137d7ddcebSAlex Crichton (core module $m2 114fcf62087SAlex Crichton (import "" "a" (func $f)) 115fcf62087SAlex Crichton (import "" "b" (table 1 funcref)) 116fcf62087SAlex Crichton (import "" "c" (memory 1)) 117fcf62087SAlex Crichton (import "" "d" (global $g i32)) 118fcf62087SAlex Crichton ) 1197d7ddcebSAlex Crichton (core instance (instantiate $m2 120fcf62087SAlex Crichton (with "" (instance 121fcf62087SAlex Crichton (export "a" (func $i "1")) 122fcf62087SAlex Crichton (export "b" (table $i "2")) 123fcf62087SAlex Crichton (export "c" (memory $i "3")) 124fcf62087SAlex Crichton (export "d" (global $i "4")) 125fcf62087SAlex Crichton )) 126fcf62087SAlex Crichton )) 127fcf62087SAlex Crichton) 128651f4085SAlex Crichton 129651f4085SAlex Crichton;; indirect references through a synthetic instance 130651f4085SAlex Crichton(component 131651f4085SAlex Crichton (core module $m 132651f4085SAlex Crichton (func (export "a")) 133651f4085SAlex Crichton (table (export "b") 1 funcref) 134651f4085SAlex Crichton (memory (export "c") 1) 135651f4085SAlex Crichton (global (export "d") i32 i32.const 1) 136651f4085SAlex Crichton ) 137651f4085SAlex Crichton (core instance $i (instantiate $m)) 138651f4085SAlex Crichton (core instance $i2 139651f4085SAlex Crichton (export "a1" (func $i "a")) 140651f4085SAlex Crichton (export "a2" (table $i "b")) 141651f4085SAlex Crichton (export "a3" (memory $i "c")) 142651f4085SAlex Crichton (export "a4" (global $i "d")) 143651f4085SAlex Crichton ) 144651f4085SAlex Crichton 145651f4085SAlex Crichton (core module $m2 146651f4085SAlex Crichton (import "" "1" (func $f)) 147651f4085SAlex Crichton (import "" "2" (table 1 funcref)) 148651f4085SAlex Crichton (import "" "3" (memory 1)) 149651f4085SAlex Crichton (import "" "4" (global $g i32)) 150651f4085SAlex Crichton ) 151651f4085SAlex Crichton (core instance (instantiate $m2 152651f4085SAlex Crichton (with "" (instance 153651f4085SAlex Crichton (export "1" (func $i2 "a1")) 154651f4085SAlex Crichton (export "2" (table $i2 "a2")) 155651f4085SAlex Crichton (export "3" (memory $i2 "a3")) 156651f4085SAlex Crichton (export "4" (global $i2 "a4")) 157651f4085SAlex Crichton )) 158651f4085SAlex Crichton )) 159651f4085SAlex Crichton) 160651f4085SAlex Crichton 161651f4085SAlex Crichton(component 162651f4085SAlex Crichton (import "host" (instance $i (export "return-three" (func (result u32))))) 163651f4085SAlex Crichton 164651f4085SAlex Crichton (core module $m 165651f4085SAlex Crichton (import "host" "return-three" (func $three (result i32))) 166651f4085SAlex Crichton (func $start 167651f4085SAlex Crichton call $three 168651f4085SAlex Crichton i32.const 3 169651f4085SAlex Crichton i32.ne 170651f4085SAlex Crichton if unreachable end 171651f4085SAlex Crichton ) 172651f4085SAlex Crichton (start $start) 173651f4085SAlex Crichton ) 174651f4085SAlex Crichton (core func $three_lower 175651f4085SAlex Crichton (canon lower (func $i "return-three")) 176651f4085SAlex Crichton ) 177651f4085SAlex Crichton (core instance (instantiate $m 178651f4085SAlex Crichton (with "host" (instance (export "return-three" (func $three_lower)))) 179651f4085SAlex Crichton )) 180651f4085SAlex Crichton) 181651f4085SAlex Crichton 182651f4085SAlex Crichton(component 183651f4085SAlex Crichton (import "host" (instance $i 1847b9189baSAlex Crichton (type $x' (record (field "x" u32))) 185*c71d3aabSNick Fitzgerald (export "x" (type $x (eq $x'))) 186f928bf72SAlex Crichton (type $rec' (record (field "x" $x) (field "y" string))) 187*c71d3aabSNick Fitzgerald (export "rec" (type $rec (eq $rec'))) 188f96491f3SPat Hickey (export "some-record" (type (eq $rec))))) 189f96491f3SPat Hickey) 190f96491f3SPat Hickey 191f96491f3SPat Hickey(component 192f96491f3SPat Hickey (import "host" (instance $i 193651f4085SAlex Crichton (export "nested" (instance 194651f4085SAlex Crichton (export "return-four" (func (result u32))) 195651f4085SAlex Crichton )) 196651f4085SAlex Crichton )) 197651f4085SAlex Crichton 198651f4085SAlex Crichton (core module $m 199651f4085SAlex Crichton (import "host" "return-three" (func $three (result i32))) 200651f4085SAlex Crichton (func $start 201651f4085SAlex Crichton call $three 202651f4085SAlex Crichton i32.const 4 203651f4085SAlex Crichton i32.ne 204651f4085SAlex Crichton if unreachable end 205651f4085SAlex Crichton ) 206651f4085SAlex Crichton (start $start) 207651f4085SAlex Crichton ) 208651f4085SAlex Crichton (core func $three_lower 209651f4085SAlex Crichton (canon lower (func $i "nested" "return-four")) 210651f4085SAlex Crichton ) 211651f4085SAlex Crichton (core instance (instantiate $m 212651f4085SAlex Crichton (with "host" (instance (export "return-three" (func $three_lower)))) 213651f4085SAlex Crichton )) 214651f4085SAlex Crichton) 215651f4085SAlex Crichton 216651f4085SAlex Crichton(component 217651f4085SAlex Crichton (import "host" (instance $i 218651f4085SAlex Crichton (export "simple-module" (core module)) 219651f4085SAlex Crichton )) 220651f4085SAlex Crichton 221651f4085SAlex Crichton (core instance (instantiate (module $i "simple-module"))) 222651f4085SAlex Crichton) 223651f4085SAlex Crichton 224651f4085SAlex Crichton(component 225651f4085SAlex Crichton (import "host" (instance $i 226651f4085SAlex Crichton (export "simple-module" (core module 227651f4085SAlex Crichton (export "f" (func (result i32))) 228651f4085SAlex Crichton (export "g" (global i32)) 229651f4085SAlex Crichton )) 230651f4085SAlex Crichton )) 231651f4085SAlex Crichton 232651f4085SAlex Crichton (core instance $i (instantiate (module $i "simple-module"))) 233651f4085SAlex Crichton (core module $verify 234651f4085SAlex Crichton (import "host" "f" (func $f (result i32))) 235651f4085SAlex Crichton (import "host" "g" (global $g i32)) 236651f4085SAlex Crichton 237651f4085SAlex Crichton (func $start 238651f4085SAlex Crichton call $f 239651f4085SAlex Crichton i32.const 101 240651f4085SAlex Crichton i32.ne 241651f4085SAlex Crichton if unreachable end 242651f4085SAlex Crichton 243651f4085SAlex Crichton global.get $g 244651f4085SAlex Crichton i32.const 100 245651f4085SAlex Crichton i32.ne 246651f4085SAlex Crichton if unreachable end 247651f4085SAlex Crichton ) 248651f4085SAlex Crichton (start $start) 249651f4085SAlex Crichton ) 250651f4085SAlex Crichton 251651f4085SAlex Crichton (core instance (instantiate $verify (with "host" (instance $i)))) 252651f4085SAlex Crichton) 25376a2545aSAlex Crichton 25476a2545aSAlex Crichton;; export an instance 25576a2545aSAlex Crichton(component 25676a2545aSAlex Crichton (core module $m) 25776a2545aSAlex Crichton (instance $i (export "m" (core module $m))) 25876a2545aSAlex Crichton (export "i" (instance $i)) 25976a2545aSAlex Crichton) 26076a2545aSAlex Crichton(component 26176a2545aSAlex Crichton (component $c) 26276a2545aSAlex Crichton (instance $i (instantiate $c)) 26376a2545aSAlex Crichton (export "i" (instance $i)) 26476a2545aSAlex Crichton) 26576a2545aSAlex Crichton(component 26676a2545aSAlex Crichton (import "host" (instance $i)) 26776a2545aSAlex Crichton (export "i" (instance $i)) 26876a2545aSAlex Crichton) 26976a2545aSAlex Crichton 270d29b2800SAlex Crichton 271d29b2800SAlex Crichton(component definition $C1 272d29b2800SAlex Crichton (type $r1 (resource (rep i32))) 273d29b2800SAlex Crichton (export "r" (type $r1)) 274d29b2800SAlex Crichton) 275d29b2800SAlex Crichton(component definition $C2 276d29b2800SAlex Crichton (type $r1 (resource (rep i32))) 277d29b2800SAlex Crichton (export "r" (type $r1)) 278d29b2800SAlex Crichton) 279d29b2800SAlex Crichton 280d29b2800SAlex Crichton(component instance $I1 $C1) 281d29b2800SAlex Crichton(component instance $I2 $C1) 282d29b2800SAlex Crichton(component instance $I3 $C2) 283d29b2800SAlex Crichton(component instance $I4 $C2) 284d29b2800SAlex Crichton 285d29b2800SAlex Crichton;; all instances have different resource types 286d29b2800SAlex Crichton(assert_unlinkable 287d29b2800SAlex Crichton (component 288d29b2800SAlex Crichton (import "I1" (instance $i1 (export "r" (type (sub resource))))) 289d29b2800SAlex Crichton (alias export $i1 "r" (type $r)) 290d29b2800SAlex Crichton (import "I2" (instance $i2 (export "r" (type (eq $r))))) 291d29b2800SAlex Crichton ) 292d29b2800SAlex Crichton "mismatched resource types") 293d29b2800SAlex Crichton(assert_unlinkable 294d29b2800SAlex Crichton (component 295d29b2800SAlex Crichton (import "I1" (instance $i1 (export "r" (type (sub resource))))) 296d29b2800SAlex Crichton (alias export $i1 "r" (type $r)) 297d29b2800SAlex Crichton (import "I3" (instance $i2 (export "r" (type (eq $r))))) 298d29b2800SAlex Crichton ) 299d29b2800SAlex Crichton "mismatched resource types") 300d29b2800SAlex Crichton(assert_unlinkable 301d29b2800SAlex Crichton (component 302d29b2800SAlex Crichton (import "I1" (instance $i1 (export "r" (type (sub resource))))) 303d29b2800SAlex Crichton (alias export $i1 "r" (type $r)) 304d29b2800SAlex Crichton (import "I4" (instance $i2 (export "r" (type (eq $r))))) 305d29b2800SAlex Crichton ) 306d29b2800SAlex Crichton "mismatched resource types") 307d29b2800SAlex Crichton(assert_unlinkable 308d29b2800SAlex Crichton (component 309d29b2800SAlex Crichton (import "I2" (instance $i1 (export "r" (type (sub resource))))) 310d29b2800SAlex Crichton (alias export $i1 "r" (type $r)) 311d29b2800SAlex Crichton (import "I3" (instance $i2 (export "r" (type (eq $r))))) 312d29b2800SAlex Crichton ) 313d29b2800SAlex Crichton "mismatched resource types") 314d29b2800SAlex Crichton(assert_unlinkable 315d29b2800SAlex Crichton (component 316d29b2800SAlex Crichton (import "I2" (instance $i1 (export "r" (type (sub resource))))) 317d29b2800SAlex Crichton (alias export $i1 "r" (type $r)) 318d29b2800SAlex Crichton (import "I4" (instance $i2 (export "r" (type (eq $r))))) 319d29b2800SAlex Crichton ) 320d29b2800SAlex Crichton "mismatched resource types") 321d29b2800SAlex Crichton(assert_unlinkable 322d29b2800SAlex Crichton (component 323d29b2800SAlex Crichton (import "I3" (instance $i1 (export "r" (type (sub resource))))) 324d29b2800SAlex Crichton (alias export $i1 "r" (type $r)) 325d29b2800SAlex Crichton (import "I4" (instance $i2 (export "r" (type (eq $r))))) 326d29b2800SAlex Crichton ) 327d29b2800SAlex Crichton "mismatched resource types") 328