File tree Expand file tree Collapse file tree 3 files changed +21
-9
lines changed Expand file tree Collapse file tree 3 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -161,13 +161,15 @@ mod tests {
161161
162162 // Verify function body
163163 assert ! ( generated. contains( "arg0 := value" ) ) ;
164+ assert ! ( generated. contains( "result0 := api.EncodeU32(arg0)" ) ) ;
164165 assert ! (
165- generated. contains( "i.module.ExportedFunction(\" add_number\" ).Call(ctx, uint64(arg0))" )
166+ generated
167+ . contains( "i.module.ExportedFunction(\" add_number\" ).Call(ctx, uint64(result0))" )
166168 ) ;
167- assert ! ( generated. contains( "if err0 != nil {" ) ) ;
168- assert ! ( generated. contains( "panic(err0 )" ) ) ;
169- assert ! ( generated. contains( "results0 := raw0 [0]" ) ) ;
170- assert ! ( generated. contains( "result1 := uint32(results0 )" ) ) ;
171- assert ! ( generated. contains( "return result1 " ) ) ;
169+ assert ! ( generated. contains( "if err1 != nil {" ) ) ;
170+ assert ! ( generated. contains( "panic(err1 )" ) ) ;
171+ assert ! ( generated. contains( "results1 := raw1 [0]" ) ) ;
172+ assert ! ( generated. contains( "result2 := api.DecodeU32(results1 )" ) ) ;
173+ assert ! ( generated. contains( "return result2 " ) ) ;
172174 }
173175}
Original file line number Diff line number Diff line change @@ -310,17 +310,22 @@ impl Bindgen for Func<'_> {
310310 results. push ( Operand :: SingleValue ( value) )
311311 }
312312 Instruction :: I32FromU32 => {
313- // It seems like this isn't needed because Wazero works with Go's uint32 type
313+ let tmp = self . tmp ( ) ;
314+ let result = & format ! ( "result{tmp}" ) ;
314315 let operand = & operands[ 0 ] ;
315- results. push ( operand. clone ( ) ) ;
316+ quote_in ! { self . body =>
317+ $[ '\r' ]
318+ $result : = $( & self . go_imports. wazero_api_encode_u32) ( $operand)
319+ } ;
320+ results. push ( Operand :: SingleValue ( result. into ( ) ) ) ;
316321 }
317322 Instruction :: U32FromI32 => {
318323 let tmp = self . tmp ( ) ;
319324 let result = & format ! ( "result{tmp}" ) ;
320325 let operand = & operands[ 0 ] ;
321326 quote_in ! { self . body =>
322327 $[ '\r' ]
323- $result : = uint32 ( $operand)
328+ $result : = $ ( & self . go_imports . wazero_api_decode_u32 ) ( $operand)
324329 } ;
325330 results. push ( Operand :: SingleValue ( result. into ( ) ) ) ;
326331 }
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ pub struct GoImports {
1414 pub wazero_api_decode_i32 : Import ,
1515 pub wazero_api_encode_i32 : Import ,
1616 pub wazero_api_decode_u32 : Import ,
17+ pub wazero_api_encode_u32 : Import ,
1718}
1819
1920impl Default for GoImports {
@@ -61,6 +62,10 @@ impl GoImports {
6162 "github.com/tetratelabs/wazero/api" ,
6263 "DecodeU32" ,
6364 ) ,
65+ wazero_api_encode_u32 : genco:: lang:: go:: import (
66+ "github.com/tetratelabs/wazero/api" ,
67+ "EncodeU32" ,
68+ ) ,
6469 }
6570 }
6671}
You can’t perform that action at this time.
0 commit comments