diff --git a/src/.vuepress/public/images/reference-hierarchy.svg b/src/.vuepress/public/images/reference-hierarchy.svg index 3a5525e13..11559dab5 100644 --- a/src/.vuepress/public/images/reference-hierarchy.svg +++ b/src/.vuepress/public/images/reference-hierarchy.svg @@ -1,4 +1,4 @@ -Wasm-internal references
any
any
eq
eq
i31
i31
struct
struct
array
array
none
none
(...)
(...)
none
none
(...)
(...)
none
none
string
string
?
?
External references
extern
extern
noextern
noextern
Function references
func
func
(...)
(...)
nofunc
nofunc
Working draft. The design is still in flux and support is incomplete / preliminary.
Working draft. The design is still in flux and support is incomplete / preliminary.
Text is not SVG - cannot display
\ No newline at end of file +Wasm-internal references
any
any
eq
eq
i31
i31
struct
struct
array
array
null
null
(...)
(...)
null
null
(...)
(...)
null
null
string
string
null
null
External references
extern
extern
nullextern
nullextern
Function references
func
func
(...)
(...)
nullfunc
nullfunc
Working draft. The design is still in flux and support is incomplete / preliminary.
Working draft. The design is still in flux and support is incomplete / preliminary.
String references
stringview_wtf8
stringview_wtf8
?
?
stringview_wtf16
stringview_wtf16
?
?
stringview_iter
stringview_iter
?
?
Text is not SVG - cannot display
\ No newline at end of file diff --git a/src/types.md b/src/types.md index fd1541251..40d4d895c 100644 --- a/src/types.md +++ b/src/types.md @@ -30,23 +30,25 @@ AssemblyScript inherits WebAssembly's more specific integer, floating point and | *Vector types* | | `v128` | v128 | - | A 128-bit vector. || -| *Reference types* | -| `externref` | externref | Object | An external reference. -| `funcref` | funcref | Function | A function reference. -|| -| *Wasm GC types* 🦄 | -| `anyref` | anyref | Object | An internal reference. -| `eqref` | eqref | Object | An equatable reference. -| `dataref` | dataref | Object | A data reference. -| `arrayref` | arrayref | Array | An array reference. -| `stringref` | stringref | string | A string reference. -| `stringview_wtf8` | stringview_wtf8 | string | A string view reference ([WTF-8](https://simonsapin.github.io/wtf-8/)). -| `stringview_wtf16` | stringview_wtf16 | string | A string view reference ([WTF-16](https://simonsapin.github.io/wtf-8/#wtf-16)). -| `stringview_iter` | stringview_iter | - | A string iterator reference. +| *Reference / GC types* | +| `ref_extern` | (ref extern) | Object | An external reference. +| `ref_func` | (ref func) | Function | A function reference. +| `ref_any` | (ref any) | Object | An internal reference. 🦄 +| `ref_eq` | (ref eq) | Object | An equatable reference. 🦄 +| `ref_struct` | (ref struct) | Object | A data reference. 🦄 +| `ref_array` | (ref array) | Array | An array reference. 🦄 +| `ref_string` | (ref string) | string | A string reference. 🦄 +| `ref_stringview_wtf8` | (ref stringview_wtf8) | - | A WTF-8 string view reference. 🦄 +| `ref_stringview_wtf16` | (ref stringview_wtf16) | string | A WTF-16 string view reference. 🦄 +| `ref_stringview_iter` | (ref stringview_iter) | - | A string iterator reference. 🦄 || | *Special types* | | `void` | - | void | Indicates no return value. +::: tip Note +The base reference types above are non-nullable. Canonical aliases, as per the spec, are available as well and refer to the respective nullable type, e.g. `type externref = ref_extern | null` mapping to `externref == (ref null extern)` in Wasm. The `ref_` prefix avoids naming collisions for the time being and might be dropped in the future. +::: + Just like in TypeScript, types are annotated after variable, function argument or class member names, separated by `:`, like so: ```ts @@ -96,11 +98,11 @@ var u16val: u16 = i8val // becomes 65408 through masking (0xFF80) var f32val: f32 = i8val // becomes -128.0 ``` -Wasm reference, GC and string types are anticipated to adhere to the following hierarchy 🦄: +Wasm reference and GC types are anticipated to adhere to the following hierarchy 🦄: Diagram of anticipated reference types hierarchy. -Dashed elements are not exposed (yet) or unclear. Exposed types have a `*ref` suffix (e.g. `anyref`) and are nullable. `(...)`-placeholders indicate the concrete subtypes, e.g. an array of a specific element type, a struct with specific field types and potentially a supertype, or a function with specific parameter and return types. For details, see [Wasm GC's subtyping rules](https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#structural-types). +Dashed elements are not exposed and/or unclear. `(...)`-placeholders indicate the concrete subtypes, e.g. an array of a specific element type, a struct with specific field types and potentially a supertype, or a function with specific parameter and return types. For details, see [Wasm GC's subtyping rules](https://github.com/WebAssembly/gc/blob/main/proposals/gc/MVP.md#structural-types). ### Comparability