feat: add a histrical wit-bindgen
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
async-no-args: async func()
|
||||
async-args: async func(a: u32, b: string, c: list<string>)
|
||||
async-results: async func() -> tuple<u32, string, list<string>>
|
||||
|
||||
resource async-resource {
|
||||
frob: async func()
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/// A function that accepts a character
|
||||
take-char: func(x: char)
|
||||
/// A function that returns a character
|
||||
return-char: func() -> char
|
||||
@@ -0,0 +1,28 @@
|
||||
// hello 🐱 world
|
||||
|
||||
kebab-case: func()
|
||||
|
||||
record ludicrous-speed {
|
||||
how-fast-are-you-going: u32,
|
||||
i-am-going-extremely-slow: u64,
|
||||
}
|
||||
|
||||
foo: func(x: ludicrous-speed)
|
||||
%function-with-dashes: func()
|
||||
%function-with-no-weird-characters: func()
|
||||
|
||||
apple: func()
|
||||
apple-pear: func()
|
||||
apple-pear-grape: func()
|
||||
garçon: func()
|
||||
hühnervögel: func()
|
||||
москва: func()
|
||||
東-京: func()
|
||||
garçon-hühnervögel-москва-東-京: func()
|
||||
a0: func()
|
||||
|
||||
%explicit: func()
|
||||
%explicit-kebab: func()
|
||||
|
||||
// Identifiers with the same name as keywords are quoted.
|
||||
%bool: func()
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
flags flag1 {
|
||||
b0,
|
||||
}
|
||||
|
||||
flags flag2 {
|
||||
b0, b1,
|
||||
}
|
||||
|
||||
flags flag4 {
|
||||
b0, b1, b2, b3,
|
||||
}
|
||||
|
||||
flags flag8 {
|
||||
b0, b1, b2, b3, b4, b5, b6, b7,
|
||||
}
|
||||
|
||||
flags flag16 {
|
||||
b0, b1, b2, b3, b4, b5, b6, b7,
|
||||
b8, b9, b10, b11, b12, b13, b14, b15,
|
||||
}
|
||||
|
||||
flags flag32 {
|
||||
b0, b1, b2, b3, b4, b5, b6, b7,
|
||||
b8, b9, b10, b11, b12, b13, b14, b15,
|
||||
b16, b17, b18, b19, b20, b21, b22, b23,
|
||||
b24, b25, b26, b27, b28, b29, b30, b31,
|
||||
}
|
||||
|
||||
flags flag64 {
|
||||
b0, b1, b2, b3, b4, b5, b6, b7,
|
||||
b8, b9, b10, b11, b12, b13, b14, b15,
|
||||
b16, b17, b18, b19, b20, b21, b22, b23,
|
||||
b24, b25, b26, b27, b28, b29, b30, b31,
|
||||
b32, b33, b34, b35, b36, b37, b38, b39,
|
||||
b40, b41, b42, b43, b44, b45, b46, b47,
|
||||
b48, b49, b50, b51, b52, b53, b54, b55,
|
||||
b56, b57, b58, b59, b60, b61, b62, b63,
|
||||
}
|
||||
|
||||
roundtrip-flag1: func(x: flag1) -> flag1
|
||||
roundtrip-flag2: func(x: flag2) -> flag2
|
||||
roundtrip-flag4: func(x: flag4) -> flag4
|
||||
roundtrip-flag8: func(x: flag8) -> flag8
|
||||
roundtrip-flag16: func(x: flag16) -> flag16
|
||||
roundtrip-flag32: func(x: flag32) -> flag32
|
||||
roundtrip-flag64: func(x: flag64) -> flag64
|
||||
@@ -0,0 +1,4 @@
|
||||
float32-param: func(x: float32)
|
||||
float64-param: func(x: float64)
|
||||
float32-result: func() -> float32
|
||||
float64-result: func() -> float64
|
||||
@@ -0,0 +1,31 @@
|
||||
a1: func(x: u8)
|
||||
a2: func(x: s8)
|
||||
a3: func(x: u16)
|
||||
a4: func(x: s16)
|
||||
a5: func(x: u32)
|
||||
a6: func(x: s32)
|
||||
a7: func(x: u64)
|
||||
a8: func(x: s64)
|
||||
|
||||
a9: func(
|
||||
p1: u8,
|
||||
p2: s8,
|
||||
p3: u16,
|
||||
p4: s16,
|
||||
p5: u32,
|
||||
p6: s32,
|
||||
p7: u64,
|
||||
p8: s64,
|
||||
)
|
||||
|
||||
|
||||
r1: func() -> u8
|
||||
r2: func() -> s8
|
||||
r3: func() -> u16
|
||||
r4: func() -> s16
|
||||
r5: func() -> u32
|
||||
r6: func() -> s32
|
||||
r7: func() -> u64
|
||||
r8: func() -> s64
|
||||
|
||||
pair-ret: func() -> tuple<s64, u8>
|
||||
@@ -0,0 +1,76 @@
|
||||
list-u8-param: func(x: list<u8>)
|
||||
list-u16-param: func(x: list<u16>)
|
||||
list-u32-param: func(x: list<u32>)
|
||||
list-u64-param: func(x: list<u64>)
|
||||
list-s8-param: func(x: list<s8>)
|
||||
list-s16-param: func(x: list<s16>)
|
||||
list-s32-param: func(x: list<s32>)
|
||||
list-s64-param: func(x: list<s64>)
|
||||
list-float32-param: func(x: list<float32>)
|
||||
list-float64-param: func(x: list<float64>)
|
||||
|
||||
list-u8-ret: func() -> list<u8>
|
||||
list-u16-ret: func() -> list<u16>
|
||||
list-u32-ret: func() -> list<u32>
|
||||
list-u64-ret: func() -> list<u64>
|
||||
list-s8-ret: func() -> list<s8>
|
||||
list-s16-ret: func() -> list<s16>
|
||||
list-s32-ret: func() -> list<s32>
|
||||
list-s64-ret: func() -> list<s64>
|
||||
list-float32-ret: func() -> list<float32>
|
||||
list-float64-ret: func() -> list<float64>
|
||||
|
||||
tuple-list: func(x: list<tuple<u8, s8>>) -> list<tuple<s64, u32>>
|
||||
string-list-arg: func(a: list<string>)
|
||||
string-list-ret: func() -> list<string>
|
||||
tuple-string-list: func(x: list<tuple<u8, string>>) -> list<tuple<string, u8>>
|
||||
string-list: func(x: list<string>) -> list<string>
|
||||
|
||||
record some-record {
|
||||
x: string,
|
||||
y: other-record,
|
||||
z: list<other-record>,
|
||||
c1: u32,
|
||||
c2: u64,
|
||||
c3: s32,
|
||||
c4: s64,
|
||||
}
|
||||
record other-record {
|
||||
a1: u32,
|
||||
a2: u64,
|
||||
a3: s32,
|
||||
a4: s64,
|
||||
b: string,
|
||||
c: list<u8>,
|
||||
}
|
||||
record-list: func(x: list<some-record>) -> list<other-record>
|
||||
record-list-reverse: func(x: list<other-record>) -> list<some-record>
|
||||
|
||||
variant some-variant {
|
||||
a(string),
|
||||
b,
|
||||
c(u32),
|
||||
d(list<other-variant>),
|
||||
}
|
||||
variant other-variant {
|
||||
a,
|
||||
b(u32),
|
||||
c(string),
|
||||
}
|
||||
variant-list: func(x: list<some-variant>) -> list<other-variant>
|
||||
|
||||
type load-store-all-sizes = list<tuple<
|
||||
string,
|
||||
u8,
|
||||
s8,
|
||||
u16,
|
||||
s16,
|
||||
u32,
|
||||
s32,
|
||||
u64,
|
||||
s64,
|
||||
float32,
|
||||
float64,
|
||||
char,
|
||||
>>
|
||||
load-store-everything: func(a: load-store-all-sizes) -> load-store-all-sizes
|
||||
@@ -0,0 +1,47 @@
|
||||
many-args: func(
|
||||
a1: u64,
|
||||
a2: u64,
|
||||
a3: u64,
|
||||
a4: u64,
|
||||
a5: u64,
|
||||
a6: u64,
|
||||
a7: u64,
|
||||
a8: u64,
|
||||
a9: u64,
|
||||
a10: u64,
|
||||
a11: u64,
|
||||
a12: u64,
|
||||
a13: u64,
|
||||
a14: u64,
|
||||
a15: u64,
|
||||
a16: u64,
|
||||
a17: u64,
|
||||
a18: u64,
|
||||
a19: u64,
|
||||
a20: u64,
|
||||
)
|
||||
|
||||
record big-struct {
|
||||
a1: string,
|
||||
a2: string,
|
||||
a3: string,
|
||||
a4: string,
|
||||
a5: string,
|
||||
a6: string,
|
||||
a7: string,
|
||||
a8: string,
|
||||
a9: string,
|
||||
a10: string,
|
||||
a11: string,
|
||||
a12: string,
|
||||
a13: string,
|
||||
a14: string,
|
||||
a15: string,
|
||||
a16: string,
|
||||
a17: string,
|
||||
a18: string,
|
||||
a19: string,
|
||||
a20: string,
|
||||
}
|
||||
|
||||
big-argument: func(x: big-struct)
|
||||
@@ -0,0 +1,52 @@
|
||||
tuple-arg: func(x: tuple<char, u32>)
|
||||
tuple-result: func() -> tuple<char, u32>
|
||||
|
||||
record empty {}
|
||||
|
||||
empty-arg: func(x: empty)
|
||||
empty-result: func() -> empty
|
||||
|
||||
/// A record containing two scalar fields
|
||||
/// that both have the same type
|
||||
record scalars {
|
||||
/// The first field, named a
|
||||
a: u32,
|
||||
/// The second field, named b
|
||||
b: u32,
|
||||
}
|
||||
|
||||
scalar-arg: func(x: scalars)
|
||||
scalar-result: func() -> scalars
|
||||
|
||||
/// A record that is really just flags
|
||||
/// All of the fields are bool
|
||||
record really-flags {
|
||||
a: bool,
|
||||
b: bool,
|
||||
c: bool,
|
||||
d: bool,
|
||||
e: bool,
|
||||
f: bool,
|
||||
g: bool,
|
||||
h: bool,
|
||||
i: bool,
|
||||
}
|
||||
|
||||
flags-arg: func(x: really-flags)
|
||||
flags-result: func() -> really-flags
|
||||
|
||||
record aggregates {
|
||||
a: scalars,
|
||||
b: u32,
|
||||
c: empty,
|
||||
d: string,
|
||||
e: really-flags,
|
||||
}
|
||||
|
||||
aggregate-arg: func(x: aggregates)
|
||||
aggregate-result: func() -> aggregates
|
||||
|
||||
type tuple-typedef = tuple<s32>
|
||||
type int-typedef = s32
|
||||
type tuple-typedef2 = tuple<int-typedef>
|
||||
typedef-inout: func(e: tuple-typedef2) -> s32
|
||||
@@ -0,0 +1,11 @@
|
||||
resource x
|
||||
|
||||
acquire-an-x: func() -> x
|
||||
receive-an-x: func(val: x)
|
||||
|
||||
resource y {
|
||||
static some-constructor: func() -> y
|
||||
method-on-y: func()
|
||||
method-with-param: func(x: u32)
|
||||
method-with-result: func() -> string
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
f1: func()
|
||||
f2: func(a: u32)
|
||||
f3: func(a: u32, b: u32)
|
||||
|
||||
f4: func() -> u32
|
||||
// TODO: reenable this when smw implements this
|
||||
//f5: func() -> tuple<u32, u32>
|
||||
//
|
||||
//f6: func(a: u32, b: u32, c: u32) -> tuple<u32, u32, u32>
|
||||
@@ -0,0 +1,5 @@
|
||||
simple-list1: func(l: list<u32>)
|
||||
simple-list2: func() -> list<u32>
|
||||
// TODO: reenable this when smw implements this
|
||||
// simple-list3: func(a: list<u32>, b: list<u32>) -> tuple<list<u32>, list<u32>>
|
||||
simple-list4: func(l: list<list<u32>>) -> list<list<u32>>
|
||||
@@ -0,0 +1,6 @@
|
||||
enum error {
|
||||
success,
|
||||
failure,
|
||||
}
|
||||
|
||||
option-test: func() -> expected<option<string>, error>
|
||||
@@ -0,0 +1 @@
|
||||
y: func()
|
||||
@@ -0,0 +1,3 @@
|
||||
a: func(x: string)
|
||||
b: func() -> string
|
||||
c: func(a: string, b: string) -> string
|
||||
@@ -0,0 +1,57 @@
|
||||
/// A union of all of the integral types
|
||||
union all-integers {
|
||||
/// Bool is equivalent to a 1 bit integer
|
||||
/// and is treated that way in some languages
|
||||
bool,
|
||||
u8, u16, u32, u64,
|
||||
s8, s16, s32, s64
|
||||
}
|
||||
union all-floats {
|
||||
float32, float64
|
||||
}
|
||||
union all-text {
|
||||
char, string
|
||||
}
|
||||
|
||||
// Returns the same case as the input but with 1 added
|
||||
add-one-integer: func(num: all-integers) -> all-integers
|
||||
// Returns the same case as the input but with 1 added
|
||||
add-one-float: func(num: all-floats) -> all-floats
|
||||
// Returns the same case as the input but with the first character replaced
|
||||
replace-first-char: func(text: all-text, letter: char) -> all-text
|
||||
|
||||
// Returns the index of the case provided
|
||||
identify-integer: func(num: all-integers) -> u8
|
||||
// Returns the index of the case provided
|
||||
identify-float: func(num: all-floats) -> u8
|
||||
// Returns the index of the case provided
|
||||
identify-text: func(text: all-text) -> u8
|
||||
|
||||
union duplicated-s32 {
|
||||
/// The first s32
|
||||
s32,
|
||||
/// The second s32
|
||||
s32,
|
||||
/// The third s32
|
||||
s32
|
||||
}
|
||||
|
||||
// Returns the same case as the input but with 1 added
|
||||
add-one-duplicated: func(num: duplicated-s32) -> duplicated-s32
|
||||
|
||||
// Returns the index of the case provided
|
||||
identify-duplicated: func(num: duplicated-s32) -> u8
|
||||
|
||||
/// A type containing numeric types that are distinct in most languages
|
||||
union distinguishable-num {
|
||||
/// A Floating Point Number
|
||||
float64,
|
||||
/// A Signed Integer
|
||||
s64
|
||||
}
|
||||
|
||||
// Returns the same case as the input but with 1 added
|
||||
add-one-distinguishable-num: func(num: distinguishable-num) -> distinguishable-num
|
||||
|
||||
// Returns the index of the case provided
|
||||
identify-distinguishable-num: func(num: distinguishable-num) -> u8
|
||||
135
__wasm/wit-bindgen-sample/wit-bindgen/tests/codegen/variants.wit
Normal file
135
__wasm/wit-bindgen-sample/wit-bindgen/tests/codegen/variants.wit
Normal file
@@ -0,0 +1,135 @@
|
||||
enum e1 {
|
||||
a,
|
||||
}
|
||||
|
||||
e1-arg: func(x: e1)
|
||||
e1-result: func() -> e1
|
||||
|
||||
union u1 {
|
||||
u32,
|
||||
float32,
|
||||
}
|
||||
|
||||
u1-arg: func(x: u1)
|
||||
u1-result: func() -> u1
|
||||
|
||||
record empty {}
|
||||
|
||||
variant v1 {
|
||||
a,
|
||||
b(u1),
|
||||
c(e1),
|
||||
d(string),
|
||||
e(empty),
|
||||
f,
|
||||
g(u32),
|
||||
}
|
||||
|
||||
v1-arg: func(x: v1)
|
||||
v1-result: func() -> v1
|
||||
|
||||
bool-arg: func(x: bool)
|
||||
bool-result: func() -> bool
|
||||
|
||||
option-arg: func(
|
||||
a: option<bool>,
|
||||
b: option<tuple<>>,
|
||||
c: option<u32>,
|
||||
d: option<e1>,
|
||||
e: option<float32>,
|
||||
f: option<u1>,
|
||||
g: option<option<bool>>,
|
||||
)
|
||||
option-result: func() -> tuple<
|
||||
option<bool>,
|
||||
option<tuple<>>,
|
||||
option<u32>,
|
||||
option<e1>,
|
||||
option<float32>,
|
||||
option<u1>,
|
||||
option<option<bool>>,
|
||||
>
|
||||
|
||||
variant casts1 {
|
||||
a(s32),
|
||||
b(float32),
|
||||
}
|
||||
|
||||
variant casts2 {
|
||||
a(float64),
|
||||
b(float32),
|
||||
}
|
||||
|
||||
variant casts3 {
|
||||
a(float64),
|
||||
b(u64),
|
||||
}
|
||||
|
||||
variant casts4 {
|
||||
a(u32),
|
||||
b(s64),
|
||||
}
|
||||
|
||||
variant casts5 {
|
||||
a(float32),
|
||||
b(s64),
|
||||
}
|
||||
|
||||
variant casts6 {
|
||||
a(tuple<float32, u32>),
|
||||
b(tuple<u32, u32>),
|
||||
}
|
||||
|
||||
casts: func(
|
||||
a: casts1,
|
||||
b: casts2,
|
||||
c: casts3,
|
||||
d: casts4,
|
||||
e: casts5,
|
||||
f: casts6,
|
||||
) -> tuple<
|
||||
casts1,
|
||||
casts2,
|
||||
casts3,
|
||||
casts4,
|
||||
casts5,
|
||||
casts6,
|
||||
>
|
||||
|
||||
expected-arg: func(
|
||||
a: expected<unit, unit>,
|
||||
b: expected<unit, e1>,
|
||||
c: expected<e1, unit>,
|
||||
d: expected<tuple<>, tuple<>>,
|
||||
e: expected<u32, v1>,
|
||||
f: expected<string, list<u8>>,
|
||||
)
|
||||
expected-result: func() -> tuple<
|
||||
expected<unit, unit>,
|
||||
expected<unit, e1>,
|
||||
expected<e1, unit>,
|
||||
expected<tuple<>, tuple<>>,
|
||||
expected<u32, v1>,
|
||||
expected<string, list<u8>>,
|
||||
>
|
||||
|
||||
enum my-errno {
|
||||
bad1,
|
||||
bad2,
|
||||
}
|
||||
|
||||
return-expected-sugar: func() -> expected<s32, my-errno>
|
||||
return-expected-sugar2: func() -> expected<unit, my-errno>
|
||||
return-expected-sugar3: func() -> expected<my-errno, my-errno>
|
||||
return-expected-sugar4: func() -> expected<tuple<s32, u32>, my-errno>
|
||||
return-option-sugar: func() -> option<s32>
|
||||
return-option-sugar2: func() -> option<my-errno>
|
||||
|
||||
expected-simple: func() -> expected<u32, s32>
|
||||
|
||||
record is-clone {
|
||||
v1: v1,
|
||||
}
|
||||
|
||||
is-clone-arg: func(a: is-clone)
|
||||
is-clone-return: func() -> is-clone
|
||||
Reference in New Issue
Block a user