@@ -7,7 +7,11 @@ import { BINDING, runtimeHelpers } from "./modules";
77import { js_to_mono_enum , _js_to_mono_obj , _js_to_mono_uri } from "./js-to-cs" ;
88import { js_string_to_mono_string , js_string_to_mono_string_interned } from "./strings" ;
99import { MarshalType , _unbox_mono_obj_root_with_known_nonprimitive_type } from "./cs-to-js" ;
10- import { _create_temp_frame } from "./memory" ;
10+ import {
11+ _create_temp_frame ,
12+ getI32 , getU32 , getF32 , getF64 ,
13+ setI32 , setU32 , setF32 , setF64 , setI64 ,
14+ } from "./memory" ;
1115import {
1216 _get_args_root_buffer_for_method_call , _get_buffer_for_method_call ,
1317 _handle_exception_for_call , _teardown_after_call
@@ -213,15 +217,18 @@ export function _compile_converter_for_marshal_string(args_marshal: ArgsMarshalS
213217 Module,
214218 _malloc : Module . _malloc ,
215219 mono_wasm_unbox_rooted : cwraps . mono_wasm_unbox_rooted ,
220+ setI32,
221+ setU32,
222+ setF32,
223+ setF64,
224+ setI64
216225 } ;
217226 let indirectLocalOffset = 0 ;
218227
219228 body . push (
220229 "if (!method) throw new Error('no method provided');" ,
221230 `if (!buffer) buffer = _malloc (${ bufferSizeBytes } );` ,
222231 `let indirectStart = buffer + ${ indirectBaseOffset } ;` ,
223- "let indirect32 = indirectStart >>> 2, indirect64 = indirectStart >>> 3;" ,
224- "let buffer32 = buffer >>> 2;" ,
225232 ""
226233 ) ;
227234
@@ -253,37 +260,35 @@ export function _compile_converter_for_marshal_string(args_marshal: ArgsMarshalS
253260 body . push ( `${ valueKey } = mono_wasm_unbox_rooted (${ valueKey } );` ) ;
254261
255262 if ( step . indirect ) {
256- let heapArrayName = null ;
263+ const offsetText = `(indirectStart + ${ indirectLocalOffset } )` ;
257264
258265 switch ( step . indirect ) {
259266 case "u32" :
260- heapArrayName = "HEAPU32" ;
267+ body . push ( `setU32( ${ offsetText } , ${ valueKey } );` ) ;
261268 break ;
262269 case "i32" :
263- heapArrayName = "HEAP32" ;
270+ body . push ( `setI32( ${ offsetText } , ${ valueKey } );` ) ;
264271 break ;
265272 case "float" :
266- heapArrayName = "HEAPF32" ;
273+ body . push ( `setF32( ${ offsetText } , ${ valueKey } );` ) ;
267274 break ;
268275 case "double" :
269- body . push ( `Module.HEAPF64[indirect64 + ${ ( indirectLocalOffset >>> 3 ) } ] = ${ valueKey } ;` ) ;
276+ body . push ( `setF64( ${ offsetText } , ${ valueKey } ) ;` ) ;
270277 break ;
271278 case "i64" :
272- body . push ( `Module.setValue (indirectStart + ${ indirectLocalOffset } , ${ valueKey } , 'i64' );` ) ;
279+ body . push ( `setI64( ${ offsetText } , ${ valueKey } );` ) ;
273280 break ;
274281 default :
275282 throw new Error ( "Unimplemented indirect type: " + step . indirect ) ;
276283 }
277284
278- if ( heapArrayName )
279- body . push ( `Module.${ heapArrayName } [indirect32 + ${ ( indirectLocalOffset >>> 2 ) } ] = ${ valueKey } ;` ) ;
280-
281- body . push ( `Module.HEAP32[buffer32 + ${ i } ] = indirectStart + ${ indirectLocalOffset } ;` , "" ) ;
285+ body . push ( `setU32(buffer + (${ i } * 4), ${ offsetText } );` ) ;
282286 indirectLocalOffset += step . size ! ;
283287 } else {
284- body . push ( `Module.HEAP32[buffer32 + ${ i } ] = ${ valueKey } ;` , "" ) ;
288+ body . push ( `setI32(buffer + ( ${ i } * 4), ${ valueKey } );` ) ;
285289 indirectLocalOffset += 4 ;
286290 }
291+ body . push ( "" ) ;
287292 }
288293
289294 body . push ( "return buffer;" ) ;
@@ -404,7 +409,11 @@ export function mono_bind_method(method: MonoMethod, this_arg: MonoObject | null
404409 this_arg,
405410 token,
406411 unbox_buffer,
407- unbox_buffer_size
412+ unbox_buffer_size,
413+ getI32,
414+ getU32,
415+ getF32,
416+ getF64
408417 } ;
409418
410419 const converterKey = converter ? "converter_" + converter . name : "" ;
@@ -493,18 +502,18 @@ export function mono_bind_method(method: MonoMethod, this_arg: MonoObject | null
493502 " let resultType = mono_wasm_try_unbox_primitive_and_get_type (resultPtr, unbox_buffer, unbox_buffer_size);" ,
494503 " switch (resultType) {" ,
495504 ` case ${ MarshalType . INT } :` ,
496- " result = Module.HEAP32[ unbox_buffer >>> 2] ; break;" ,
505+ " result = getI32( unbox_buffer) ; break;" ,
497506 ` case ${ MarshalType . POINTER } :` , // FIXME: Is this right?
498507 ` case ${ MarshalType . UINT32 } :` ,
499- " result = Module.HEAPU32[ unbox_buffer >>> 2] ; break;" ,
508+ " result = getU32( unbox_buffer) ; break;" ,
500509 ` case ${ MarshalType . FP32 } :` ,
501- " result = Module.HEAPF32[ unbox_buffer >>> 2] ; break;" ,
510+ " result = getF32( unbox_buffer) ; break;" ,
502511 ` case ${ MarshalType . FP64 } :` ,
503- " result = Module.HEAPF64[ unbox_buffer >>> 3] ; break;" ,
512+ " result = getF64( unbox_buffer) ; break;" ,
504513 ` case ${ MarshalType . BOOL } :` ,
505- " result = (Module.HEAP32[ unbox_buffer >>> 2] ) !== 0; break;" ,
514+ " result = getI32( unbox_buffer) !== 0; break;" ,
506515 ` case ${ MarshalType . CHAR } :` ,
507- " result = String.fromCharCode(Module.HEAP32[ unbox_buffer >>> 2] ); break;" ,
516+ " result = String.fromCharCode(getI32( unbox_buffer) ); break;" ,
508517 " default:" ,
509518 " result = _unbox_mono_obj_root_with_known_nonprimitive_type (resultRoot, resultType, unbox_buffer); break;" ,
510519 " }" ,
0 commit comments