@@ -433,9 +433,8 @@ componentdecl ::= <importdecl>
433
433
instancedecl ::= <type>
434
434
| <alias>
435
435
| <exportdecl>
436
- importdecl ::= (import <name> <importdesc> )
436
+ importdecl ::= (import <name> bind-id(<externdesc>) )
437
437
exportdecl ::= (export <name> <externdesc>)
438
- importdesc ::= bind-id(<externdesc>)
439
438
externdesc ::= (<sort> (type <u32>) )
440
439
| core-prefix(<core:moduletype>)
441
440
| <functype>
@@ -524,14 +523,14 @@ text format allows both references to out-of-line type definitions (via
524
523
` (type <typeidx>) ` ) and inline type expressions that the text format desugars
525
524
into out-of-line type definitions.
526
525
527
- The ` value ` case of ` importdesc ` / ` exportdesc ` describes a runtime value
528
- that is imported or exported at instantiation time as described in the [ start
529
- definitions] ( #start-definitions ) section below.
526
+ The ` value ` case of ` externdesc ` describes a runtime value that is imported or
527
+ exported at instantiation time as described in the
528
+ [ start definitions] ( #start-definitions ) section below.
530
529
531
- The ` type ` case of ` importdesc ` / ` exportdesc ` describes an imported or exported
532
- type along with its bounds. The bounds currently only have an ` eq ` option that
533
- says that the imported/exported type must be exactly equal to the referenced
534
- type. There are two main use cases for this in the short-term:
530
+ The ` type ` case of ` externdesc ` describes an imported or exported type along
531
+ with its bounds. The bounds currently only have an ` eq ` option that says that
532
+ the imported/exported type must be exactly equal to the referenced type. There
533
+ are two main use cases for this in the short-term:
535
534
* Type exports allow a component or interface to associate a name with a
536
535
structural type (e.g., ` (export "nanos" (type (eq u64))) ` ) which bindings
537
536
generators can use to generate type aliases (e.g., ` typedef uint64_t nanos; ` ).
@@ -611,7 +610,7 @@ two directions:
611
610
Canonical definitions specify one of these two wrapping directions, the function
612
611
to wrap and a list of configuration options:
613
612
```
614
- canon ::= (canon lift core-prefix(<core:funcidx>) <functype> < canonopt>* (func <id>? ))
613
+ canon ::= (canon lift core-prefix(<core:funcidx>) <canonopt>* bind-id(<externdesc> ))
615
614
| (canon lower <funcidx> <canonopt>* (core func <id>?))
616
615
canonopt ::= string-encoding=utf8
617
616
| string-encoding=utf16
@@ -620,6 +619,10 @@ canonopt ::= string-encoding=utf8
620
619
| (realloc core-prefix(<core:funcidx>))
621
620
| (post-return core-prefix(<core:funcidx>))
622
621
```
622
+ While the production ` externdesc ` accepts any ` sort ` , the validation rules
623
+ for ` canon lift ` would only allow the ` func ` sort. In the future, other sorts
624
+ may be added (viz., types), hence the explicit sort.
625
+
623
626
The ` string-encoding ` option specifies the encoding the Canonical ABI will use
624
627
for the ` string ` type. The ` latin1+utf16 ` encoding captures a common string
625
628
encoding across Java, JavaScript and .NET VMs and allows a dynamic choice
@@ -672,9 +675,9 @@ stack-switching in component function signatures.
672
675
Similar to the ` import ` and ` alias ` abbreviations shown above, ` canon `
673
676
definitions can also be written in an inverted form that puts the sort first:
674
677
``` wasm
675
- (func $f (import "i" "f")) ≡ (import "i" "f" (func $f)) (WebAssembly 1.0)
676
- (func $h (canon lift ...)) ≡ (canon lift ... (func $h))
677
- (core func $h (canon lower ...)) ≡ (canon lower ... (core func $h))
678
+ (func $f ...type... (import "i" "f")) ≡ (import "i" "f" (func $f ...type...)) (WebAssembly 1.0)
679
+ (func $h ...type... (canon lift ...)) ≡ (canon lift ... (func $h ...type... ))
680
+ (core func $h ...type... (canon lower ...)) ≡ (canon lower ... (core func $h ...type... ))
678
681
```
679
682
Note: in the future, ` canon ` may be generalized to define other sorts than
680
683
functions (such as types), hence the explicit ` sort ` .
@@ -707,11 +710,11 @@ takes a string, does some logging, then returns a string.
707
710
(with "libc" (instance $libc))
708
711
(with "wasi:logging" (instance (export "log" (func $log))))
709
712
))
710
- (func (export "run" ) (canon lift
713
+ (func $run (param string) (result string ) (canon lift
711
714
(core func $main "run")
712
- (func (param string) (result string))
713
715
(memory (core memory $libc "mem")) (realloc (core func $libc "realloc"))
714
716
))
717
+ (export "run" (func $run))
715
718
)
716
719
```
717
720
This example shows the pattern of splitting out a reusable language runtime
@@ -764,9 +767,8 @@ exported string at instantiation time:
764
767
)
765
768
)
766
769
(core instance $main (instantiate $Main (with "libc" (instance $libc))))
767
- (func $start (canon lift
770
+ (func $start (param string) (result string) ( canon lift
768
771
(core func $main "start")
769
- (func (param string) (result string))
770
772
(memory (core memory $libc "mem")) (realloc (core func $libc "realloc"))
771
773
))
772
774
(start $start (value $name) (result (value $greeting)))
@@ -782,7 +784,7 @@ of core linear memory.
782
784
783
785
Lastly, imports and exports are defined in terms of the above as:
784
786
```
785
- import ::= (import <name> <importdesc>)
787
+ import ::= <importdecl>
786
788
export ::= (export <name> <sortidx>)
787
789
```
788
790
All import and export names within a component must be unique, respectively.
0 commit comments