@@ -433,9 +433,8 @@ componentdecl ::= <importdecl>
433433instancedecl ::= <type>
434434 | <alias>
435435 | <exportdecl>
436- importdecl ::= (import <name> <importdesc> )
436+ importdecl ::= (import <name> bind-id(<externdesc>) )
437437exportdecl ::= (export <name> <externdesc>)
438- importdesc ::= bind-id(<externdesc>)
439438externdesc ::= (<sort> (type <u32>) )
440439 | core-prefix(<core:moduletype>)
441440 | <functype>
@@ -524,14 +523,14 @@ text format allows both references to out-of-line type definitions (via
524523` (type <typeidx>) ` ) and inline type expressions that the text format desugars
525524into out-of-line type definitions.
526525
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.
530529
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:
535534* Type exports allow a component or interface to associate a name with a
536535 structural type (e.g., ` (export "nanos" (type (eq u64))) ` ) which bindings
537536 generators can use to generate type aliases (e.g., ` typedef uint64_t nanos; ` ).
@@ -611,7 +610,7 @@ two directions:
611610Canonical definitions specify one of these two wrapping directions, the function
612611to wrap and a list of configuration options:
613612```
614- canon ::= (canon lift core-prefix(<core:funcidx>) <functype> < canonopt>* (func <id>? ))
613+ canon ::= (canon lift core-prefix(<core:funcidx>) <canonopt>* bind-id(<externdesc> ))
615614 | (canon lower <funcidx> <canonopt>* (core func <id>?))
616615canonopt ::= string-encoding=utf8
617616 | string-encoding=utf16
@@ -620,6 +619,10 @@ canonopt ::= string-encoding=utf8
620619 | (realloc core-prefix(<core:funcidx>))
621620 | (post-return core-prefix(<core:funcidx>))
622621```
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+
623626The ` string-encoding ` option specifies the encoding the Canonical ABI will use
624627for the ` string ` type. The ` latin1+utf16 ` encoding captures a common string
625628encoding across Java, JavaScript and .NET VMs and allows a dynamic choice
@@ -672,9 +675,9 @@ stack-switching in component function signatures.
672675Similar to the ` import ` and ` alias ` abbreviations shown above, ` canon `
673676definitions can also be written in an inverted form that puts the sort first:
674677``` 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... ))
678681```
679682Note: in the future, ` canon ` may be generalized to define other sorts than
680683functions (such as types), hence the explicit ` sort ` .
@@ -707,11 +710,11 @@ takes a string, does some logging, then returns a string.
707710 (with "libc" (instance $libc))
708711 (with "wasi:logging" (instance (export "log" (func $log))))
709712 ))
710- (func (export "run" ) (canon lift
713+ (func $run (param string) (result string ) (canon lift
711714 (core func $main "run")
712- (func (param string) (result string))
713715 (memory (core memory $libc "mem")) (realloc (core func $libc "realloc"))
714716 ))
717+ (export "run" (func $run))
715718)
716719```
717720This example shows the pattern of splitting out a reusable language runtime
@@ -764,9 +767,8 @@ exported string at instantiation time:
764767 )
765768 )
766769 (core instance $main (instantiate $Main (with "libc" (instance $libc))))
767- (func $start (canon lift
770+ (func $start (param string) (result string) ( canon lift
768771 (core func $main "start")
769- (func (param string) (result string))
770772 (memory (core memory $libc "mem")) (realloc (core func $libc "realloc"))
771773 ))
772774 (start $start (value $name) (result (value $greeting)))
@@ -782,7 +784,7 @@ of core linear memory.
782784
783785Lastly, imports and exports are defined in terms of the above as:
784786```
785- import ::= (import <name> <importdesc>)
787+ import ::= <importdecl>
786788export ::= (export <name> <sortidx>)
787789```
788790All import and export names within a component must be unique, respectively.
0 commit comments