From d9cd64f47f01d74df17cc705d1e6088f6c713af6 Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Fri, 26 May 2023 14:43:21 -0700 Subject: [PATCH 1/4] update go generator to re-enable codegen-tests Signed-off-by: Jiaxiao Zhou (Mossaka) --- Cargo.toml | 2 +- crates/go/src/lib.rs | 288 +++++++++++++++++++++---------------- crates/go/tests/codegen.rs | 3 - 3 files changed, 168 insertions(+), 125 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 67a9cbb49..aea7bda17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ default = [ 'rust', 'markdown', 'teavm-java', - # 'go', + 'go', ] c = ['dep:wit-bindgen-c'] rust = ['dep:wit-bindgen-rust'] diff --git a/crates/go/src/lib.rs b/crates/go/src/lib.rs index 2131a0a71..0d773c5ea 100644 --- a/crates/go/src/lib.rs +++ b/crates/go/src/lib.rs @@ -68,17 +68,21 @@ impl Opts { pub struct TinyGo { _opts: Opts, src: Source, - export_funcs: Vec<(String, String)>, world: String, needs_result_option: bool, needs_import_unsafe: bool, needs_fmt_import: bool, sizes: SizeAlign, - interface_names: HashMap, + interface_names: HashMap, } impl TinyGo { - fn interface<'a>(&'a mut self, resolve: &'a Resolve, name: &'a str) -> InterfaceGenerator<'a> { + fn interface<'a>( + &'a mut self, + resolve: &'a Resolve, + name: &'a Option<&'a WorldKey>, + in_import: bool, + ) -> InterfaceGenerator<'a> { InterfaceGenerator { src: Source::default(), gen: self, @@ -86,12 +90,10 @@ impl TinyGo { interface: None, name, public_anonymous_types: BTreeSet::new(), + in_import, + export_funcs: Vec::new(), } } - - fn clean_up_export_funcs(&mut self) { - self.export_funcs = vec![]; - } } impl WorldGenerator for TinyGo { @@ -108,12 +110,13 @@ impl WorldGenerator for TinyGo { id: InterfaceId, _files: &mut Files, ) { - // TODO: this is not a correct way to use `name` - let name = &resolve.name_world_key(name); - self.interface_names.insert(id, name.to_string()); - self.src.push_str(&format!("// {name}\n")); + let name_raw = &resolve.name_world_key(name); + self.src + .push_str(&format!("// Import functions from {name_raw}\n")); + self.interface_names.insert(id, name.clone()); - let mut gen = self.interface(resolve, name); + let binding = Some(name); + let mut gen = self.interface(resolve, &binding, true); gen.interface = Some(id); gen.types(id); @@ -134,9 +137,10 @@ impl WorldGenerator for TinyGo { _files: &mut Files, ) { let name = &resolve.worlds[world].name; - self.src.push_str(&format!("// {name}\n")); + self.src + .push_str(&format!("// Import functions from {name}\n")); - let mut gen = self.interface(resolve, name); + let mut gen = self.interface(resolve, &None, true); for (_name, func) in funcs.iter() { gen.import(resolve, func); } @@ -153,13 +157,13 @@ impl WorldGenerator for TinyGo { id: InterfaceId, _files: &mut Files, ) { - // TODO: this is not a correct way to use `name` - let name = &resolve.name_world_key(name); - self.interface_names.insert(id, name.to_string()); - self.src.push_str(&format!("// {name}\n")); - self.clean_up_export_funcs(); + self.interface_names.insert(id, name.clone()); + let name_raw = &resolve.name_world_key(name); + self.src + .push_str(&format!("// Export functions from {name_raw}\n")); - let mut gen = self.interface(resolve, name); + let binding = Some(name); + let mut gen = self.interface(resolve, &binding, false); gen.interface = Some(id); gen.types(id); @@ -171,31 +175,6 @@ impl WorldGenerator for TinyGo { let src = mem::take(&mut gen.src); self.src.push_str(&src); - - if !self.export_funcs.is_empty() { - let interface_var_name = &name.to_snake_case(); - let interface_name = &name.to_upper_camel_case(); - - self.src - .push_str(format!("var {interface_var_name} {interface_name} = nil\n").as_str()); - self.src.push_str( - format!( - "func Set{interface_name}(i {interface_name}) {{\n {interface_var_name} = i\n}}\n" - ) - .as_str(), - ); - self.src - .push_str(format!("type {interface_name} interface {{\n").as_str()); - for (interface_func_declaration, _) in &self.export_funcs { - self.src - .push_str(format!("{interface_func_declaration}\n").as_str()); - } - self.src.push_str("}\n"); - - for (_, export_func) in &self.export_funcs { - self.src.push_str(export_func); - } - } } fn export_funcs( @@ -206,10 +185,10 @@ impl WorldGenerator for TinyGo { _files: &mut Files, ) { let name = &resolve.worlds[world].name; - self.src.push_str(&format!("// {name}\n")); - self.clean_up_export_funcs(); + self.src + .push_str(&format!("// Export functions from {name}\n")); - let mut gen = self.interface(resolve, name); + let mut gen = self.interface(resolve, &None, false); for (_name, func) in funcs.iter() { gen.export(resolve, func); } @@ -218,42 +197,16 @@ impl WorldGenerator for TinyGo { let src = mem::take(&mut gen.src); self.src.push_str(&src); - - if !self.export_funcs.is_empty() { - let interface_var_name = &name.to_snake_case(); - let interface_name = &name.to_upper_camel_case(); - - self.src - .push_str(format!("var {interface_var_name} {interface_name} = nil\n").as_str()); - self.src.push_str( - format!( - "func Set{interface_name}(i {interface_name}) {{\n {interface_var_name} = i\n}}\n" - ) - .as_str(), - ); - self.src - .push_str(format!("type {interface_name} interface {{\n").as_str()); - for (interface_func_declaration, _) in &self.export_funcs { - self.src - .push_str(format!("{interface_func_declaration}\n").as_str()); - } - self.src.push_str("}\n"); - - for (_, export_func) in &self.export_funcs { - self.src.push_str(export_func); - } - } } fn export_types( &mut self, resolve: &Resolve, - world: WorldId, + _world: WorldId, types: &[(&str, TypeId)], _files: &mut Files, ) { - let name = &resolve.worlds[world].name; - let mut gen = self.interface(resolve, name); + let mut gen = self.interface(resolve, &None, false); for (name, id) in types { gen.define_type(name, *id); } @@ -422,21 +375,81 @@ struct InterfaceGenerator<'a> { gen: &'a mut TinyGo, resolve: &'a Resolve, interface: Option, - name: &'a str, + name: &'a Option<&'a WorldKey>, public_anonymous_types: BTreeSet, + in_import: bool, + export_funcs: Vec<(String, String)>, } impl InterfaceGenerator<'_> { - fn get_typedef_target(&self, name: &str) -> String { - format!( - "{}{}", - self.name.to_upper_camel_case(), - name.to_upper_camel_case() - ) + fn get_func_or_type_name(&self, name: &str) -> String { + format!("{}{}", self.get_package_name(), name.to_upper_camel_case()) + } + + fn get_c_func_name(&self, func_name: &str) -> String { + let mut name = String::new(); + match self.name { + Some(WorldKey::Name(k)) => name.push_str(&k.to_snake_case()), + Some(WorldKey::Interface(id)) => { + if !self.in_import { + name.push_str("exports_"); + } + let iface = &self.resolve.interfaces[*id]; + let pkg = &self.resolve.packages[iface.package.unwrap()]; + name.push_str(&pkg.name.namespace.to_snake_case()); + name.push('_'); + name.push_str(&pkg.name.name.to_snake_case()); + name.push('_'); + name.push_str(&iface.name.as_ref().unwrap().to_snake_case()); + } + None => name.push_str(&self.gen.world.to_snake_case()), + } + name.push('_'); + name.push_str(&func_name.to_snake_case()); + name + } + + fn get_package_name(&self) -> String { + match self.name { + Some(key) => self.get_package_name_with(key), + None => self.gen.world.to_upper_camel_case(), + } + } + + fn get_package_name_with(&self, key: &WorldKey) -> String { + let mut name = String::new(); + match key { + WorldKey::Name(k) => name.push_str(&k.to_upper_camel_case()), + WorldKey::Interface(id) => { + if !self.in_import { + name.push_str("Exports"); + } + let iface = &self.resolve.interfaces[*id]; + let pkg = &self.resolve.packages[iface.package.unwrap()]; + name.push_str(&pkg.name.namespace.to_upper_camel_case()); + name.push_str(&pkg.name.name.to_upper_camel_case()); + name.push_str(&iface.name.as_ref().unwrap().to_upper_camel_case()); + } + } + name } - fn get_c_typedef_target(&self, name: &str) -> String { - format!("{}_{}", self.name.to_snake_case(), name.to_snake_case()) + fn get_interface_var_name(&self) -> String { + let mut name = String::new(); + match self.name { + Some(WorldKey::Name(k)) => name.push_str(&k.to_snake_case()), + Some(WorldKey::Interface(id)) => { + let iface = &self.resolve.interfaces[*id]; + let pkg = &self.resolve.packages[iface.package.unwrap()]; + name.push_str(&pkg.name.namespace.to_snake_case()); + name.push('_'); + name.push_str(&pkg.name.name.to_snake_case()); + name.push('_'); + name.push_str(&iface.name.as_ref().unwrap().to_snake_case()); + } + None => name.push_str(&self.gen.world.to_snake_case()), + } + name } fn get_ty(&mut self, ty: &Type) -> String { @@ -476,16 +489,17 @@ impl InterfaceGenerator<'_> { _ => { if let Some(name) = &ty.name { let iface = if let TypeOwner::Interface(owner) = ty.owner { - self.gen.interface_names[&owner].to_upper_camel_case() + let key = &self.gen.interface_names[&owner]; + self.get_package_name_with(key) } else { - self.name.to_upper_camel_case() + self.get_package_name() }; format!("{iface}{name}", name = name.to_upper_camel_case()) } else { self.public_anonymous_types.insert(*id); format!( "{namespace}{name}", - namespace = self.name.to_upper_camel_case(), + namespace = self.get_package_name(), name = self.get_ty_name(&Type::Id(*id)), ) } @@ -520,17 +534,25 @@ impl InterfaceGenerator<'_> { match &ty.name { Some(name) => match ty.owner { TypeOwner::Interface(owner) => { - format!( - "{namespace}_{name}_t", - namespace = self.resolve.interfaces[owner] - .name - .as_ref() - .map(|s| s.to_snake_case()) - .unwrap_or_else( - || self.gen.interface_names[&owner].to_snake_case() - ), - name = name.to_snake_case(), - ) + let key = &self.gen.interface_names[&owner]; + let mut ns = match &key { + WorldKey::Name(name) => name.to_snake_case(), + WorldKey::Interface(id) => { + let mut ns = String::new(); + let iface = &self.resolve.interfaces[*id]; + let pkg = &self.resolve.packages[iface.package.unwrap()]; + ns.push_str(&pkg.name.namespace.to_snake_case()); + ns.push('_'); + ns.push_str(&pkg.name.name.to_snake_case()); + ns.push('_'); + ns.push_str(&iface.name.as_ref().unwrap().to_snake_case()); + ns + } + }; + ns.push('_'); + ns.push_str(name.to_snake_case().as_str()); + ns.push_str("_t"); + ns } TypeOwner::World(owner) => { format!( @@ -588,7 +610,8 @@ impl InterfaceGenerator<'_> { self.resolve.worlds[owner].name.to_upper_camel_case() } TypeOwner::Interface(owner) => { - self.gen.interface_names[&owner].to_upper_camel_case() + let key = &self.gen.interface_names[&owner]; + self.get_package_name_with(key) } TypeOwner::None => "".into(), }; @@ -896,10 +919,10 @@ impl InterfaceGenerator<'_> { in_import: bool, ) -> String { let mut src = Source::default(); - let name = if in_import { - self.get_c_typedef_target(&func.name) + let func_name = if in_import { + self.get_c_func_name(&func.name) } else { - self.get_typedef_target(&func.name) + self.get_func_or_type_name(&func.name) }; if !in_import { @@ -907,7 +930,7 @@ impl InterfaceGenerator<'_> { } else { src.push_str("C."); } - src.push_str(&name); + src.push_str(&func_name); src.push_str("("); // prepare args @@ -936,7 +959,7 @@ impl InterfaceGenerator<'_> { fn print_func_signature(&mut self, resolve: &Resolve, func: &Function) { self.src.push_str("func "); - let func_name = self.name.to_upper_camel_case(); + let func_name = self.get_package_name(); self.src.push_str(&func_name); let func_sig = self.get_func_signature_no_interface(resolve, func); self.src.push_str(&func_sig); @@ -995,7 +1018,7 @@ impl InterfaceGenerator<'_> { TypeDefKind::Tuple(t) => { let name = format!( "{}{}", - self.name.to_upper_camel_case(), + self.get_package_name(), self.get_ty_name(&Type::Id(ty)) ); self.src.push_str(&format!("type {name} struct {{\n",)); @@ -1194,7 +1217,7 @@ impl InterfaceGenerator<'_> { let mut src = String::new(); // header src.push_str("//export "); - let name = self.get_c_typedef_target(&func.name); + let name = self.get_c_func_name(&func.name); src.push_str(&name); src.push('\n'); @@ -1204,8 +1227,8 @@ impl InterfaceGenerator<'_> { // free all the parameters for (name, ty) in func.params.iter() { - if owns_anything(resolve, &ty) { - let free = self.get_free_c_arg(&ty, &avoid_keyword(&name.to_snake_case())); + if owns_anything(resolve, ty) { + let free = self.get_free_c_arg(ty, &avoid_keyword(&name.to_snake_case())); src.push_str(&free); } } @@ -1217,7 +1240,7 @@ impl InterfaceGenerator<'_> { // invoke let invoke = format!( "{}.{}({})", - &self.name.to_snake_case(), + &self.get_interface_var_name(), &func.name.to_upper_camel_case(), args.iter() .enumerate() @@ -1268,15 +1291,38 @@ impl InterfaceGenerator<'_> { src.push_str("\n}\n"); src }; - self.gen - .export_funcs - .push((interface_method_decl, export_func)); + self.export_funcs.push((interface_method_decl, export_func)); } fn finish(&mut self) { while let Some(ty) = self.public_anonymous_types.pop_last() { self.print_anonymous_type(ty); } + + if !self.in_import && !self.export_funcs.is_empty() { + let interface_var_name = &self.get_interface_var_name(); + let interface_name = &self.get_package_name(); + + self.src + .push_str(format!("var {interface_var_name} {interface_name} = nil\n").as_str()); + self.src.push_str( + format!( + "func Set{interface_name}(i {interface_name}) {{\n {interface_var_name} = i\n}}\n" + ) + .as_str(), + ); + self.src + .push_str(format!("type {interface_name} interface {{\n").as_str()); + for (interface_func_declaration, _) in &self.export_funcs { + self.src + .push_str(format!("{interface_func_declaration}\n").as_str()); + } + self.src.push_str("}\n"); + + for (_, export_func) in &self.export_funcs { + self.src.push_str(export_func); + } + } } } @@ -1292,7 +1338,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { record: &wit_bindgen_core::wit_parser::Record, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_typedef_target(name); + let name = self.get_func_or_type_name(name); self.src.push_str(&format!("type {name} struct {{\n",)); for field in record.fields.iter() { let ty = self.get_ty(&field.ty); @@ -1309,7 +1355,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { flags: &wit_bindgen_core::wit_parser::Flags, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_typedef_target(name); + let name = self.get_func_or_type_name(name); // TODO: use flags repr to determine how many flags are needed self.src.push_str(&format!("type {name} uint64\n")); self.src.push_str("const (\n"); @@ -1338,7 +1384,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { tuple: &wit_bindgen_core::wit_parser::Tuple, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_typedef_target(name); + let name = self.get_func_or_type_name(name); self.src.push_str(&format!("type {name} struct {{\n",)); for (i, case) in tuple.types.iter().enumerate() { let ty = self.get_ty(case); @@ -1354,7 +1400,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { variant: &wit_bindgen_core::wit_parser::Variant, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_typedef_target(name); + let name = self.get_func_or_type_name(name); // TODO: use variant's tag to determine how many cases are needed // this will help to optmize the Kind type. self.src.push_str(&format!("type {name}Kind int\n\n")); @@ -1411,7 +1457,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { union: &wit_bindgen_core::wit_parser::Union, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_typedef_target(name); + let name = self.get_func_or_type_name(name); // TODO: use variant's tag to determine how many cases are needed // this will help to optmize the Kind type. self.src.push_str(&format!("type {name}Kind int\n\n")); @@ -1445,7 +1491,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { enum_: &wit_bindgen_core::wit_parser::Enum, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_typedef_target(name); + let name = self.get_func_or_type_name(name); // TODO: use variant's tag to determine how many cases are needed // this will help to optmize the Kind type. self.src.push_str(&format!("type {name}Kind int\n\n")); @@ -1476,7 +1522,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { ty: &wit_bindgen_core::wit_parser::Type, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_typedef_target(name); + let name = self.get_func_or_type_name(name); let ty = self.get_ty(ty); self.src.push_str(&format!("type {name} = {ty}\n")); } @@ -1488,7 +1534,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { ty: &wit_bindgen_core::wit_parser::Type, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_typedef_target(name); + let name = self.get_func_or_type_name(name); let ty = self.get_ty(ty); self.src.push_str(&format!("type {name} = {ty}\n")); } diff --git a/crates/go/tests/codegen.rs b/crates/go/tests/codegen.rs index 987015908..e40753721 100644 --- a/crates/go/tests/codegen.rs +++ b/crates/go/tests/codegen.rs @@ -11,9 +11,6 @@ macro_rules! codegen_test { (issue544 $name:tt $test:tt) => {}; (issue551 $name:tt $test:tt) => {}; - // TODO: should fix handling of new `WorldKey` in go generator - ($id:ident $name:tt $test:tt) => {}; - ($id:ident $name:tt $test:tt) => { #[test] fn $id() { From f74ba82e8a1c10ad23cc5f7e06c6781f29b62f8a Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Fri, 26 May 2023 15:40:58 -0700 Subject: [PATCH 2/4] Re-enable runtime tests Signed-off-by: Jiaxiao Zhou (Mossaka) --- tests/runtime/flavorful/wasm.go | 92 +++++----- tests/runtime/lists/wasm.go | 96 +++++----- tests/runtime/main.rs | 5 +- tests/runtime/numbers/wasm.go | 78 ++++---- tests/runtime/records/wasm.go | 72 ++++---- tests/runtime/smoke/wasm.go | 2 +- tests/runtime/unions/wasm.go | 312 ++++++++++++++++---------------- 7 files changed, 327 insertions(+), 330 deletions(-) diff --git a/tests/runtime/flavorful/wasm.go b/tests/runtime/flavorful/wasm.go index 721d0a3a4..78f289809 100644 --- a/tests/runtime/flavorful/wasm.go +++ b/tests/runtime/flavorful/wasm.go @@ -7,52 +7,52 @@ import ( func init() { n := &FlavorfulImpl{} SetFlavorful(n) - SetExports(n) + SetExportsTestFlavorfulTest(n) } type FlavorfulImpl struct{} func (f FlavorfulImpl) TestImports() { - ImportsFListInRecord1(ImportsListInRecord1{"list_in_record1"}) - if ImportsFListInRecord2().A != "list_in_record2" { - panic("ImportsFListInRecord2") + TestFlavorfulTestFListInRecord1(TestFlavorfulTestListInRecord1{"list_in_record1"}) + if TestFlavorfulTestFListInRecord2().A != "list_in_record2" { + panic("TestFlavorfulTestFListInRecord2") } - if ImportsFListInRecord3(ImportsListInRecord3{"list_in_record3 input"}).A != "list_in_record3 output" { - panic("ImportsFListInRecord3") + if TestFlavorfulTestFListInRecord3(TestFlavorfulTestListInRecord3{"list_in_record3 input"}).A != "list_in_record3 output" { + panic("TestFlavorfulTestFListInRecord3") } - if ImportsFListInRecord4(ImportsListInAlias{"input4"}).A != "result4" { - panic("ImportsFListInRecord4") + if TestFlavorfulTestFListInRecord4(TestFlavorfulTestListInAlias{"input4"}).A != "result4" { + panic("TestFlavorfulTestFListInRecord4") } var b Result[struct{}, string] b.SetErr("bar") - ImportsFListInVariant1(Some[string]("foo"), b, ImportsListInVariant1V3F0("baz")) - if ImportsFListInVariant2().Unwrap() != "list_in_variant2" { - panic("ImportsFListInVariant2") + TestFlavorfulTestFListInVariant1(Some[string]("foo"), b, TestFlavorfulTestListInVariant1V3F0("baz")) + if TestFlavorfulTestFListInVariant2().Unwrap() != "list_in_variant2" { + panic("TestFlavorfulTestFListInVariant2") } - if ImportsFListInVariant3(Some[string]("input3")).Unwrap() != "output3" { - panic("ImportsFListInVariant3") + if TestFlavorfulTestFListInVariant3(Some[string]("input3")).Unwrap() != "output3" { + panic("TestFlavorfulTestFListInVariant3") } - if !ImportsErrnoResult().IsErr() { - panic("ImportsErrnoResult") + if !TestFlavorfulTestErrnoResult().IsErr() { + panic("TestFlavorfulTestErrnoResult") } - ImportsMyErrnoA() + TestFlavorfulTestMyErrnoA() // TODO: be able to print my_error_a - if !ImportsErrnoResult().IsOk() { - panic("ImportsErrnoResult") + if !TestFlavorfulTestErrnoResult().IsOk() { + panic("TestFlavorfulTestErrnoResult") } - t1, t2 := ImportsListTypedefs("typedef1", []string{"typedef2"}) + t1, t2 := TestFlavorfulTestListTypedefs("typedef1", []string{"typedef2"}) if len(t1) != 8 { - panic("ImportsListTypedefs") + panic("TestFlavorfulTestListTypedefs") } if len(t2) != 1 { - panic("ImportsListTypedefs") + panic("TestFlavorfulTestListTypedefs") } if t2[0] != "typedef4" { - panic("ImportsListTypedefs") + panic("TestFlavorfulTestListTypedefs") } var v2_ok Result[struct{}, struct{}] @@ -60,57 +60,57 @@ func (f FlavorfulImpl) TestImports() { var v2_err Result[struct{}, struct{}] v2_err.SetErr(struct{}{}) - v1, v2, v3 := ImportsListOfVariants( + v1, v2, v3 := TestFlavorfulTestListOfVariants( []bool{true, false}, []Result[struct{}, struct{}]{v2_ok, v2_err}, - []ImportsMyErrno{ImportsMyErrnoSuccess(), ImportsMyErrnoA()}, + []TestFlavorfulTestMyErrno{TestFlavorfulTestMyErrnoSuccess(), TestFlavorfulTestMyErrnoA()}, ) if v1[0] != false { - panic("ImportsListOfVariants") + panic("TestFlavorfulTestListOfVariants") } if v1[1] != true { - panic("ImportsListOfVariants") + panic("TestFlavorfulTestListOfVariants") } if v2[0].IsOk() { - panic("ImportsListOfVariants") + panic("TestFlavorfulTestListOfVariants") } if v2[1].IsErr() { - panic("ImportsListOfVariants") + panic("TestFlavorfulTestListOfVariants") } - if v3[0].Kind() != ImportsMyErrnoKindA { - panic("ImportsListOfVariants") + if v3[0].Kind() != TestFlavorfulTestMyErrnoKindA { + panic("TestFlavorfulTestListOfVariants") } - if v3[1].Kind() != ImportsMyErrnoKindB { - panic("ImportsListOfVariants") + if v3[1].Kind() != TestFlavorfulTestMyErrnoKindB { + panic("TestFlavorfulTestListOfVariants") } } -func (f FlavorfulImpl) FListInRecord1(a ExportsListInRecord1) { +func (f FlavorfulImpl) FListInRecord1(a ExportsTestFlavorfulTestListInRecord1) { if a.A != "list_in_record1" { panic("FListInRecord1") } } -func (f FlavorfulImpl) FListInRecord2() ExportsListInRecord2 { - return ExportsListInRecord2{"list_in_record2"} +func (f FlavorfulImpl) FListInRecord2() ExportsTestFlavorfulTestListInRecord2 { + return ExportsTestFlavorfulTestListInRecord2{"list_in_record2"} } -func (f FlavorfulImpl) FListInRecord3(a ExportsListInRecord3) ExportsListInRecord3 { +func (f FlavorfulImpl) FListInRecord3(a ExportsTestFlavorfulTestListInRecord3) ExportsTestFlavorfulTestListInRecord3 { if a.A != "list_in_record3 input" { panic("FListInRecord3") } - return ExportsListInRecord3{"list_in_record3 output"} + return ExportsTestFlavorfulTestListInRecord3{"list_in_record3 output"} } -func (f FlavorfulImpl) FListInRecord4(a ExportsListInRecord4) ExportsListInRecord4 { +func (f FlavorfulImpl) FListInRecord4(a ExportsTestFlavorfulTestListInRecord4) ExportsTestFlavorfulTestListInRecord4 { if a.A != "input4" { panic("FListInRecord4") } - return ExportsListInRecord4{"result4"} + return ExportsTestFlavorfulTestListInRecord4{"result4"} } -func (f FlavorfulImpl) FListInVariant1(a Option[string], b Result[struct{}, string], c ExportsListInVariant1V3) { +func (f FlavorfulImpl) FListInVariant1(a Option[string], b Result[struct{}, string], c ExportsTestFlavorfulTestListInVariant1V3) { if a.Unwrap() != "foo" { panic("FListInVariant1") } @@ -118,11 +118,11 @@ func (f FlavorfulImpl) FListInVariant1(a Option[string], b Result[struct{}, stri panic("FListInVariant1") } switch c.Kind() { - case ExportsListInVariant1V3KindF0: + case ExportsTestFlavorfulTestListInVariant1V3KindF0: if c.GetF0() != "baz" { panic("FListInVariant1") } - case ExportsListInVariant1V3KindF1: + case ExportsTestFlavorfulTestListInVariant1V3KindF1: panic("FListInVariant1") } } @@ -138,9 +138,9 @@ func (f FlavorfulImpl) FListInVariant3(a Option[string]) Option[string] { return Some[string]("output3") } -func (f FlavorfulImpl) ErrnoResult() Result[struct{}, ExportsMyErrno] { - var res Result[struct{}, ExportsMyErrno] - res.SetErr(ExportsMyErrnoB()) +func (f FlavorfulImpl) ErrnoResult() Result[struct{}, ExportsTestFlavorfulTestMyErrno] { + var res Result[struct{}, ExportsTestFlavorfulTestMyErrno] + res.SetErr(ExportsTestFlavorfulTestMyErrnoB()) return res } @@ -157,7 +157,7 @@ func (f FlavorfulImpl) ListTypedefs(a string, c []string) ([]uint8, []string) { return []uint8("typedef3"), []string{"typedef4"} } -func (f FlavorfulImpl) ListOfVariants(a []bool, b []Result[struct{}, struct{}], c []ExportsMyErrno) ([]bool, []Result[struct{}, struct{}], []ExportsMyErrno) { +func (f FlavorfulImpl) ListOfVariants(a []bool, b []Result[struct{}, struct{}], c []ExportsTestFlavorfulTestMyErrno) ([]bool, []Result[struct{}, struct{}], []ExportsTestFlavorfulTestMyErrno) { return a, b, c } diff --git a/tests/runtime/lists/wasm.go b/tests/runtime/lists/wasm.go index 7689ef19d..4a8b53b9a 100644 --- a/tests/runtime/lists/wasm.go +++ b/tests/runtime/lists/wasm.go @@ -8,123 +8,123 @@ import ( func init() { a := ListImpl{} SetLists(a) - SetExports(a) + SetExportsTestListsTest(a) } type ListImpl struct { } func (i ListImpl) TestImports() { - ImportsEmptyListParam([]uint8{}) - ImportsEmptyStringParam("") - res := ImportsEmptyListResult() + TestListsTestEmptyListParam([]uint8{}) + TestListsTestEmptyStringParam("") + res := TestListsTestEmptyListResult() if len(res) != 0 { - panic("ImportsEmptyListResult") + panic("TestListsTestEmptyListResult") } - res2 := ImportsEmptyStringResult() + res2 := TestListsTestEmptyStringResult() if res2 != "" { - panic("ImportsEmptyStringResult") + panic("TestListsTestEmptyStringResult") } - ImportsListParam([]uint8{1, 2, 3, 4}) - ImportsListParam2("foo") - ImportsListParam3([]string{"foo", "bar", "baz"}) - ImportsListParam4([][]string{{"foo", "bar"}, {"baz"}}) - res3 := ImportsListResult() + TestListsTestListParam([]uint8{1, 2, 3, 4}) + TestListsTestListParam2("foo") + TestListsTestListParam3([]string{"foo", "bar", "baz"}) + TestListsTestListParam4([][]string{{"foo", "bar"}, {"baz"}}) + res3 := TestListsTestListResult() if len(res3) != 5 { - panic("ImportsListResult") + panic("TestListsTestListResult") } for i := range res3 { if res3[i] != uint8(i+1) { - panic("ImportsListResult") + panic("TestListsTestListResult") } } - res4 := ImportsListResult2() + res4 := TestListsTestListResult2() if res4 != "hello!" { - panic("ImportsListResult2") + panic("TestListsTestListResult2") } - res5 := ImportsListResult3() + res5 := TestListsTestListResult3() if len(res5) != 2 { - panic("ImportsListResult3") + panic("TestListsTestListResult3") } if res5[0] != "hello," { - panic("ImportsListResult3") + panic("TestListsTestListResult3") } if res5[1] != "world!" { - panic("ImportsListResult3") + panic("TestListsTestListResult3") } - res6 := ImportsListRoundtrip([]uint8{}) + res6 := TestListsTestListRoundtrip([]uint8{}) if len(res6) != 0 { - panic("ImportsListRoundtrip") + panic("TestListsTestListRoundtrip") } - res7 := ImportsListRoundtrip([]uint8{1, 2, 3, 4, 5}) + res7 := TestListsTestListRoundtrip([]uint8{1, 2, 3, 4, 5}) if len(res7) != 5 { - panic("ImportsListRoundtrip") + panic("TestListsTestListRoundtrip") } - res8 := ImportsStringRoundtrip("") + res8 := TestListsTestStringRoundtrip("") if res8 != "" { - panic("ImportsStringRoundtrip") + panic("TestListsTestStringRoundtrip") } - res9 := ImportsStringRoundtrip("hello ⚑ world") + res9 := TestListsTestStringRoundtrip("hello ⚑ world") if res9 != "hello ⚑ world" { - panic("ImportsStringRoundtrip") + panic("TestListsTestStringRoundtrip") } - u8, i8 := ImportsListMinmax8([]uint8{0, math.MaxUint8}, []int8{math.MinInt8, math.MaxInt8}) + u8, i8 := TestListsTestListMinmax8([]uint8{0, math.MaxUint8}, []int8{math.MinInt8, math.MaxInt8}) if u8[0] != uint8(0) { - panic("ImportsListMinmax8") + panic("TestListsTestListMinmax8") } if u8[1] != math.MaxUint8 { - panic("ImportsListMinmax8") + panic("TestListsTestListMinmax8") } if i8[0] != math.MinInt8 { - panic("ImportsListMinmax8") + panic("TestListsTestListMinmax8") } if i8[1] != math.MaxInt8 { - panic("ImportsListMinmax8") + panic("TestListsTestListMinmax8") } - u16, i16 := ImportsListMinmax16([]uint16{0, math.MaxUint16}, []int16{math.MinInt16, math.MaxInt16}) + u16, i16 := TestListsTestListMinmax16([]uint16{0, math.MaxUint16}, []int16{math.MinInt16, math.MaxInt16}) if u16[0] != uint16(0) { - panic("ImportsListMinmax16") + panic("TestListsTestListMinmax16") } if u16[1] != math.MaxUint16 { - panic("ImportsListMinmax16") + panic("TestListsTestListMinmax16") } if i16[0] != math.MinInt16 { - panic("ImportsListMinmax16") + panic("TestListsTestListMinmax16") } if i16[1] != math.MaxInt16 { - panic("ImportsListMinmax16") + panic("TestListsTestListMinmax16") } - u32, i32 := ImportsListMinmax32([]uint32{0, math.MaxUint32}, []int32{math.MinInt32, math.MaxInt32}) + u32, i32 := TestListsTestListMinmax32([]uint32{0, math.MaxUint32}, []int32{math.MinInt32, math.MaxInt32}) if u32[0] != uint32(0) { - panic("ImportsListMinmax32") + panic("TestListsTestListMinmax32") } if u32[1] != math.MaxUint32 { - panic("ImportsListMinmax32") + panic("TestListsTestListMinmax32") } if i32[0] != math.MinInt32 { - panic("ImportsListMinmax32") + panic("TestListsTestListMinmax32") } if i32[1] != math.MaxInt32 { - panic("ImportsListMinmax32") + panic("TestListsTestListMinmax32") } - u64, i64 := ImportsListMinmax64([]uint64{0, math.MaxUint64}, []int64{math.MinInt64, math.MaxInt64}) + u64, i64 := TestListsTestListMinmax64([]uint64{0, math.MaxUint64}, []int64{math.MinInt64, math.MaxInt64}) if u64[0] != uint64(0) { - panic("ImportsListMinmax64") + panic("TestListsTestListMinmax64") } if u64[1] != math.MaxUint64 { - panic("ImportsListMinmax64") + panic("TestListsTestListMinmax64") } if i64[0] != math.MinInt64 { - panic("ImportsListMinmax64") + panic("TestListsTestListMinmax64") } if i64[1] != math.MaxInt64 { - panic("ImportsListMinmax64") + panic("TestListsTestListMinmax64") } } diff --git a/tests/runtime/main.rs b/tests/runtime/main.rs index 36e8f09e7..8e0950929 100644 --- a/tests/runtime/main.rs +++ b/tests/runtime/main.rs @@ -211,10 +211,7 @@ fn tests(name: &str) -> Result> { } #[cfg(feature = "go")] - if !go.is_empty() - // FIXME: needs fixing after #545 - && false - { + if !go.is_empty() { let world_name = &resolve.worlds[world].name; let out_dir = out_dir.join(format!("go-{}", world_name)); drop(fs::remove_dir_all(&out_dir)); diff --git a/tests/runtime/numbers/wasm.go b/tests/runtime/numbers/wasm.go index ce3c4e687..f89c0782c 100644 --- a/tests/runtime/numbers/wasm.go +++ b/tests/runtime/numbers/wasm.go @@ -9,7 +9,7 @@ import ( func init() { n := &NumbersImpl{} SetNumbers(n) - SetExports(n) + SetExportsTestNumbersTest(n) } type NumbersImpl struct { @@ -17,126 +17,126 @@ type NumbersImpl struct { } func (i NumbersImpl) TestImports() { - if ImportsRoundtripU8(1) != 1 { + if TestNumbersTestRoundtripU8(1) != 1 { panic("roundtrip-u8") } - if ImportsRoundtripU8(0) != 0 { + if TestNumbersTestRoundtripU8(0) != 0 { panic("roundtrip-u8") } - if ImportsRoundtripU8(math.MaxUint8) != math.MaxUint8 { + if TestNumbersTestRoundtripU8(math.MaxUint8) != math.MaxUint8 { panic("roundtrip-u8") } - if ImportsRoundtripS8(1) != 1 { + if TestNumbersTestRoundtripS8(1) != 1 { panic("roundtrip-s8") } - if ImportsRoundtripS8(math.MaxInt8) != math.MaxInt8 { + if TestNumbersTestRoundtripS8(math.MaxInt8) != math.MaxInt8 { panic("roundtrip-s8") } - if ImportsRoundtripS8(math.MinInt8) != math.MinInt8 { + if TestNumbersTestRoundtripS8(math.MinInt8) != math.MinInt8 { panic("roundtrip-s8") } - if ImportsRoundtripU16(1) != 1 { + if TestNumbersTestRoundtripU16(1) != 1 { panic("roundtrip-u16") } - if ImportsRoundtripU16(0) != 0 { + if TestNumbersTestRoundtripU16(0) != 0 { panic("roundtrip-u16") } - if ImportsRoundtripU16(math.MaxUint16) != math.MaxUint16 { + if TestNumbersTestRoundtripU16(math.MaxUint16) != math.MaxUint16 { panic("roundtrip-u16") } - if ImportsRoundtripS16(1) != 1 { + if TestNumbersTestRoundtripS16(1) != 1 { panic("roundtrip-s16") } - if ImportsRoundtripS16(math.MaxInt16) != math.MaxInt16 { + if TestNumbersTestRoundtripS16(math.MaxInt16) != math.MaxInt16 { panic("roundtrip-s16") } - if ImportsRoundtripS16(math.MinInt16) != math.MinInt16 { + if TestNumbersTestRoundtripS16(math.MinInt16) != math.MinInt16 { panic("roundtrip-s16") } - if ImportsRoundtripU32(1) != 1 { + if TestNumbersTestRoundtripU32(1) != 1 { panic("roundtrip-u32") } - if ImportsRoundtripU32(0) != 0 { + if TestNumbersTestRoundtripU32(0) != 0 { panic("roundtrip-u32") } - if ImportsRoundtripU32(math.MaxUint32) != math.MaxUint32 { + if TestNumbersTestRoundtripU32(math.MaxUint32) != math.MaxUint32 { panic("roundtrip-u32") } - if ImportsRoundtripS32(1) != 1 { + if TestNumbersTestRoundtripS32(1) != 1 { panic("roundtrip-s32") } - if ImportsRoundtripS32(math.MaxInt32) != math.MaxInt32 { + if TestNumbersTestRoundtripS32(math.MaxInt32) != math.MaxInt32 { panic("roundtrip-s32") } - if ImportsRoundtripS32(math.MinInt32) != math.MinInt32 { + if TestNumbersTestRoundtripS32(math.MinInt32) != math.MinInt32 { panic("roundtrip-s32") } - if ImportsRoundtripU64(1) != 1 { + if TestNumbersTestRoundtripU64(1) != 1 { panic("roundtrip-u64") } - if ImportsRoundtripU64(0) != 0 { + if TestNumbersTestRoundtripU64(0) != 0 { panic("roundtrip-u64") } - if ImportsRoundtripU64(math.MaxUint64) != math.MaxUint64 { + if TestNumbersTestRoundtripU64(math.MaxUint64) != math.MaxUint64 { panic("roundtrip-u64") } - if ImportsRoundtripS64(1) != 1 { + if TestNumbersTestRoundtripS64(1) != 1 { panic("roundtrip-s64") } - if ImportsRoundtripS64(math.MaxInt64) != math.MaxInt64 { + if TestNumbersTestRoundtripS64(math.MaxInt64) != math.MaxInt64 { panic("roundtrip-s64") } - if ImportsRoundtripS64(math.MinInt64) != math.MinInt64 { + if TestNumbersTestRoundtripS64(math.MinInt64) != math.MinInt64 { panic("roundtrip-s64") } - if ImportsRoundtripFloat32(1.0) != 1.0 { + if TestNumbersTestRoundtripFloat32(1.0) != 1.0 { panic("roundtrip-float32") } - if ImportsRoundtripFloat32(math.MaxFloat32) != math.MaxFloat32 { + if TestNumbersTestRoundtripFloat32(math.MaxFloat32) != math.MaxFloat32 { panic("roundtrip-float32") } - if ImportsRoundtripFloat32(math.SmallestNonzeroFloat32) != math.SmallestNonzeroFloat32 { + if TestNumbersTestRoundtripFloat32(math.SmallestNonzeroFloat32) != math.SmallestNonzeroFloat32 { panic("roundtrip-float32") } - if ImportsRoundtripFloat64(1.0) != 1.0 { + if TestNumbersTestRoundtripFloat64(1.0) != 1.0 { panic("roundtrip-float64") } - if ImportsRoundtripFloat64(math.MaxFloat64) != math.MaxFloat64 { + if TestNumbersTestRoundtripFloat64(math.MaxFloat64) != math.MaxFloat64 { panic("roundtrip-float64") } - if ImportsRoundtripFloat64(math.SmallestNonzeroFloat64) != math.SmallestNonzeroFloat64 { + if TestNumbersTestRoundtripFloat64(math.SmallestNonzeroFloat64) != math.SmallestNonzeroFloat64 { panic("roundtrip-float64") } - if !math.IsNaN(ImportsRoundtripFloat64(math.NaN())) { + if !math.IsNaN(TestNumbersTestRoundtripFloat64(math.NaN())) { panic("roundtrip-float64") } - if ImportsRoundtripChar('a') != 'a' { + if TestNumbersTestRoundtripChar('a') != 'a' { panic("roundtrip-char") } - if ImportsRoundtripChar(' ') != ' ' { + if TestNumbersTestRoundtripChar(' ') != ' ' { panic("roundtrip-char") } - if ImportsRoundtripChar('🚩') != '🚩' { + if TestNumbersTestRoundtripChar('🚩') != '🚩' { panic("roundtrip-char") } - ImportsSetScalar(2) - if ImportsGetScalar() != 2 { + TestNumbersTestSetScalar(2) + if TestNumbersTestGetScalar() != 2 { panic("get-scalar") } - ImportsSetScalar(4) - if ImportsGetScalar() != 4 { + TestNumbersTestSetScalar(4) + if TestNumbersTestGetScalar() != 4 { panic("get-scalar") } } diff --git a/tests/runtime/records/wasm.go b/tests/runtime/records/wasm.go index 85cad6127..a6a5cd808 100644 --- a/tests/runtime/records/wasm.go +++ b/tests/runtime/records/wasm.go @@ -7,59 +7,59 @@ import ( func init() { n := &RecordImpl{} SetRecords(n) - SetExports(n) + SetExportsTestRecordsTest(n) } type RecordImpl struct{} func (r *RecordImpl) TestImports() { - a, b := ImportsMultipleResults() + a, b := TestRecordsTestMultipleResults() if a != 4 && b != 5 { - panic("ImportsMultipleResults") + panic("TestRecordsTestMultipleResults") } - t := ImportsSwapTuple(ImportsTuple2U8U32T{1, 2}) + t := TestRecordsTestSwapTuple(TestRecordsTestTuple2U8U32T{1, 2}) if t.F0 != 2 && t.F1 != 1 { - panic("ImportsSwapTuple") + panic("TestRecordsTestSwapTuple") } // TODO: how to handle empty flags? - if ImportsRoundtripFlags1(ImportsF1_A) != ImportsF1_A { - panic("ImportsRoundtripFlags1") + if TestRecordsTestRoundtripFlags1(TestRecordsTestF1_A) != TestRecordsTestF1_A { + panic("TestRecordsTestRoundtripFlags1") } - if ImportsRoundtripFlags1(ImportsF1_B) != ImportsF1_B { - panic("ImportsRoundtripFlags1") + if TestRecordsTestRoundtripFlags1(TestRecordsTestF1_B) != TestRecordsTestF1_B { + panic("TestRecordsTestRoundtripFlags1") } - if ImportsRoundtripFlags1(ImportsF1_A|ImportsF1_B) != ImportsF1_A|ImportsF1_B { - panic("ImportsRoundtripFlags1") + if TestRecordsTestRoundtripFlags1(TestRecordsTestF1_A|TestRecordsTestF1_B) != TestRecordsTestF1_A|TestRecordsTestF1_B { + panic("TestRecordsTestRoundtripFlags1") } - if ImportsRoundtripFlags2(ImportsF2_C) != ImportsF2_C { - panic("ImportsRoundtripFlags2") + if TestRecordsTestRoundtripFlags2(TestRecordsTestF2_C) != TestRecordsTestF2_C { + panic("TestRecordsTestRoundtripFlags2") } - if ImportsRoundtripFlags2(ImportsF2_D) != ImportsF2_D { - panic("ImportsRoundtripFlags2") + if TestRecordsTestRoundtripFlags2(TestRecordsTestF2_D) != TestRecordsTestF2_D { + panic("TestRecordsTestRoundtripFlags2") } - if ImportsRoundtripFlags2(ImportsF2_C|ImportsF2_E) != ImportsF2_C|ImportsF2_E { - panic("ImportsRoundtripFlags2") + if TestRecordsTestRoundtripFlags2(TestRecordsTestF2_C|TestRecordsTestF2_E) != TestRecordsTestF2_C|TestRecordsTestF2_E { + panic("TestRecordsTestRoundtripFlags2") } - if a, b, c, d := ImportsRoundtripFlags3(ImportsFlag8_B0, ImportsFlag16_B1, ImportsFlag32_B2, ImportsFlag64_B3); a != ImportsFlag8_B0 && b != ImportsFlag16_B1 && c != ImportsFlag32_B2 && d != ImportsFlag64_B3 { - panic("ImportsRoundtripFlags3") + if a, b, c, d := TestRecordsTestRoundtripFlags3(TestRecordsTestFlag8_B0, TestRecordsTestFlag16_B1, TestRecordsTestFlag32_B2, TestRecordsTestFlag64_B3); a != TestRecordsTestFlag8_B0 && b != TestRecordsTestFlag16_B1 && c != TestRecordsTestFlag32_B2 && d != TestRecordsTestFlag64_B3 { + panic("TestRecordsTestRoundtripFlags3") } - r1 := ImportsRoundtripRecord1(ImportsR1{8, ImportsF1_A}) - if r1.A != 8 && r1.B != ImportsF1_A { - panic("ImportsRoundtripRecord1") + r1 := TestRecordsTestRoundtripRecord1(TestRecordsTestR1{8, TestRecordsTestF1_A}) + if r1.A != 8 && r1.B != TestRecordsTestF1_A { + panic("TestRecordsTestRoundtripRecord1") } - r2 := ImportsRoundtripRecord1(ImportsR1{0, ImportsF1_A | ImportsF1_B}) - if r2.A != 0 && r2.B != ImportsF1_A|ImportsF1_B { - panic("ImportsRoundtripRecord1") + r2 := TestRecordsTestRoundtripRecord1(TestRecordsTestR1{0, TestRecordsTestF1_A | TestRecordsTestF1_B}) + if r2.A != 0 && r2.B != TestRecordsTestF1_A|TestRecordsTestF1_B { + panic("TestRecordsTestRoundtripRecord1") } - ImportsTuple0(ImportsTuple0T{}) - if ImportsTuple1(ImportsTuple1U8T{1}).F0 != 1 { - panic("ImportsTuple0") + TestRecordsTestTuple0(TestRecordsTestTuple0T{}) + if TestRecordsTestTuple1(TestRecordsTestTuple1U8T{1}).F0 != 1 { + panic("TestRecordsTestTuple0") } } @@ -67,31 +67,31 @@ func (r *RecordImpl) MultipleResults() (uint8, uint16) { return 100, 200 } -func (r *RecordImpl) SwapTuple(a ExportsTuple2U8U32T) ExportsTuple2U32U8T { - return ExportsTuple2U32U8T{a.F1, a.F0} +func (r *RecordImpl) SwapTuple(a ExportsTestRecordsTestTuple2U8U32T) ExportsTestRecordsTestTuple2U32U8T { + return ExportsTestRecordsTestTuple2U32U8T{a.F1, a.F0} } -func (r *RecordImpl) RoundtripFlags1(a ExportsF1) ExportsF1 { +func (r *RecordImpl) RoundtripFlags1(a ExportsTestRecordsTestF1) ExportsTestRecordsTestF1 { return a } -func (r *RecordImpl) RoundtripFlags2(a ExportsF2) ExportsF2 { +func (r *RecordImpl) RoundtripFlags2(a ExportsTestRecordsTestF2) ExportsTestRecordsTestF2 { return a } -func (r *RecordImpl) RoundtripFlags3(a ExportsFlag8, b ExportsFlag16, c ExportsFlag32, d ExportsFlag64) (ExportsFlag8, ExportsFlag16, ExportsFlag32, ExportsFlag64) { +func (r *RecordImpl) RoundtripFlags3(a ExportsTestRecordsTestFlag8, b ExportsTestRecordsTestFlag16, c ExportsTestRecordsTestFlag32, d ExportsTestRecordsTestFlag64) (ExportsTestRecordsTestFlag8, ExportsTestRecordsTestFlag16, ExportsTestRecordsTestFlag32, ExportsTestRecordsTestFlag64) { return a, b, c, d } -func (r *RecordImpl) RoundtripRecord1(a ExportsR1) ExportsR1 { +func (r *RecordImpl) RoundtripRecord1(a ExportsTestRecordsTestR1) ExportsTestRecordsTestR1 { return a } -func (r *RecordImpl) Tuple0(a ExportsTuple0T) ExportsTuple0T { +func (r *RecordImpl) Tuple0(a ExportsTestRecordsTestTuple0T) ExportsTestRecordsTestTuple0T { return a } -func (r *RecordImpl) Tuple1(a ExportsTuple1U8T) ExportsTuple1U8T { +func (r *RecordImpl) Tuple1(a ExportsTestRecordsTestTuple1U8T) ExportsTestRecordsTestTuple1U8T { return a } diff --git a/tests/runtime/smoke/wasm.go b/tests/runtime/smoke/wasm.go index e8c2b6674..ff3c0c316 100644 --- a/tests/runtime/smoke/wasm.go +++ b/tests/runtime/smoke/wasm.go @@ -12,7 +12,7 @@ func init() { type SmokeImpl struct{} func (s SmokeImpl) Thunk() { - ImportsThunk() + TestSmokeImportsThunk() } func main() {} diff --git a/tests/runtime/unions/wasm.go b/tests/runtime/unions/wasm.go index d67c57375..4af15222c 100644 --- a/tests/runtime/unions/wasm.go +++ b/tests/runtime/unions/wasm.go @@ -8,346 +8,346 @@ import ( func init() { n := UnionsImpl{} SetUnions(n) - SetExports(n) + SetExportsTestUnionsTest(n) } type UnionsImpl struct{} func (s UnionsImpl) TestImports() { - res1 := ImportsAddOneInteger(ImportsAllIntegersF0(false)) + res1 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF0(false)) if res1.GetF0() != true { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res2 := ImportsAddOneInteger(ImportsAllIntegersF0(true)) + res2 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF0(true)) if res2.GetF0() != false { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res3 := ImportsAddOneInteger(ImportsAllIntegersF1(0)) + res3 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF1(0)) if res3.GetF1() != 1 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res4 := ImportsAddOneInteger(ImportsAllIntegersF1(math.MaxUint8)) + res4 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF1(math.MaxUint8)) if res4.GetF1() != 0 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res5 := ImportsAddOneInteger(ImportsAllIntegersF2(0)) + res5 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF2(0)) if res5.GetF2() != 1 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res6 := ImportsAddOneInteger(ImportsAllIntegersF2(math.MaxUint16)) + res6 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF2(math.MaxUint16)) if res6.GetF2() != 0 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res7 := ImportsAddOneInteger(ImportsAllIntegersF3(0)) + res7 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF3(0)) if res7.GetF3() != 1 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res8 := ImportsAddOneInteger(ImportsAllIntegersF3(math.MaxUint32)) + res8 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF3(math.MaxUint32)) if res8.GetF3() != 0 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res9 := ImportsAddOneInteger(ImportsAllIntegersF4(0)) + res9 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF4(0)) if res9.GetF4() != 1 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res10 := ImportsAddOneInteger(ImportsAllIntegersF4(math.MaxUint64)) + res10 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF4(math.MaxUint64)) if res10.GetF4() != 0 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res11 := ImportsAddOneInteger(ImportsAllIntegersF5(0)) + res11 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF5(0)) if res11.GetF5() != 1 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res12 := ImportsAddOneInteger(ImportsAllIntegersF5(math.MaxInt8)) + res12 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF5(math.MaxInt8)) if res12.GetF5() != math.MinInt8 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res13 := ImportsAddOneInteger(ImportsAllIntegersF6(0)) + res13 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF6(0)) if res13.GetF6() != 1 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res14 := ImportsAddOneInteger(ImportsAllIntegersF6(math.MaxInt16)) + res14 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF6(math.MaxInt16)) if res14.GetF6() != math.MinInt16 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res15 := ImportsAddOneInteger(ImportsAllIntegersF7(0)) + res15 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF7(0)) if res15.GetF7() != 1 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res16 := ImportsAddOneInteger(ImportsAllIntegersF7(math.MaxInt32)) + res16 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF7(math.MaxInt32)) if res16.GetF7() != math.MinInt32 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res17 := ImportsAddOneInteger(ImportsAllIntegersF8(0)) + res17 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF8(0)) if res17.GetF8() != 1 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } - res18 := ImportsAddOneInteger(ImportsAllIntegersF8(math.MaxInt64)) + res18 := TestUnionsTestAddOneInteger(TestUnionsTestAllIntegersF8(math.MaxInt64)) if res18.GetF8() != math.MinInt64 { - panic("unexpect result in ImportsAddOneInteger") + panic("unexpect result in TestUnionsTestAddOneInteger") } // All Floats - res19 := ImportsAddOneFloat(ImportsAllFloatsF0(0.0)) + res19 := TestUnionsTestAddOneFloat(TestUnionsTestAllFloatsF0(0.0)) if res19.GetF0() != 1.0 { - panic("unexpect result in ImportsAddOneFloat") + panic("unexpect result in TestUnionsTestAddOneFloat") } - res20 := ImportsAddOneFloat(ImportsAllFloatsF1(0.0)) + res20 := TestUnionsTestAddOneFloat(TestUnionsTestAllFloatsF1(0.0)) if res20.GetF1() != 1.0 { - panic("unexpect result in ImportsAddOneFloat") + panic("unexpect result in TestUnionsTestAddOneFloat") } // All Text - if ImportsReplaceFirstChar(ImportsAllTextF0('a'), 'z').GetF0() != 'z' { - panic("unexpect result in ImportsReplaceFirstChar") + if TestUnionsTestReplaceFirstChar(TestUnionsTestAllTextF0('a'), 'z').GetF0() != 'z' { + panic("unexpect result in TestUnionsTestReplaceFirstChar") } - if ImportsReplaceFirstChar(ImportsAllTextF1("abc"), 'z').GetF1() != "zbc" { - panic("unexpect result in ImportsReplaceFirstChar") + if TestUnionsTestReplaceFirstChar(TestUnionsTestAllTextF1("abc"), 'z').GetF1() != "zbc" { + panic("unexpect result in TestUnionsTestReplaceFirstChar") } // All Integers - if ImportsIdentifyInteger(ImportsAllIntegersF0(true)) != 0 { - panic("unexpect result in ImportsIdentifyInteger") + if TestUnionsTestIdentifyInteger(TestUnionsTestAllIntegersF0(true)) != 0 { + panic("unexpect result in TestUnionsTestIdentifyInteger") } - if ImportsIdentifyInteger(ImportsAllIntegersF1(0)) != 1 { - panic("unexpect result in ImportsIdentifyInteger") + if TestUnionsTestIdentifyInteger(TestUnionsTestAllIntegersF1(0)) != 1 { + panic("unexpect result in TestUnionsTestIdentifyInteger") } - if ImportsIdentifyInteger(ImportsAllIntegersF2(0)) != 2 { - panic("unexpect result in ImportsIdentifyInteger") + if TestUnionsTestIdentifyInteger(TestUnionsTestAllIntegersF2(0)) != 2 { + panic("unexpect result in TestUnionsTestIdentifyInteger") } - if ImportsIdentifyInteger(ImportsAllIntegersF3(0)) != 3 { - panic("unexpect result in ImportsIdentifyInteger") + if TestUnionsTestIdentifyInteger(TestUnionsTestAllIntegersF3(0)) != 3 { + panic("unexpect result in TestUnionsTestIdentifyInteger") } - if ImportsIdentifyInteger(ImportsAllIntegersF4(0)) != 4 { - panic("unexpect result in ImportsIdentifyInteger") + if TestUnionsTestIdentifyInteger(TestUnionsTestAllIntegersF4(0)) != 4 { + panic("unexpect result in TestUnionsTestIdentifyInteger") } - if ImportsIdentifyInteger(ImportsAllIntegersF5(0)) != 5 { - panic("unexpect result in ImportsIdentifyInteger") + if TestUnionsTestIdentifyInteger(TestUnionsTestAllIntegersF5(0)) != 5 { + panic("unexpect result in TestUnionsTestIdentifyInteger") } - if ImportsIdentifyInteger(ImportsAllIntegersF6(0)) != 6 { - panic("unexpect result in ImportsIdentifyInteger") + if TestUnionsTestIdentifyInteger(TestUnionsTestAllIntegersF6(0)) != 6 { + panic("unexpect result in TestUnionsTestIdentifyInteger") } - if ImportsIdentifyInteger(ImportsAllIntegersF7(0)) != 7 { - panic("unexpect result in ImportsIdentifyInteger") + if TestUnionsTestIdentifyInteger(TestUnionsTestAllIntegersF7(0)) != 7 { + panic("unexpect result in TestUnionsTestIdentifyInteger") } - if ImportsIdentifyInteger(ImportsAllIntegersF8(0)) != 8 { - panic("unexpect result in ImportsIdentifyInteger") + if TestUnionsTestIdentifyInteger(TestUnionsTestAllIntegersF8(0)) != 8 { + panic("unexpect result in TestUnionsTestIdentifyInteger") } - if ImportsIdentifyFloat(ImportsAllFloatsF0(0.0)) != 0 { - panic("unexpect result in ImportsIdentifyFloat") + if TestUnionsTestIdentifyFloat(TestUnionsTestAllFloatsF0(0.0)) != 0 { + panic("unexpect result in TestUnionsTestIdentifyFloat") } - if ImportsIdentifyFloat(ImportsAllFloatsF1(0.0)) != 1 { - panic("unexpect result in ImportsIdentifyFloat") + if TestUnionsTestIdentifyFloat(TestUnionsTestAllFloatsF1(0.0)) != 1 { + panic("unexpect result in TestUnionsTestIdentifyFloat") } // All Text - if ImportsIdentifyText(ImportsAllTextF0('a')) != 0 { - panic("unexpected result in ImportsIdentifyText") + if TestUnionsTestIdentifyText(TestUnionsTestAllTextF0('a')) != 0 { + panic("unexpected result in TestUnionsTestIdentifyText") } - if ImportsIdentifyText(ImportsAllTextF1("abc")) != 1 { - panic("unexpected result in ImportsIdentifyText") + if TestUnionsTestIdentifyText(TestUnionsTestAllTextF1("abc")) != 1 { + panic("unexpected result in TestUnionsTestIdentifyText") } // All Duplicated - res21 := ImportsAddOneDuplicated(ImportsDuplicatedS32F0(0)) + res21 := TestUnionsTestAddOneDuplicated(TestUnionsTestDuplicatedS32F0(0)) if res21.GetF0() != 1 { - panic("unexpected result in ImportsAddOneDuplicated") + panic("unexpected result in TestUnionsTestAddOneDuplicated") } - res22 := ImportsAddOneDuplicated(ImportsDuplicatedS32F1(1)) + res22 := TestUnionsTestAddOneDuplicated(TestUnionsTestDuplicatedS32F1(1)) if res22.GetF1() != 2 { - panic("unexpected result in ImportsAddOneDuplicated") + panic("unexpected result in TestUnionsTestAddOneDuplicated") } - res23 := ImportsAddOneDuplicated(ImportsDuplicatedS32F2(2)) + res23 := TestUnionsTestAddOneDuplicated(TestUnionsTestDuplicatedS32F2(2)) if res23.GetF2() != 3 { - panic("unexpected result in ImportsAddOneDuplicated") + panic("unexpected result in TestUnionsTestAddOneDuplicated") } // Distinguishable - if ImportsAddOneDistinguishableNum(ImportsDistinguishableNumF1(0)).GetF1() != 1 { - panic("unexpect result in ImportsAddOneDistinguishableNum") + if TestUnionsTestAddOneDistinguishableNum(TestUnionsTestDistinguishableNumF1(0)).GetF1() != 1 { + panic("unexpect result in TestUnionsTestAddOneDistinguishableNum") } - if ImportsIdentifyDistinguishableNum(ImportsDistinguishableNumF0(0.0)) != 0 { - panic("unexpect result in ImportsIdentifyDistinguishableNum") + if TestUnionsTestIdentifyDistinguishableNum(TestUnionsTestDistinguishableNumF0(0.0)) != 0 { + panic("unexpect result in TestUnionsTestIdentifyDistinguishableNum") } - if ImportsIdentifyDistinguishableNum(ImportsDistinguishableNumF1(1)) != 1 { - panic("unexpect result in ImportsIdentifyDistinguishableNum") + if TestUnionsTestIdentifyDistinguishableNum(TestUnionsTestDistinguishableNumF1(1)) != 1 { + panic("unexpect result in TestUnionsTestIdentifyDistinguishableNum") } } -func (u UnionsImpl) AddOneInteger(num ExportsAllIntegers) ExportsAllIntegers { +func (u UnionsImpl) AddOneInteger(num ExportsTestUnionsTestAllIntegers) ExportsTestUnionsTestAllIntegers { switch num.Kind() { - case ExportsAllIntegersKindF0: - return ExportsAllIntegersF0(!num.GetF0()) - case ExportsAllIntegersKindF1: - return ExportsAllIntegersF1(num.GetF1() + 1) - case ExportsAllIntegersKindF2: - return ExportsAllIntegersF2(num.GetF2() + 1) - case ExportsAllIntegersKindF3: - return ExportsAllIntegersF3(num.GetF3() + 1) - case ExportsAllIntegersKindF4: - return ExportsAllIntegersF4(num.GetF4() + 1) - case ExportsAllIntegersKindF5: - return ExportsAllIntegersF5(num.GetF5() + 1) - case ExportsAllIntegersKindF6: - return ExportsAllIntegersF6(num.GetF6() + 1) - case ExportsAllIntegersKindF7: - return ExportsAllIntegersF7(num.GetF7() + 1) - case ExportsAllIntegersKindF8: - return ExportsAllIntegersF8(num.GetF8() + 1) + case ExportsTestUnionsTestAllIntegersKindF0: + return ExportsTestUnionsTestAllIntegersF0(!num.GetF0()) + case ExportsTestUnionsTestAllIntegersKindF1: + return ExportsTestUnionsTestAllIntegersF1(num.GetF1() + 1) + case ExportsTestUnionsTestAllIntegersKindF2: + return ExportsTestUnionsTestAllIntegersF2(num.GetF2() + 1) + case ExportsTestUnionsTestAllIntegersKindF3: + return ExportsTestUnionsTestAllIntegersF3(num.GetF3() + 1) + case ExportsTestUnionsTestAllIntegersKindF4: + return ExportsTestUnionsTestAllIntegersF4(num.GetF4() + 1) + case ExportsTestUnionsTestAllIntegersKindF5: + return ExportsTestUnionsTestAllIntegersF5(num.GetF5() + 1) + case ExportsTestUnionsTestAllIntegersKindF6: + return ExportsTestUnionsTestAllIntegersF6(num.GetF6() + 1) + case ExportsTestUnionsTestAllIntegersKindF7: + return ExportsTestUnionsTestAllIntegersF7(num.GetF7() + 1) + case ExportsTestUnionsTestAllIntegersKindF8: + return ExportsTestUnionsTestAllIntegersF8(num.GetF8() + 1) default: - panic("unexpected type in ExportsAllIntegers") + panic("unexpected type in ExportsTestUnionsTestAllIntegers") } } -func (u UnionsImpl) AddOneFloat(num ExportsAllFloats) ExportsAllFloats { +func (u UnionsImpl) AddOneFloat(num ExportsTestUnionsTestAllFloats) ExportsTestUnionsTestAllFloats { switch num.Kind() { - case ExportsAllFloatsKindF0: - return ExportsAllFloatsF0(num.GetF0() + 1.0) - case ExportsAllFloatsKindF1: - return ExportsAllFloatsF1(num.GetF1() + 1.0) + case ExportsTestUnionsTestAllFloatsKindF0: + return ExportsTestUnionsTestAllFloatsF0(num.GetF0() + 1.0) + case ExportsTestUnionsTestAllFloatsKindF1: + return ExportsTestUnionsTestAllFloatsF1(num.GetF1() + 1.0) default: - panic("unexpected type in ExportsAllFloats") + panic("unexpected type in ExportsTestUnionsTestAllFloats") } } -func (u UnionsImpl) ReplaceFirstChar(text ExportsAllText, letter rune) ExportsAllText { +func (u UnionsImpl) ReplaceFirstChar(text ExportsTestUnionsTestAllText, letter rune) ExportsTestUnionsTestAllText { switch text.Kind() { - case ExportsAllTextKindF0: - return ExportsAllTextF0(letter) - case ExportsAllTextKindF1: - return ExportsAllTextF1(string(letter) + text.GetF1()[1:]) + case ExportsTestUnionsTestAllTextKindF0: + return ExportsTestUnionsTestAllTextF0(letter) + case ExportsTestUnionsTestAllTextKindF1: + return ExportsTestUnionsTestAllTextF1(string(letter) + text.GetF1()[1:]) default: // handle error or panic - return ExportsAllText{} + return ExportsTestUnionsTestAllText{} } } -func (u UnionsImpl) IdentifyInteger(num ExportsAllIntegers) uint8 { +func (u UnionsImpl) IdentifyInteger(num ExportsTestUnionsTestAllIntegers) uint8 { switch num.Kind() { - case ExportsAllIntegersKindF0: + case ExportsTestUnionsTestAllIntegersKindF0: return 0 - case ExportsAllIntegersKindF1: + case ExportsTestUnionsTestAllIntegersKindF1: return 1 - case ExportsAllIntegersKindF2: + case ExportsTestUnionsTestAllIntegersKindF2: return 2 - case ExportsAllIntegersKindF3: + case ExportsTestUnionsTestAllIntegersKindF3: return 3 - case ExportsAllIntegersKindF4: + case ExportsTestUnionsTestAllIntegersKindF4: return 4 - case ExportsAllIntegersKindF5: + case ExportsTestUnionsTestAllIntegersKindF5: return 5 - case ExportsAllIntegersKindF6: + case ExportsTestUnionsTestAllIntegersKindF6: return 6 - case ExportsAllIntegersKindF7: + case ExportsTestUnionsTestAllIntegersKindF7: return 7 - case ExportsAllIntegersKindF8: + case ExportsTestUnionsTestAllIntegersKindF8: return 8 default: - panic("unexpected type in ExportsAllIntegers") + panic("unexpected type in ExportsTestUnionsTestAllIntegers") } } -func (u UnionsImpl) IdentifyFloat(num ExportsAllFloats) uint8 { +func (u UnionsImpl) IdentifyFloat(num ExportsTestUnionsTestAllFloats) uint8 { switch num.Kind() { - case ExportsAllFloatsKindF0: + case ExportsTestUnionsTestAllFloatsKindF0: return 0 - case ExportsAllFloatsKindF1: + case ExportsTestUnionsTestAllFloatsKindF1: return 1 default: - panic("unexpected type in ExportsAllFloats") + panic("unexpected type in ExportsTestUnionsTestAllFloats") } } -func (u UnionsImpl) IdentifyText(text ExportsAllText) uint8 { +func (u UnionsImpl) IdentifyText(text ExportsTestUnionsTestAllText) uint8 { switch text.Kind() { - case ExportsAllTextKindF0: + case ExportsTestUnionsTestAllTextKindF0: return 0 - case ExportsAllTextKindF1: + case ExportsTestUnionsTestAllTextKindF1: return 1 default: - panic("unexpected type in ExportsAllText") + panic("unexpected type in ExportsTestUnionsTestAllText") } } -func (u UnionsImpl) AddOneDuplicated(num ExportsDuplicatedS32) ExportsDuplicatedS32 { +func (u UnionsImpl) AddOneDuplicated(num ExportsTestUnionsTestDuplicatedS32) ExportsTestUnionsTestDuplicatedS32 { switch num.Kind() { - case ExportsDuplicatedS32KindF0: - return ExportsDuplicatedS32F0(num.GetF0() + 1) - case ExportsDuplicatedS32KindF1: - return ExportsDuplicatedS32F1(num.GetF1() + 1) - case ExportsDuplicatedS32KindF2: - return ExportsDuplicatedS32F2(num.GetF2() + 1) + case ExportsTestUnionsTestDuplicatedS32KindF0: + return ExportsTestUnionsTestDuplicatedS32F0(num.GetF0() + 1) + case ExportsTestUnionsTestDuplicatedS32KindF1: + return ExportsTestUnionsTestDuplicatedS32F1(num.GetF1() + 1) + case ExportsTestUnionsTestDuplicatedS32KindF2: + return ExportsTestUnionsTestDuplicatedS32F2(num.GetF2() + 1) default: - panic("unexpected type in ExportsDuplicatedS32") + panic("unexpected type in ExportsTestUnionsTestDuplicatedS32") } } -func (u UnionsImpl) IdentifyDuplicated(num ExportsDuplicatedS32) uint8 { +func (u UnionsImpl) IdentifyDuplicated(num ExportsTestUnionsTestDuplicatedS32) uint8 { switch num.Kind() { - case ExportsDuplicatedS32KindF0: + case ExportsTestUnionsTestDuplicatedS32KindF0: return 0 - case ExportsDuplicatedS32KindF1: + case ExportsTestUnionsTestDuplicatedS32KindF1: return 1 - case ExportsDuplicatedS32KindF2: + case ExportsTestUnionsTestDuplicatedS32KindF2: return 2 default: panic("unexpected type in IdentifyDuplicated") } } -func (u UnionsImpl) AddOneDistinguishableNum(num ExportsDistinguishableNum) ExportsDistinguishableNum { +func (u UnionsImpl) AddOneDistinguishableNum(num ExportsTestUnionsTestDistinguishableNum) ExportsTestUnionsTestDistinguishableNum { switch num.Kind() { - case ExportsDistinguishableNumKindF0: - return ExportsDistinguishableNumF0(num.GetF0() + 1.0) - case ExportsDistinguishableNumKindF1: - return ExportsDistinguishableNumF1(num.GetF1() + 1) + case ExportsTestUnionsTestDistinguishableNumKindF0: + return ExportsTestUnionsTestDistinguishableNumF0(num.GetF0() + 1.0) + case ExportsTestUnionsTestDistinguishableNumKindF1: + return ExportsTestUnionsTestDistinguishableNumF1(num.GetF1() + 1) default: - panic("unexpected type in ExportsDistinguishableNum") + panic("unexpected type in ExportsTestUnionsTestDistinguishableNum") } } -func (u UnionsImpl) IdentifyDistinguishableNum(num ExportsDistinguishableNum) uint8 { +func (u UnionsImpl) IdentifyDistinguishableNum(num ExportsTestUnionsTestDistinguishableNum) uint8 { switch num.Kind() { - case ExportsDistinguishableNumKindF0: + case ExportsTestUnionsTestDistinguishableNumKindF0: return 0 - case ExportsDistinguishableNumKindF1: + case ExportsTestUnionsTestDistinguishableNumKindF1: return 1 default: - panic("unexpected type in ExportsDistinguishableNum") + panic("unexpected type in ExportsTestUnionsTestDistinguishableNum") } } From 1d0e8001bb8ab980f9ba64dab7361b56de6fa987 Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Sat, 27 May 2023 23:50:38 -0700 Subject: [PATCH 3/4] enable all the runtime tests Signed-off-by: Jiaxiao Zhou (Mossaka) --- crates/go/src/lib.rs | 177 ++++++++++++++++++++++++------ crates/go/tests/codegen.rs | 6 - tests/codegen/zero-size-tuple.wit | 10 ++ tests/runtime/flavorful/wasm.go | 28 ++--- tests/runtime/records/wasm.go | 16 +-- tests/runtime/unions/wasm.go | 146 ++++++++++++------------ 6 files changed, 247 insertions(+), 136 deletions(-) create mode 100644 tests/codegen/zero-size-tuple.wit diff --git a/crates/go/src/lib.rs b/crates/go/src/lib.rs index 0d773c5ea..bfc625c8b 100644 --- a/crates/go/src/lib.rs +++ b/crates/go/src/lib.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use std::fmt::Write; use std::{collections::BTreeSet, mem}; @@ -74,6 +74,15 @@ pub struct TinyGo { needs_fmt_import: bool, sizes: SizeAlign, interface_names: HashMap, + types: HashMap, + + // Interfaces who have had their types printed. + // + // This is used to guard against printing the types for an interface twice. + // The same interface can be both imported and exported in which case only + // one set of types is generated and all bindings for both imports and + // exports use that set of types. + interfaces_with_types_printed: HashSet, } impl TinyGo { @@ -94,6 +103,14 @@ impl TinyGo { export_funcs: Vec::new(), } } + + fn finish_types(&mut self, resolve: &Resolve) { + for (id, _) in resolve.types.iter() { + if let Some(ty) = self.types.get(&id) { + self.src.push_str(&ty); + } + } + } } impl WorldGenerator for TinyGo { @@ -118,7 +135,9 @@ impl WorldGenerator for TinyGo { let binding = Some(name); let mut gen = self.interface(resolve, &binding, true); gen.interface = Some(id); - gen.types(id); + if gen.gen.interfaces_with_types_printed.insert(id) { + gen.types(id); + } for (_name, func) in resolve.interfaces[id].functions.iter() { gen.import(resolve, func); @@ -165,7 +184,9 @@ impl WorldGenerator for TinyGo { let binding = Some(name); let mut gen = self.interface(resolve, &binding, false); gen.interface = Some(id); - gen.types(id); + if gen.gen.interfaces_with_types_printed.insert(id) { + gen.types(id); + } for (_name, func) in resolve.interfaces[id].functions.iter() { gen.export(resolve, func); @@ -216,6 +237,11 @@ impl WorldGenerator for TinyGo { } fn finish(&mut self, resolve: &Resolve, id: WorldId, files: &mut Files) { + // make sure all types are defined on top of the file + let src = mem::take(&mut self.src); + self.finish_types(resolve); + self.src.push_str(&src); + let world = &resolve.worlds[id]; let mut header = Source::default(); let snake = self.world.to_snake_case(); @@ -364,6 +390,7 @@ impl WorldGenerator for TinyGo { result_option_src.as_bytes(), ); } + let mut opts = wit_bindgen_c::Opts::default(); opts.no_sig_flattening = true; opts.build().generate(resolve, id, files) @@ -382,10 +409,26 @@ struct InterfaceGenerator<'a> { } impl InterfaceGenerator<'_> { - fn get_func_or_type_name(&self, name: &str) -> String { + fn get_func_name(&self, name: &str) -> String { format!("{}{}", self.get_package_name(), name.to_upper_camel_case()) } + fn get_type_name(&self, ty_name: &str, convert: bool) -> String { + let mut name = String::new(); + let package_name = match self.name { + Some(key) => self.get_ty_name_with(key), + None => self.gen.world.to_upper_camel_case(), + }; + let ty_name = if convert { + ty_name.to_upper_camel_case() + } else { + ty_name.into() + }; + name.push_str(&package_name); + name.push_str(&ty_name); + name + } + fn get_c_func_name(&self, func_name: &str) -> String { let mut name = String::new(); match self.name { @@ -434,6 +477,21 @@ impl InterfaceGenerator<'_> { name } + fn get_ty_name_with(&self, key: &WorldKey) -> String { + let mut name = String::new(); + match key { + WorldKey::Name(k) => name.push_str(&k.to_upper_camel_case()), + WorldKey::Interface(id) => { + let iface = &self.resolve.interfaces[*id]; + let pkg = &self.resolve.packages[iface.package.unwrap()]; + name.push_str(&pkg.name.namespace.to_upper_camel_case()); + name.push_str(&pkg.name.name.to_upper_camel_case()); + name.push_str(&iface.name.as_ref().unwrap().to_upper_camel_case()); + } + } + name + } + fn get_interface_var_name(&self) -> String { let mut name = String::new(); match self.name { @@ -488,19 +546,19 @@ impl InterfaceGenerator<'_> { } _ => { if let Some(name) = &ty.name { - let iface = if let TypeOwner::Interface(owner) = ty.owner { + if let TypeOwner::Interface(owner) = ty.owner { let key = &self.gen.interface_names[&owner]; - self.get_package_name_with(key) + let iface = self.get_ty_name_with(key); + format!("{iface}{name}", name = name.to_upper_camel_case()) } else { - self.get_package_name() - }; - format!("{iface}{name}", name = name.to_upper_camel_case()) + self.get_type_name(name, true) + } } else { self.public_anonymous_types.insert(*id); format!( - "{namespace}{name}", - namespace = self.get_package_name(), - name = self.get_ty_name(&Type::Id(*id)), + "{namespace}", + namespace = + self.get_type_name(&self.get_ty_name(&Type::Id(*id)), false) ) } } @@ -611,7 +669,7 @@ impl InterfaceGenerator<'_> { } TypeOwner::Interface(owner) => { let key = &self.gen.interface_names[&owner]; - self.get_package_name_with(key) + self.get_ty_name_with(key) } TypeOwner::None => "".into(), }; @@ -922,7 +980,7 @@ impl InterfaceGenerator<'_> { let func_name = if in_import { self.get_c_func_name(&func.name) } else { - self.get_func_or_type_name(&func.name) + self.get_func_name(&func.name) }; if !in_import { @@ -997,6 +1055,16 @@ impl InterfaceGenerator<'_> { } } + fn is_empty_tuple_ty(&self, ty: &Type) -> bool { + match ty { + Type::Id(id) => match &self.resolve.types[*id].kind { + TypeDefKind::Tuple(t) => t.types.is_empty(), + _ => false, + }, + _ => false, + } + } + fn get_optional_ty(&mut self, ty: Option<&Type>) -> String { match ty { Some(ty) => self.get_ty(ty), @@ -1016,17 +1084,18 @@ impl InterfaceGenerator<'_> { unreachable!() } TypeDefKind::Tuple(t) => { - let name = format!( - "{}{}", - self.get_package_name(), - self.get_ty_name(&Type::Id(ty)) - ); + let prev = mem::replace(&mut self.src, Source::default()); + + let ty_name = &self.get_ty_name(&Type::Id(ty)); + let name = self.get_type_name(&ty_name, false); self.src.push_str(&format!("type {name} struct {{\n",)); for (i, ty) in t.types.iter().enumerate() { let ty = self.get_ty(ty); self.src.push_str(&format!(" F{i} {ty}\n",)); } self.src.push_str("}\n\n"); + + self.finish_ty(ty, prev) } TypeDefKind::Option(_t) => {} TypeDefKind::Result(_r) => {} @@ -1096,6 +1165,16 @@ impl InterfaceGenerator<'_> { } } + fn finish_ty(&mut self, id: TypeId, source: wit_bindgen_core::Source) { + // insert or replace the type + let _prev = self + .gen + .types + .insert(id, mem::replace(&mut self.src, source)); + + // TODO: what if prev is not None? + } + fn import(&mut self, resolve: &Resolve, func: &Function) { let mut func_bindgen = FunctionBindgen::new(self, func); // lower params to c @@ -1295,9 +1374,11 @@ impl InterfaceGenerator<'_> { } fn finish(&mut self) { + let src = mem::take(&mut self.src); while let Some(ty) = self.public_anonymous_types.pop_last() { self.print_anonymous_type(ty); } + self.src.push_str(&src); if !self.in_import && !self.export_funcs.is_empty() { let interface_var_name = &self.get_interface_var_name(); @@ -1333,12 +1414,13 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { fn type_record( &mut self, - _id: wit_bindgen_core::wit_parser::TypeId, + id: wit_bindgen_core::wit_parser::TypeId, name: &str, record: &wit_bindgen_core::wit_parser::Record, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_func_or_type_name(name); + let prev = mem::take(&mut self.src); + let name = self.get_type_name(name, true); self.src.push_str(&format!("type {name} struct {{\n",)); for field in record.fields.iter() { let ty = self.get_ty(&field.ty); @@ -1346,16 +1428,18 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { self.src.push_str(&format!(" {name} {ty}\n",)); } self.src.push_str("}\n\n"); + self.finish_ty(id, prev) } fn type_flags( &mut self, - _id: wit_bindgen_core::wit_parser::TypeId, + id: wit_bindgen_core::wit_parser::TypeId, name: &str, flags: &wit_bindgen_core::wit_parser::Flags, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_func_or_type_name(name); + let prev = mem::take(&mut self.src); + let name = self.get_type_name(name, true); // TODO: use flags repr to determine how many flags are needed self.src.push_str(&format!("type {name} uint64\n")); self.src.push_str("const (\n"); @@ -1375,32 +1459,36 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { } } self.src.push_str(")\n\n"); + self.finish_ty(id, prev) } fn type_tuple( &mut self, - _id: wit_bindgen_core::wit_parser::TypeId, + id: wit_bindgen_core::wit_parser::TypeId, name: &str, tuple: &wit_bindgen_core::wit_parser::Tuple, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_func_or_type_name(name); + let prev = mem::take(&mut self.src); + let name = self.get_type_name(name, true); self.src.push_str(&format!("type {name} struct {{\n",)); for (i, case) in tuple.types.iter().enumerate() { let ty = self.get_ty(case); self.src.push_str(&format!("F{i} {ty}\n",)); } self.src.push_str("}\n\n"); + self.finish_ty(id, prev) } fn type_variant( &mut self, - _id: wit_bindgen_core::wit_parser::TypeId, + id: wit_bindgen_core::wit_parser::TypeId, name: &str, variant: &wit_bindgen_core::wit_parser::Variant, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_func_or_type_name(name); + let prev = mem::take(&mut self.src); + let name = self.get_type_name(name, true); // TODO: use variant's tag to determine how many cases are needed // this will help to optmize the Kind type. self.src.push_str(&format!("type {name}Kind int\n\n")); @@ -1428,6 +1516,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { self.print_constructor_method_without_value(&name, &case_name); } } + self.finish_ty(id, prev) } fn type_option( @@ -1437,7 +1526,9 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { _payload: &wit_bindgen_core::wit_parser::Type, _docs: &wit_bindgen_core::wit_parser::Docs, ) { + let prev = mem::take(&mut self.src); self.get_ty(&Type::Id(id)); + self.finish_ty(id, prev) } fn type_result( @@ -1447,17 +1538,20 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { _result: &wit_bindgen_core::wit_parser::Result_, _docs: &wit_bindgen_core::wit_parser::Docs, ) { + let prev = mem::take(&mut self.src); self.get_ty(&Type::Id(id)); + self.finish_ty(id, prev) } fn type_union( &mut self, - _id: wit_bindgen_core::wit_parser::TypeId, + id: wit_bindgen_core::wit_parser::TypeId, name: &str, union: &wit_bindgen_core::wit_parser::Union, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_func_or_type_name(name); + let prev = mem::take(&mut self.src); + let name = self.get_type_name(name, true); // TODO: use variant's tag to determine how many cases are needed // this will help to optmize the Kind type. self.src.push_str(&format!("type {name}Kind int\n\n")); @@ -1482,16 +1576,18 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { let case_name = format!("F{i}"); self.print_accessor_methods(&name, &case_name, &case.ty); } + self.finish_ty(id, prev) } fn type_enum( &mut self, - _id: wit_bindgen_core::wit_parser::TypeId, + id: wit_bindgen_core::wit_parser::TypeId, name: &str, enum_: &wit_bindgen_core::wit_parser::Enum, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_func_or_type_name(name); + let prev = mem::take(&mut self.src); + let name = self.get_type_name(name, true); // TODO: use variant's tag to determine how many cases are needed // this will help to optmize the Kind type. self.src.push_str(&format!("type {name}Kind int\n\n")); @@ -1513,30 +1609,35 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> { let case_name = case.name.to_upper_camel_case(); self.print_constructor_method_without_value(&name, &case_name); } + self.finish_ty(id, prev) } fn type_alias( &mut self, - _id: wit_bindgen_core::wit_parser::TypeId, + id: wit_bindgen_core::wit_parser::TypeId, name: &str, ty: &wit_bindgen_core::wit_parser::Type, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_func_or_type_name(name); + let prev = mem::take(&mut self.src); + let name = self.get_type_name(name, true); let ty = self.get_ty(ty); self.src.push_str(&format!("type {name} = {ty}\n")); + self.finish_ty(id, prev) } fn type_list( &mut self, - _id: wit_bindgen_core::wit_parser::TypeId, + id: wit_bindgen_core::wit_parser::TypeId, name: &str, ty: &wit_bindgen_core::wit_parser::Type, _docs: &wit_bindgen_core::wit_parser::Docs, ) { - let name = self.get_func_or_type_name(name); + let prev = mem::take(&mut self.src); + let name = self.get_type_name(name, true); let ty = self.get_ty(ty); self.src.push_str(&format!("type {name} = {ty}\n")); + self.finish_ty(id, prev) } fn type_builtin( @@ -2009,6 +2110,12 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> { uintptr({lift_name}_i)*unsafe.Sizeof(empty_{lift_name})))" ); + // If l is an empty tuple, set _ = {lift_name}_ptr + // this is a special case needs to be handled + if self.interface.is_empty_tuple_ty(l) { + uwriteln!(self.lift_src, "_ = {lift_name}_ptr"); + } + self.lift_value( &format!("{lift_name}_ptr"), l, diff --git a/crates/go/tests/codegen.rs b/crates/go/tests/codegen.rs index e40753721..6a7759ede 100644 --- a/crates/go/tests/codegen.rs +++ b/crates/go/tests/codegen.rs @@ -5,12 +5,6 @@ use std::path::Path; use std::process::Command; macro_rules! codegen_test { - // TODO: should fix this test - (lift_lower_foreign $name:tt $test:tt) => {}; - (unused_import $name:tt $test:tt) => {}; - (issue544 $name:tt $test:tt) => {}; - (issue551 $name:tt $test:tt) => {}; - ($id:ident $name:tt $test:tt) => { #[test] fn $id() { diff --git a/tests/codegen/zero-size-tuple.wit b/tests/codegen/zero-size-tuple.wit new file mode 100644 index 000000000..e48e344cf --- /dev/null +++ b/tests/codegen/zero-size-tuple.wit @@ -0,0 +1,10 @@ +package foo:foo + +world bindings { + import component +} + +interface component { + type value = tuple<> + query-eval: func(q: u64) -> list +} diff --git a/tests/runtime/flavorful/wasm.go b/tests/runtime/flavorful/wasm.go index 78f289809..4796ea964 100644 --- a/tests/runtime/flavorful/wasm.go +++ b/tests/runtime/flavorful/wasm.go @@ -86,31 +86,31 @@ func (f FlavorfulImpl) TestImports() { } -func (f FlavorfulImpl) FListInRecord1(a ExportsTestFlavorfulTestListInRecord1) { +func (f FlavorfulImpl) FListInRecord1(a TestFlavorfulTestListInRecord1) { if a.A != "list_in_record1" { panic("FListInRecord1") } } -func (f FlavorfulImpl) FListInRecord2() ExportsTestFlavorfulTestListInRecord2 { - return ExportsTestFlavorfulTestListInRecord2{"list_in_record2"} +func (f FlavorfulImpl) FListInRecord2() TestFlavorfulTestListInRecord2 { + return TestFlavorfulTestListInRecord2{"list_in_record2"} } -func (f FlavorfulImpl) FListInRecord3(a ExportsTestFlavorfulTestListInRecord3) ExportsTestFlavorfulTestListInRecord3 { +func (f FlavorfulImpl) FListInRecord3(a TestFlavorfulTestListInRecord3) TestFlavorfulTestListInRecord3 { if a.A != "list_in_record3 input" { panic("FListInRecord3") } - return ExportsTestFlavorfulTestListInRecord3{"list_in_record3 output"} + return TestFlavorfulTestListInRecord3{"list_in_record3 output"} } -func (f FlavorfulImpl) FListInRecord4(a ExportsTestFlavorfulTestListInRecord4) ExportsTestFlavorfulTestListInRecord4 { +func (f FlavorfulImpl) FListInRecord4(a TestFlavorfulTestListInRecord4) TestFlavorfulTestListInRecord4 { if a.A != "input4" { panic("FListInRecord4") } - return ExportsTestFlavorfulTestListInRecord4{"result4"} + return TestFlavorfulTestListInRecord4{"result4"} } -func (f FlavorfulImpl) FListInVariant1(a Option[string], b Result[struct{}, string], c ExportsTestFlavorfulTestListInVariant1V3) { +func (f FlavorfulImpl) FListInVariant1(a Option[string], b Result[struct{}, string], c TestFlavorfulTestListInVariant1V3) { if a.Unwrap() != "foo" { panic("FListInVariant1") } @@ -118,11 +118,11 @@ func (f FlavorfulImpl) FListInVariant1(a Option[string], b Result[struct{}, stri panic("FListInVariant1") } switch c.Kind() { - case ExportsTestFlavorfulTestListInVariant1V3KindF0: + case TestFlavorfulTestListInVariant1V3KindF0: if c.GetF0() != "baz" { panic("FListInVariant1") } - case ExportsTestFlavorfulTestListInVariant1V3KindF1: + case TestFlavorfulTestListInVariant1V3KindF1: panic("FListInVariant1") } } @@ -138,9 +138,9 @@ func (f FlavorfulImpl) FListInVariant3(a Option[string]) Option[string] { return Some[string]("output3") } -func (f FlavorfulImpl) ErrnoResult() Result[struct{}, ExportsTestFlavorfulTestMyErrno] { - var res Result[struct{}, ExportsTestFlavorfulTestMyErrno] - res.SetErr(ExportsTestFlavorfulTestMyErrnoB()) +func (f FlavorfulImpl) ErrnoResult() Result[struct{}, TestFlavorfulTestMyErrno] { + var res Result[struct{}, TestFlavorfulTestMyErrno] + res.SetErr(TestFlavorfulTestMyErrnoB()) return res } @@ -157,7 +157,7 @@ func (f FlavorfulImpl) ListTypedefs(a string, c []string) ([]uint8, []string) { return []uint8("typedef3"), []string{"typedef4"} } -func (f FlavorfulImpl) ListOfVariants(a []bool, b []Result[struct{}, struct{}], c []ExportsTestFlavorfulTestMyErrno) ([]bool, []Result[struct{}, struct{}], []ExportsTestFlavorfulTestMyErrno) { +func (f FlavorfulImpl) ListOfVariants(a []bool, b []Result[struct{}, struct{}], c []TestFlavorfulTestMyErrno) ([]bool, []Result[struct{}, struct{}], []TestFlavorfulTestMyErrno) { return a, b, c } diff --git a/tests/runtime/records/wasm.go b/tests/runtime/records/wasm.go index a6a5cd808..2cdd3aed2 100644 --- a/tests/runtime/records/wasm.go +++ b/tests/runtime/records/wasm.go @@ -67,31 +67,31 @@ func (r *RecordImpl) MultipleResults() (uint8, uint16) { return 100, 200 } -func (r *RecordImpl) SwapTuple(a ExportsTestRecordsTestTuple2U8U32T) ExportsTestRecordsTestTuple2U32U8T { - return ExportsTestRecordsTestTuple2U32U8T{a.F1, a.F0} +func (r *RecordImpl) SwapTuple(a TestRecordsTestTuple2U8U32T) TestRecordsTestTuple2U32U8T { + return TestRecordsTestTuple2U32U8T{a.F1, a.F0} } -func (r *RecordImpl) RoundtripFlags1(a ExportsTestRecordsTestF1) ExportsTestRecordsTestF1 { +func (r *RecordImpl) RoundtripFlags1(a TestRecordsTestF1) TestRecordsTestF1 { return a } -func (r *RecordImpl) RoundtripFlags2(a ExportsTestRecordsTestF2) ExportsTestRecordsTestF2 { +func (r *RecordImpl) RoundtripFlags2(a TestRecordsTestF2) TestRecordsTestF2 { return a } -func (r *RecordImpl) RoundtripFlags3(a ExportsTestRecordsTestFlag8, b ExportsTestRecordsTestFlag16, c ExportsTestRecordsTestFlag32, d ExportsTestRecordsTestFlag64) (ExportsTestRecordsTestFlag8, ExportsTestRecordsTestFlag16, ExportsTestRecordsTestFlag32, ExportsTestRecordsTestFlag64) { +func (r *RecordImpl) RoundtripFlags3(a TestRecordsTestFlag8, b TestRecordsTestFlag16, c TestRecordsTestFlag32, d TestRecordsTestFlag64) (TestRecordsTestFlag8, TestRecordsTestFlag16, TestRecordsTestFlag32, TestRecordsTestFlag64) { return a, b, c, d } -func (r *RecordImpl) RoundtripRecord1(a ExportsTestRecordsTestR1) ExportsTestRecordsTestR1 { +func (r *RecordImpl) RoundtripRecord1(a TestRecordsTestR1) TestRecordsTestR1 { return a } -func (r *RecordImpl) Tuple0(a ExportsTestRecordsTestTuple0T) ExportsTestRecordsTestTuple0T { +func (r *RecordImpl) Tuple0(a TestRecordsTestTuple0T) TestRecordsTestTuple0T { return a } -func (r *RecordImpl) Tuple1(a ExportsTestRecordsTestTuple1U8T) ExportsTestRecordsTestTuple1U8T { +func (r *RecordImpl) Tuple1(a TestRecordsTestTuple1U8T) TestRecordsTestTuple1U8T { return a } diff --git a/tests/runtime/unions/wasm.go b/tests/runtime/unions/wasm.go index 4af15222c..b1b68ac71 100644 --- a/tests/runtime/unions/wasm.go +++ b/tests/runtime/unions/wasm.go @@ -208,146 +208,146 @@ func (s UnionsImpl) TestImports() { } -func (u UnionsImpl) AddOneInteger(num ExportsTestUnionsTestAllIntegers) ExportsTestUnionsTestAllIntegers { +func (u UnionsImpl) AddOneInteger(num TestUnionsTestAllIntegers) TestUnionsTestAllIntegers { switch num.Kind() { - case ExportsTestUnionsTestAllIntegersKindF0: - return ExportsTestUnionsTestAllIntegersF0(!num.GetF0()) - case ExportsTestUnionsTestAllIntegersKindF1: - return ExportsTestUnionsTestAllIntegersF1(num.GetF1() + 1) - case ExportsTestUnionsTestAllIntegersKindF2: - return ExportsTestUnionsTestAllIntegersF2(num.GetF2() + 1) - case ExportsTestUnionsTestAllIntegersKindF3: - return ExportsTestUnionsTestAllIntegersF3(num.GetF3() + 1) - case ExportsTestUnionsTestAllIntegersKindF4: - return ExportsTestUnionsTestAllIntegersF4(num.GetF4() + 1) - case ExportsTestUnionsTestAllIntegersKindF5: - return ExportsTestUnionsTestAllIntegersF5(num.GetF5() + 1) - case ExportsTestUnionsTestAllIntegersKindF6: - return ExportsTestUnionsTestAllIntegersF6(num.GetF6() + 1) - case ExportsTestUnionsTestAllIntegersKindF7: - return ExportsTestUnionsTestAllIntegersF7(num.GetF7() + 1) - case ExportsTestUnionsTestAllIntegersKindF8: - return ExportsTestUnionsTestAllIntegersF8(num.GetF8() + 1) + case TestUnionsTestAllIntegersKindF0: + return TestUnionsTestAllIntegersF0(!num.GetF0()) + case TestUnionsTestAllIntegersKindF1: + return TestUnionsTestAllIntegersF1(num.GetF1() + 1) + case TestUnionsTestAllIntegersKindF2: + return TestUnionsTestAllIntegersF2(num.GetF2() + 1) + case TestUnionsTestAllIntegersKindF3: + return TestUnionsTestAllIntegersF3(num.GetF3() + 1) + case TestUnionsTestAllIntegersKindF4: + return TestUnionsTestAllIntegersF4(num.GetF4() + 1) + case TestUnionsTestAllIntegersKindF5: + return TestUnionsTestAllIntegersF5(num.GetF5() + 1) + case TestUnionsTestAllIntegersKindF6: + return TestUnionsTestAllIntegersF6(num.GetF6() + 1) + case TestUnionsTestAllIntegersKindF7: + return TestUnionsTestAllIntegersF7(num.GetF7() + 1) + case TestUnionsTestAllIntegersKindF8: + return TestUnionsTestAllIntegersF8(num.GetF8() + 1) default: - panic("unexpected type in ExportsTestUnionsTestAllIntegers") + panic("unexpected type in TestUnionsTestAllIntegers") } } -func (u UnionsImpl) AddOneFloat(num ExportsTestUnionsTestAllFloats) ExportsTestUnionsTestAllFloats { +func (u UnionsImpl) AddOneFloat(num TestUnionsTestAllFloats) TestUnionsTestAllFloats { switch num.Kind() { - case ExportsTestUnionsTestAllFloatsKindF0: - return ExportsTestUnionsTestAllFloatsF0(num.GetF0() + 1.0) - case ExportsTestUnionsTestAllFloatsKindF1: - return ExportsTestUnionsTestAllFloatsF1(num.GetF1() + 1.0) + case TestUnionsTestAllFloatsKindF0: + return TestUnionsTestAllFloatsF0(num.GetF0() + 1.0) + case TestUnionsTestAllFloatsKindF1: + return TestUnionsTestAllFloatsF1(num.GetF1() + 1.0) default: - panic("unexpected type in ExportsTestUnionsTestAllFloats") + panic("unexpected type in TestUnionsTestAllFloats") } } -func (u UnionsImpl) ReplaceFirstChar(text ExportsTestUnionsTestAllText, letter rune) ExportsTestUnionsTestAllText { +func (u UnionsImpl) ReplaceFirstChar(text TestUnionsTestAllText, letter rune) TestUnionsTestAllText { switch text.Kind() { - case ExportsTestUnionsTestAllTextKindF0: - return ExportsTestUnionsTestAllTextF0(letter) - case ExportsTestUnionsTestAllTextKindF1: - return ExportsTestUnionsTestAllTextF1(string(letter) + text.GetF1()[1:]) + case TestUnionsTestAllTextKindF0: + return TestUnionsTestAllTextF0(letter) + case TestUnionsTestAllTextKindF1: + return TestUnionsTestAllTextF1(string(letter) + text.GetF1()[1:]) default: // handle error or panic - return ExportsTestUnionsTestAllText{} + return TestUnionsTestAllText{} } } -func (u UnionsImpl) IdentifyInteger(num ExportsTestUnionsTestAllIntegers) uint8 { +func (u UnionsImpl) IdentifyInteger(num TestUnionsTestAllIntegers) uint8 { switch num.Kind() { - case ExportsTestUnionsTestAllIntegersKindF0: + case TestUnionsTestAllIntegersKindF0: return 0 - case ExportsTestUnionsTestAllIntegersKindF1: + case TestUnionsTestAllIntegersKindF1: return 1 - case ExportsTestUnionsTestAllIntegersKindF2: + case TestUnionsTestAllIntegersKindF2: return 2 - case ExportsTestUnionsTestAllIntegersKindF3: + case TestUnionsTestAllIntegersKindF3: return 3 - case ExportsTestUnionsTestAllIntegersKindF4: + case TestUnionsTestAllIntegersKindF4: return 4 - case ExportsTestUnionsTestAllIntegersKindF5: + case TestUnionsTestAllIntegersKindF5: return 5 - case ExportsTestUnionsTestAllIntegersKindF6: + case TestUnionsTestAllIntegersKindF6: return 6 - case ExportsTestUnionsTestAllIntegersKindF7: + case TestUnionsTestAllIntegersKindF7: return 7 - case ExportsTestUnionsTestAllIntegersKindF8: + case TestUnionsTestAllIntegersKindF8: return 8 default: - panic("unexpected type in ExportsTestUnionsTestAllIntegers") + panic("unexpected type in TestUnionsTestAllIntegers") } } -func (u UnionsImpl) IdentifyFloat(num ExportsTestUnionsTestAllFloats) uint8 { +func (u UnionsImpl) IdentifyFloat(num TestUnionsTestAllFloats) uint8 { switch num.Kind() { - case ExportsTestUnionsTestAllFloatsKindF0: + case TestUnionsTestAllFloatsKindF0: return 0 - case ExportsTestUnionsTestAllFloatsKindF1: + case TestUnionsTestAllFloatsKindF1: return 1 default: - panic("unexpected type in ExportsTestUnionsTestAllFloats") + panic("unexpected type in TestUnionsTestAllFloats") } } -func (u UnionsImpl) IdentifyText(text ExportsTestUnionsTestAllText) uint8 { +func (u UnionsImpl) IdentifyText(text TestUnionsTestAllText) uint8 { switch text.Kind() { - case ExportsTestUnionsTestAllTextKindF0: + case TestUnionsTestAllTextKindF0: return 0 - case ExportsTestUnionsTestAllTextKindF1: + case TestUnionsTestAllTextKindF1: return 1 default: - panic("unexpected type in ExportsTestUnionsTestAllText") + panic("unexpected type in TestUnionsTestAllText") } } -func (u UnionsImpl) AddOneDuplicated(num ExportsTestUnionsTestDuplicatedS32) ExportsTestUnionsTestDuplicatedS32 { +func (u UnionsImpl) AddOneDuplicated(num TestUnionsTestDuplicatedS32) TestUnionsTestDuplicatedS32 { switch num.Kind() { - case ExportsTestUnionsTestDuplicatedS32KindF0: - return ExportsTestUnionsTestDuplicatedS32F0(num.GetF0() + 1) - case ExportsTestUnionsTestDuplicatedS32KindF1: - return ExportsTestUnionsTestDuplicatedS32F1(num.GetF1() + 1) - case ExportsTestUnionsTestDuplicatedS32KindF2: - return ExportsTestUnionsTestDuplicatedS32F2(num.GetF2() + 1) + case TestUnionsTestDuplicatedS32KindF0: + return TestUnionsTestDuplicatedS32F0(num.GetF0() + 1) + case TestUnionsTestDuplicatedS32KindF1: + return TestUnionsTestDuplicatedS32F1(num.GetF1() + 1) + case TestUnionsTestDuplicatedS32KindF2: + return TestUnionsTestDuplicatedS32F2(num.GetF2() + 1) default: - panic("unexpected type in ExportsTestUnionsTestDuplicatedS32") + panic("unexpected type in TestUnionsTestDuplicatedS32") } } -func (u UnionsImpl) IdentifyDuplicated(num ExportsTestUnionsTestDuplicatedS32) uint8 { +func (u UnionsImpl) IdentifyDuplicated(num TestUnionsTestDuplicatedS32) uint8 { switch num.Kind() { - case ExportsTestUnionsTestDuplicatedS32KindF0: + case TestUnionsTestDuplicatedS32KindF0: return 0 - case ExportsTestUnionsTestDuplicatedS32KindF1: + case TestUnionsTestDuplicatedS32KindF1: return 1 - case ExportsTestUnionsTestDuplicatedS32KindF2: + case TestUnionsTestDuplicatedS32KindF2: return 2 default: panic("unexpected type in IdentifyDuplicated") } } -func (u UnionsImpl) AddOneDistinguishableNum(num ExportsTestUnionsTestDistinguishableNum) ExportsTestUnionsTestDistinguishableNum { +func (u UnionsImpl) AddOneDistinguishableNum(num TestUnionsTestDistinguishableNum) TestUnionsTestDistinguishableNum { switch num.Kind() { - case ExportsTestUnionsTestDistinguishableNumKindF0: - return ExportsTestUnionsTestDistinguishableNumF0(num.GetF0() + 1.0) - case ExportsTestUnionsTestDistinguishableNumKindF1: - return ExportsTestUnionsTestDistinguishableNumF1(num.GetF1() + 1) + case TestUnionsTestDistinguishableNumKindF0: + return TestUnionsTestDistinguishableNumF0(num.GetF0() + 1.0) + case TestUnionsTestDistinguishableNumKindF1: + return TestUnionsTestDistinguishableNumF1(num.GetF1() + 1) default: - panic("unexpected type in ExportsTestUnionsTestDistinguishableNum") + panic("unexpected type in TestUnionsTestDistinguishableNum") } } -func (u UnionsImpl) IdentifyDistinguishableNum(num ExportsTestUnionsTestDistinguishableNum) uint8 { +func (u UnionsImpl) IdentifyDistinguishableNum(num TestUnionsTestDistinguishableNum) uint8 { switch num.Kind() { - case ExportsTestUnionsTestDistinguishableNumKindF0: + case TestUnionsTestDistinguishableNumKindF0: return 0 - case ExportsTestUnionsTestDistinguishableNumKindF1: + case TestUnionsTestDistinguishableNumKindF1: return 1 default: - panic("unexpected type in ExportsTestUnionsTestDistinguishableNum") + panic("unexpected type in TestUnionsTestDistinguishableNum") } } From 1015af4321a1a4eb8f9873e0a94e9b427d1aa9d9 Mon Sep 17 00:00:00 2001 From: "Jiaxiao Zhou (Mossaka)" Date: Sun, 28 May 2023 00:01:16 -0700 Subject: [PATCH 4/4] adds variants test Signed-off-by: Jiaxiao Zhou (Mossaka) --- tests/runtime/variants/wasm.go | 238 +++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 tests/runtime/variants/wasm.go diff --git a/tests/runtime/variants/wasm.go b/tests/runtime/variants/wasm.go new file mode 100644 index 000000000..034d979d5 --- /dev/null +++ b/tests/runtime/variants/wasm.go @@ -0,0 +1,238 @@ +package main + +import ( + . "wit_variants_go/gen" +) + +func init() { + a := VariantsImpl{} + SetExportsTestVariantsTest(a) + SetVariants(a) +} + +type VariantsImpl struct { +} + +func (i VariantsImpl) TestImports() { + { + res := TestVariantsTestRoundtripOption(Some[float32](1)) + if res.IsNone() { + panic("TestVariantsTestRoundtripOption") + } + if res.Unwrap() != 1.0 { + panic("TestVariantsTestRoundtripOption") + } + + res2 := TestVariantsTestRoundtripOption(None[float32]()) + if res2.IsSome() { + panic("TestVariantsTestRoundtripOption") + } + } + { + var param Result[uint32, float32] + param.Set(5) + res := TestVariantsTestRoundtripResult(param) + if res.IsErr() { + panic("TestVariantsTestRoundtripResult") + } + if res.Unwrap() != 5 { + panic("TestVariantsTestRoundtripResult") + } + + param.SetErr(10.0) + res2 := TestVariantsTestRoundtripResult(param) + if res2.IsOk() { + panic("TestVariantsTestRoundtripResult") + } + if res2.UnwrapErr() != 10.0 { + panic("TestVariantsTestRoundtripResult") + } + } + + { + a := TestVariantsTestE1A() + res := TestVariantsTestRoundtripEnum(a) + if res.Kind() != TestVariantsTestE1KindA { + panic("TestVariantsTestRoundtripEnum") + } + + b := TestVariantsTestE1B() + res2 := TestVariantsTestRoundtripEnum(b) + if res2.Kind() != TestVariantsTestE1KindB { + panic("TestVariantsTestRoundtripEnum") + } + } + { + if TestVariantsTestInvertBool(true) != false { + panic("TestVariantsTestRoundtripBool") + } + if TestVariantsTestInvertBool(false) != true { + panic("TestVariantsTestRoundtripBool") + } + } + { + var a TestVariantsTestCasts + a.F0 = TestVariantsTestC1A(1) + a.F1 = TestVariantsTestC2A(2) + a.F2 = TestVariantsTestC3A(3) + a.F3 = TestVariantsTestC4A(4) + a.F4 = TestVariantsTestC5A(5) + a.F5 = TestVariantsTestC6A(6.0) + res := TestVariantsTestVariantCasts(a) + if res.F0.GetA() != 1 { + panic("TestVariantsTestVariantCasts") + } + if res.F1.GetA() != 2 { + panic("TestVariantsTestVariantCasts") + } + if res.F2.GetA() != 3 { + panic("TestVariantsTestVariantCasts") + } + if res.F3.GetA() != 4 { + panic("TestVariantsTestVariantCasts") + } + if res.F4.GetA() != 5 { + panic("TestVariantsTestVariantCasts") + } + if res.F5.GetA() != 6.0 { + panic("TestVariantsTestVariantCasts") + } + } + { + var a TestVariantsTestCasts + a.F0 = TestVariantsTestC1B(1) + a.F1 = TestVariantsTestC2B(2.0) + a.F2 = TestVariantsTestC3B(3.0) + a.F3 = TestVariantsTestC4B(4.0) + a.F4 = TestVariantsTestC5B(5.0) + a.F5 = TestVariantsTestC6B(6.0) + res := TestVariantsTestVariantCasts(a) + if res.F0.GetB() != 1 { + panic("TestVariantsTestVariantCasts") + } + if res.F1.GetB() != 2.0 { + panic("TestVariantsTestVariantCasts") + } + if res.F2.GetB() != 3.0 { + panic("TestVariantsTestVariantCasts") + } + if res.F3.GetB() != 4.0 { + panic("TestVariantsTestVariantCasts") + } + if res.F4.GetB() != 5.0 { + panic("TestVariantsTestVariantCasts") + } + if res.F5.GetB() != 6.0 { + panic("TestVariantsTestVariantCasts") + } + } + { + var a TestVariantsTestZeros + a.F0 = TestVariantsTestZ1A(1) + a.F1 = TestVariantsTestZ2A(2) + a.F2 = TestVariantsTestZ3A(3.0) + a.F3 = TestVariantsTestZ4A(4.0) + res := TestVariantsTestVariantZeros(a) + if res.F0.GetA() != 1 { + panic("TestVariantsTestVariantZeros") + } + if res.F1.GetA() != 2 { + panic("TestVariantsTestVariantZeros") + } + if res.F2.GetA() != 3.0 { + panic("TestVariantsTestVariantZeros") + } + if res.F3.GetA() != 4.0 { + panic("TestVariantsTestVariantZeros") + } + } + { + var a TestVariantsTestZeros + a.F0 = TestVariantsTestZ1B() + a.F1 = TestVariantsTestZ2B() + a.F2 = TestVariantsTestZ3B() + a.F3 = TestVariantsTestZ4B() + res := TestVariantsTestVariantZeros(a) + if res.F0.Kind() != TestVariantsTestZ1KindB { + panic("TestVariantsTestVariantZeros") + } + if res.F1.Kind() != TestVariantsTestZ2KindB { + panic("TestVariantsTestVariantZeros") + } + if res.F2.Kind() != TestVariantsTestZ3KindB { + panic("TestVariantsTestVariantZeros") + } + if res.F3.Kind() != TestVariantsTestZ4KindB { + panic("TestVariantsTestVariantZeros") + } + } + { + var res Result[uint32, struct{}] + res.SetErr(struct{}{}) + TestVariantsTestVariantTypedefs(None[uint32](), false, res) + } + { + var param Result[struct{}, struct{}] + param.Set(struct{}{}) + res := TestVariantsTestVariantEnums(true, param, TestVariantsTestMyErrnoSuccess()) + if res.F0 != false { + panic("TestVariantsTestVariantEnums") + } + if res.F1.IsOk() { + panic("TestVariantsTestVariantEnums") + } + if res.F2.Kind() != TestVariantsTestMyErrnoKindA { + panic("TestVariantsTestVariantEnums") + } + } + +} + +func (i VariantsImpl) RoundtripOption(a Option[float32]) Option[uint8] { + if a.IsNone() { + return None[uint8]() + } else { + return Some[uint8](uint8(a.Unwrap())) + } +} + +func (i VariantsImpl) RoundtripResult(a Result[uint32, float32]) Result[float64, uint8] { + var res Result[float64, uint8] + if a.IsOk() { + res.Set(float64(a.Unwrap())) + } else { + res.SetErr(uint8(a.UnwrapErr())) + } + return res +} + +func (i VariantsImpl) RoundtripEnum(a TestVariantsTestE1) TestVariantsTestE1 { + return a +} + +func (i VariantsImpl) InvertBool(a bool) bool { + return !a +} + +func (i VariantsImpl) VariantCasts(a TestVariantsTestCasts) TestVariantsTestCasts { + if a.F0.Kind() == TestVariantsTestC1KindA { + if a.F0.GetA() != 1 { + panic("TestVariantsTestVariantCasts") + } + } + return a +} + +func (i VariantsImpl) VariantZeros(a TestVariantsTestZeros) TestVariantsTestZeros { + return a +} + +func (i VariantsImpl) VariantTypedefs(a Option[uint32], b bool, c Result[uint32, struct{}]) { + +} + +func (i VariantsImpl) VariantEnums(a bool, b Result[struct{}, struct{}], c TestVariantsTestMyErrno) TestVariantsTestTuple3BoolResultEmptyEmptyTTestVariantsTestMyErrnoT { + return TestVariantsTestTuple3BoolResultEmptyEmptyTTestVariantsTestMyErrnoT{a, b, c} +} + +func main() {}