@@ -111,34 +111,34 @@ extern "wasm" fn copy_inline(dest : Int, src : Int, len : Int) =
111
111
#|(func (param i32) (param i32) (param i32) local.get 0 local.get 1 local.get 2 memory.copy)
112
112
113
113
pub extern "wasm" fn str2ptr(str : String) -> Int =
114
- #|(func (param i32) (result i32) local.get 0 call $moonbit.decref local.get 0 i32.const 8 i32.add)
114
+ #|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)
115
115
116
116
pub extern "wasm" fn ptr2str(ptr : Int) -> String =
117
117
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.const 243 i32.store8 local.get 0 i32.const 8 i32.sub)
118
118
119
119
pub extern "wasm" fn bytes2ptr(bytes : Bytes) -> Int =
120
- #|(func (param i32) (result i32) local.get 0 call $moonbit.decref local.get 0 i32.const 8 i32.add)
120
+ #|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)
121
121
122
122
pub extern "wasm" fn ptr2bytes(ptr : Int) -> Bytes =
123
123
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)
124
124
125
125
pub extern "wasm" fn uint_array2ptr(array : FixedArray[UInt]) -> Int =
126
- #|(func (param i32) (result i32) local.get 0 call $moonbit.decref local.get 0 i32.const 8 i32.add)
126
+ #|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)
127
127
128
128
pub extern "wasm" fn uint64_array2ptr(array : FixedArray[UInt64]) -> Int =
129
- #|(func (param i32) (result i32) local.get 0 call $moonbit.decref local.get 0 i32.const 8 i32.add)
129
+ #|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)
130
130
131
131
pub extern "wasm" fn int_array2ptr(array : FixedArray[Int]) -> Int =
132
- #|(func (param i32) (result i32) local.get 0 call $moonbit.decref local.get 0 i32.const 8 i32.add)
132
+ #|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)
133
133
134
134
pub extern "wasm" fn int64_array2ptr(array : FixedArray[Int64]) -> Int =
135
- #|(func (param i32) (result i32) local.get 0 call $moonbit.decref local.get 0 i32.const 8 i32.add)
135
+ #|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)
136
136
137
137
pub extern "wasm" fn float_array2ptr(array : FixedArray[Float]) -> Int =
138
- #|(func (param i32) (result i32) local.get 0 call $moonbit.decref local.get 0 i32.const 8 i32.add)
138
+ #|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)
139
139
140
140
pub extern "wasm" fn double_array2ptr(array : FixedArray[Double]) -> Int =
141
- #|(func (param i32) (result i32) local.get 0 call $moonbit.decref local.get 0 i32.const 8 i32.add)
141
+ #|(func (param i32) (result i32) local.get 0 i32.const 8 i32.add)
142
142
143
143
pub extern "wasm" fn ptr2uint_array(ptr : Int) -> FixedArray[UInt] =
144
144
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.const 241 i32.store8 local.get 0 i32.const 8 i32.sub)
@@ -575,11 +575,17 @@ impl WorldGenerator for MoonBit {
575
575
{ffi_qualifier}free(src_offset)
576
576
dst
577
577
}}
578
-
579
- let return_area : Int = {ffi_qualifier}malloc({})
580
- " ,
581
- self . return_area_size,
578
+ "
582
579
) ;
580
+ if self . return_area_size != 0 {
581
+ uwriteln ! (
582
+ & mut body,
583
+ "
584
+ let return_area : Int = {ffi_qualifier}malloc({})
585
+ " ,
586
+ self . return_area_size,
587
+ ) ;
588
+ }
583
589
files. push ( & format ! ( "{EXPORT_DIR}/ffi.mbt" ) , indent ( & body) . as_bytes ( ) ) ;
584
590
self . export
585
591
. insert ( "cabi_realloc" . into ( ) , "cabi_realloc" . into ( ) ) ;
@@ -797,7 +803,7 @@ impl InterfaceGenerator<'_> {
797
803
. collect :: < Vec < _ > > ( )
798
804
. join ( ", " ) ;
799
805
800
- let sig = self . sig_string ( func) ;
806
+ let sig = self . sig_string ( func, false ) ;
801
807
802
808
uwriteln ! (
803
809
self . ffi,
@@ -820,7 +826,7 @@ impl InterfaceGenerator<'_> {
820
826
fn export ( & mut self , interface_name : Option < & str > , func : & Function ) {
821
827
let sig = self . resolve . wasm_signature ( AbiVariant :: GuestExport , func) ;
822
828
823
- let func_sig = self . sig_string ( func) ;
829
+ let func_sig = self . sig_string ( func, true ) ;
824
830
825
831
let export_name = func. core_export_name ( interface_name) ;
826
832
@@ -1039,7 +1045,7 @@ impl InterfaceGenerator<'_> {
1039
1045
}
1040
1046
}
1041
1047
1042
- fn sig_string ( & mut self , func : & Function ) -> String {
1048
+ fn sig_string ( & mut self , func : & Function , ignore_param : bool ) -> String {
1043
1049
let name = match func. kind {
1044
1050
FunctionKind :: Freestanding => func. name . to_moonbit_ident ( ) ,
1045
1051
FunctionKind :: Constructor ( _) => {
@@ -1074,7 +1080,11 @@ impl InterfaceGenerator<'_> {
1074
1080
. iter ( )
1075
1081
. map ( |( name, ty) | {
1076
1082
let ty = self . type_name ( ty, true ) ;
1077
- let name = name. to_moonbit_ident ( ) ;
1083
+ let name = if ignore_param {
1084
+ format ! ( "_{}" , name. to_moonbit_ident( ) )
1085
+ } else {
1086
+ name. to_moonbit_ident ( )
1087
+ } ;
1078
1088
format ! ( "{name} : {ty}" )
1079
1089
} )
1080
1090
. collect :: < Vec < _ > > ( )
@@ -1202,7 +1212,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
1202
1212
& mut self . stub,
1203
1213
r#"
1204
1214
/// Destructor of the resource.
1205
- pub fn {name}::dtor(self : {name}) -> Unit {{
1215
+ pub fn {name}::dtor(_self : {name}) -> Unit {{
1206
1216
abort("todo")
1207
1217
}}
1208
1218
"#
@@ -1570,8 +1580,10 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
1570
1580
. collect :: < Vec < _ > > ( )
1571
1581
. join ( ", " ) ;
1572
1582
1573
- let payload = if self . gen . non_empty_type ( ty. as_ref ( ) ) . is_some ( ) || is_result {
1583
+ let payload = if self . gen . non_empty_type ( ty. as_ref ( ) ) . is_some ( ) {
1574
1584
payload
1585
+ } else if is_result {
1586
+ format ! ( "_{payload}" )
1575
1587
} else {
1576
1588
String :: new ( )
1577
1589
} ;
@@ -1601,7 +1613,6 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
1601
1613
r#"
1602
1614
match {op} {{
1603
1615
{cases}
1604
- _ => panic()
1605
1616
}}
1606
1617
"#
1607
1618
) ;
@@ -1611,7 +1622,6 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
1611
1622
r#"
1612
1623
let ({declarations}) = match {op} {{
1613
1624
{cases}
1614
- _ => panic()
1615
1625
}}
1616
1626
"#
1617
1627
) ;
@@ -2109,13 +2119,14 @@ impl Bindgen for FunctionBindgen<'_, '_> {
2109
2119
Type :: U8 => {
2110
2120
let result = self . locals . tmp ( "result" ) ;
2111
2121
let address = & operands[ 0 ] ;
2112
- let _length = & operands[ 1 ] ;
2122
+ let length = & operands[ 1 ] ;
2113
2123
2114
2124
uwrite ! (
2115
2125
self . src,
2116
2126
"
2117
- let {result} = {ffi_qualifier}ptr2bytes({address})
2118
- "
2127
+ ignore({length})
2128
+ let {result} = {ffi_qualifier}ptr2bytes({address})
2129
+ "
2119
2130
) ;
2120
2131
2121
2132
results. push ( result) ;
@@ -2132,13 +2143,14 @@ impl Bindgen for FunctionBindgen<'_, '_> {
2132
2143
2133
2144
let result = self . locals . tmp ( "result" ) ;
2134
2145
let address = & operands[ 0 ] ;
2135
- let _length = & operands[ 1 ] ;
2146
+ let length = & operands[ 1 ] ;
2136
2147
2137
2148
uwrite ! (
2138
2149
self . src,
2139
2150
"
2140
- let {result} = {ffi_qualifier}ptr2{ty}_array({address})
2141
- "
2151
+ ignore({length})
2152
+ let {result} = {ffi_qualifier}ptr2{ty}_array({address})
2153
+ "
2142
2154
) ;
2143
2155
2144
2156
results. push ( result) ;
@@ -2159,11 +2171,12 @@ impl Bindgen for FunctionBindgen<'_, '_> {
2159
2171
Instruction :: StringLift { .. } => {
2160
2172
let result = self . locals . tmp ( "result" ) ;
2161
2173
let address = & operands[ 0 ] ;
2162
- let _length = & operands[ 1 ] ;
2174
+ let length = & operands[ 1 ] ;
2163
2175
2164
2176
uwrite ! (
2165
2177
self . src,
2166
2178
"
2179
+ ignore({length})
2167
2180
let {result} = {ffi_qualifier}ptr2str({address})
2168
2181
"
2169
2182
) ;
@@ -2502,6 +2515,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
2502
2515
"
2503
2516
match ({op}) {{
2504
2517
{cases}
2518
+ _ => panic()
2505
2519
}}
2506
2520
"
2507
2521
) ;
@@ -2750,7 +2764,7 @@ impl ToMoonBitIdent for str {
2750
2764
"continue" | "for" | "match" | "if" | "pub" | "priv" | "readonly" | "break"
2751
2765
| "raise" | "try" | "except" | "catch" | "else" | "enum" | "struct" | "type"
2752
2766
| "trait" | "return" | "let" | "mut" | "while" | "loop" | "extern" | "with"
2753
- | "throw" | "init" | "main" | "test" | "in" => {
2767
+ | "throw" | "init" | "main" | "test" | "in" | "guard" => {
2754
2768
format ! ( "{self}_" )
2755
2769
}
2756
2770
_ => self . to_snake_case ( ) ,
0 commit comments