diff --git a/libs/rust/src/lib.rs b/libs/rust/src/lib.rs index 47b5474..995498d 100644 --- a/libs/rust/src/lib.rs +++ b/libs/rust/src/lib.rs @@ -30,17 +30,29 @@ mod host { } pub mod num { - use crate::types::{number::Type, JSNumber, Null, Number}; + use crate::types::{ffi::CTuple, number::Type, JSNumber, Null, Number}; + use core::ffi::c_void; pub type Setter = extern "C" fn(Number, JSNumber); pub type Getter = extern "C" fn(Number) -> JSNumber; #[link(wasm_import_module = "nusa")] #[allow(improper_ctypes)] extern "C" { + #[cfg(target_feature = "multivalue")] #[link_name = "num.allocate"] pub fn allocate(ty: Type, len: u16, nullable: bool) -> (Number, Null); + + #[cfg(not(target_feature = "multivalue"))] + #[link_name = "num.cABIallocate"] + pub fn allocate(ty: Type, len: u16, nullable: bool) -> CTuple; + + #[cfg(target_feature = "multivalue")] #[link_name = "num.accessor"] pub fn accessor(ty: Type) -> (Getter, Setter); + + #[cfg(not(target_feature = "multivalue"))] + #[link_name = "num.cABIaccessor"] + pub fn accessor(ty: Type) -> CTuple<*const c_void, *const c_void>; } #[link(wasm_import_module = "nusa")] diff --git a/libs/rust/src/number.rs b/libs/rust/src/number.rs index e488715..22fa768 100644 --- a/libs/rust/src/number.rs +++ b/libs/rust/src/number.rs @@ -1,5 +1,5 @@ use crate::{host, types, Accessor, Series}; -use core::primitive; +use core::{intrinsics::transmute, primitive}; use types::number::{JSNumber, Type}; macro_rules! bridge { @@ -19,7 +19,7 @@ macro_rules! bridge { } fn allocate(len: host::Size) -> (usize, usize) { - let (number, null) = unsafe { host::num::allocate(Type::$Ty, len, false) }; + let (number, null) = unsafe { host::num::allocate(Type::$Ty, len, false).into() }; (number.addr, null.addr) } @@ -33,8 +33,8 @@ macro_rules! bridge { pub fn new() -> Self { let len = unsafe { host::scope::size() }; let (addr, _) = Self::allocate(len); - let (getter, setter) = unsafe { host::num::accessor(Type::$Ty) }; - let accr = (getter, setter); + let (getter, setter) = unsafe { host::num::accessor(Type::$Ty).into() }; + let accr = unsafe { (transmute(getter), transmute(setter)) }; $ty { len, addr, accr } } }