@@ -1183,15 +1183,15 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
11831183 deriviation. push ( "Eq" )
11841184 }
11851185 let declaration = if self . gen . opts . derive_error && name. contains ( "Error" ) {
1186- "type! "
1186+ "suberror "
11871187 } else {
1188- "type "
1188+ "struct "
11891189 } ;
11901190
11911191 uwrite ! (
11921192 self . src,
11931193 r#"
1194- pub(all) {declaration} {name} Int derive({})
1194+ pub(all) {declaration} {name}( Int) derive({})
11951195 "# ,
11961196 deriviation. join( ", " ) ,
11971197 ) ;
@@ -1227,14 +1227,14 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
12271227 fn wasmExportResourceNew{name}(rep : Int) -> Int = "[export]{module}" "[resource-new]{type_name}"
12281228
12291229 /// Drops a resource handle.
1230- pub fn {name}::drop(self : {name} ) -> Unit {{
1230+ pub fn {name}::drop(self : Self ) -> Unit {{
12311231 let {name}(resource) = self
12321232 wasmExportResourceDrop{name}(resource)
12331233 }}
12341234 fn wasmExportResourceDrop{name}(resource : Int) = "[export]{module}" "[resource-drop]{type_name}"
12351235
12361236 /// Gets the `Int` representation of the resource pointed to the given handle.
1237- pub fn {name}::rep(self : {name} ) -> Int {{
1237+ pub fn {name}::rep(self : Self ) -> Int {{
12381238 let {name}(resource) = self
12391239 wasmExportResourceRep{name}(resource)
12401240 }}
@@ -1324,15 +1324,15 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
13241324 deriviation. push ( "Eq" )
13251325 }
13261326 let declaration = if self . gen . opts . derive_error && name. contains ( "Error" ) {
1327- "type! "
1327+ "suberror "
13281328 } else {
1329- "type "
1329+ "struct "
13301330 } ;
13311331
13321332 uwrite ! (
13331333 self . src,
13341334 "
1335- pub(all) {declaration} {name} {ty} derive({})
1335+ pub(all) {declaration} {name}( {ty}) derive({})
13361336 pub fn {name}::default() -> {name} {{
13371337 {}
13381338 }}
@@ -1344,15 +1344,15 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
13441344 {map_to_int}
13451345 }}
13461346 }}
1347- pub fn {name}::set(self : {name} , other: {name}Flag) -> {name} {{
1347+ pub fn {name}::set(self : Self , other: {name}Flag) -> {name} {{
13481348 let {name}(flag) = self
13491349 flag.lor(other.value())
13501350 }}
1351- pub fn {name}::unset(self : {name} , other: {name}Flag) -> {name} {{
1351+ pub fn {name}::unset(self : Self , other: {name}Flag) -> {name} {{
13521352 let {name}(flag) = self
13531353 flag.land(other.value().lnot())
13541354 }}
1355- pub fn {name}::is_set(self : {name} , other: {name}Flag) -> Bool {{
1355+ pub fn {name}::is_set(self : Self , other: {name}Flag) -> Bool {{
13561356 let {name}(flag) = self
13571357 (flag.land(other.value()) == other.value())
13581358 }}
@@ -1399,7 +1399,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
13991399 deriviation. push ( "Eq" )
14001400 }
14011401 let declaration = if self . gen . opts . derive_error && name. contains ( "Error" ) {
1402- "type! "
1402+ "suberror "
14031403 } else {
14041404 "enum"
14051405 } ;
@@ -1444,7 +1444,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
14441444 deriviation. push ( "Eq" )
14451445 }
14461446 let declaration = if self . gen . opts . derive_error && name. contains ( "Error" ) {
1447- "type! "
1447+ "suberror "
14481448 } else {
14491449 "enum"
14501450 } ;
@@ -1785,7 +1785,9 @@ impl Bindgen for FunctionBindgen<'_, '_> {
17851785 Instruction :: F32FromCoreF32 => results. push ( operands[ 0 ] . clone ( ) ) ,
17861786 Instruction :: CoreF32FromF32 => results. push ( operands[ 0 ] . clone ( ) ) ,
17871787
1788- Instruction :: CharFromI32 => results. push ( format ! ( "Char::from_int({})" , operands[ 0 ] ) ) ,
1788+ Instruction :: CharFromI32 => {
1789+ results. push ( format ! ( "Int::unsafe_to_char({})" , operands[ 0 ] ) )
1790+ }
17891791 Instruction :: I32FromChar => results. push ( format ! ( "({}).to_int()" , operands[ 0 ] ) ) ,
17901792
17911793 Instruction :: I32FromU8 => results. push ( format ! ( "({}).to_int()" , operands[ 0 ] ) ) ,
@@ -2874,14 +2876,21 @@ impl ToMoonBitIdent for str {
28742876 fn to_moonbit_ident ( & self ) -> String {
28752877 // Escape MoonBit keywords and reserved keywords
28762878 match self {
2877- "module" | "move" | "ref" | "static" | "super" | "unsafe" | "use" | "where"
2878- | "await" | "dyn" | "abstract" | "do" | "final" | "macro" | "override" | "typeof"
2879- | "virtual" | "yield" | "local" | "method" | "alias" | "assert" | "as" | "else"
2880- | "extern" | "fn" | "if" | "let" | "const" | "match" | "mut" | "type" | "typealias"
2881- | "struct" | "enum" | "trait" | "traitalias" | "derive" | "while" | "break"
2882- | "continue" | "import" | "return" | "throw" | "raise" | "try" | "catch" | "pub"
2883- | "priv" | "readonly" | "true" | "false" | "_" | "test" | "loop" | "for" | "in"
2884- | "impl" | "with" | "guard" | "async" | "is" | "init" | "main" => {
2879+ // Keywords
2880+ "as" | "else" | "extern" | "fn" | "fnalias" | "if" | "let" | "const" | "match" | "using"
2881+ | "mut" | "type" | "typealias" | "struct" | "enum" | "trait" | "traitalias" | "derive"
2882+ | "while" | "break" | "continue" | "import" | "return" | "throw" | "raise" | "try" | "catch"
2883+ | "pub" | "priv" | "readonly" | "true" | "false" | "_" | "test" | "loop" | "for" | "in" | "impl"
2884+ | "with" | "guard" | "async" | "is" | "suberror" | "and" | "letrec" | "enumview" | "noraise"
2885+ | "defer" | "init" | "main"
2886+ // Reserved keywords
2887+ | "module" | "move" | "ref" | "static" | "super" | "unsafe" | "use" | "where" | "await"
2888+ | "dyn" | "abstract" | "do" | "final" | "macro" | "override" | "typeof" | "virtual" | "yield"
2889+ | "local" | "method" | "alias" | "assert" | "package" | "recur" | "isnot" | "define" | "downcast"
2890+ | "inherit" | "member" | "namespace" | "upcast" | "void" | "lazy" | "include" | "mixin"
2891+ | "protected" | "sealed" | "constructor" | "atomic" | "volatile" | "anyframe" | "anytype"
2892+ | "asm" | "comptime" | "errdefer" | "export" | "opaque" | "orelse" | "resume" | "threadlocal"
2893+ | "unreachable" | "dynclass" | "dynobj" | "dynrec" | "var" | "finally" | "noasync" => {
28852894 format ! ( "{self}_" )
28862895 }
28872896 _ => self . to_snake_case ( ) ,
0 commit comments