Skip to content

Commit 02f0784

Browse files
fix(moonbit): set tag correctly (#1037)
1 parent 04cef2f commit 02f0784

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

crates/moonbit/src/lib.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,35 @@ pub extern "wasm" fn ptr2int_array(ptr : Int) -> FixedArray[Int] =
149149
pub extern "wasm" fn ptr2float_array(ptr : Int) -> FixedArray[Float] =
150150
#|(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)
151151
152-
pub extern "wasm" fn ptr2uint64_array(ptr : Int) -> FixedArray[UInt64] =
153-
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.load i32.const 1 i32.shr_u i32.const 241 i32.or local.get 0 i32.const 4 i32.sub i32.store local.get 0 i32.const 8 i32.sub)
152+
extern "wasm" fn ptr2uint64_array_ffi(ptr : Int) -> FixedArray[UInt64] =
153+
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)
154+
155+
pub fn ptr2uint64_array(ptr : Int) -> FixedArray[UInt64] {
156+
set_64_header_ffi(ptr - 4)
157+
ptr2uint64_array_ffi(ptr)
158+
}
154159
155-
pub extern "wasm" fn ptr2int64_array(ptr : Int) -> FixedArray[Int64] =
156-
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.load i32.const 1 i32.shr_u i32.const 241 i32.or local.get 0 i32.const 4 i32.sub i32.store local.get 0 i32.const 8 i32.sub)
160+
extern "wasm" fn ptr2int64_array_ffi(ptr : Int) -> FixedArray[Int64] =
161+
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)
162+
163+
pub fn ptr2int64_array(ptr : Int) -> FixedArray[Int64] {
164+
set_64_header_ffi(ptr - 4)
165+
ptr2int64_array_ffi(ptr)
166+
}
157167
158-
pub extern "wasm" fn ptr2double_array(ptr : Int) -> FixedArray[Double] =
159-
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.load i32.const 1 i32.shr_u i32.const 241 i32.or local.get 0 i32.const 4 i32.sub i32.store local.get 0 i32.const 8 i32.sub)
168+
extern "wasm" fn ptr2double_array_ffi(ptr : Int) -> FixedArray[Double] =
169+
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)
170+
171+
pub fn ptr2double_array(ptr : Int) -> FixedArray[Double] {
172+
set_64_header_ffi(ptr - 4)
173+
ptr2double_array_ffi(ptr)
174+
}
175+
176+
fn set_64_header_ffi(offset : Int) -> Unit {
177+
let len = load32(offset)
178+
store32(offset, len.lsr(1))
179+
store8(offset, 241)
180+
}
160181
161182
pub trait Any {}
162183
pub struct Cleanup {

0 commit comments

Comments
 (0)