mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
Use a constant for RocCallResult tag size
This commit is contained in:
parent
ab7d2d5912
commit
f1ddf775cb
2 changed files with 6 additions and 9 deletions
|
@ -17,8 +17,8 @@ mod repl_eval {
|
||||||
// relies on this size
|
// relies on this size
|
||||||
let value: i64 = 1234;
|
let value: i64 = 1234;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
std::mem::size_of_val(RocCallResult::Success(value)),
|
std::mem::size_of_val(&RocCallResult::Success(value)),
|
||||||
RocCallResult::size_of_discriminant() + std::mem::size_of_val(value)
|
roc_gen::run_roc::ROC_CALL_RESULT_DISCRIMINANT_SIZE + std::mem::size_of_val(&value)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@ use std::ffi::CString;
|
||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
use RocCallResult::*;
|
use RocCallResult::*;
|
||||||
|
|
||||||
|
/// This must have the same size as the repr() of RocCallResult!
|
||||||
|
pub const ROC_CALL_RESULT_DISCRIMINANT_SIZE: usize = std::mem::size_of::<u64>();
|
||||||
|
|
||||||
#[repr(u64)]
|
#[repr(u64)]
|
||||||
pub enum RocCallResult<T> {
|
pub enum RocCallResult<T> {
|
||||||
Success(T),
|
Success(T),
|
||||||
|
@ -26,12 +29,6 @@ impl<T: Sized> From<RocCallResult<T>> for Result<T, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> RocCallResult<T> {
|
|
||||||
const fn size_of_discriminant() -> usize {
|
|
||||||
std::mem::size_of::<u64>()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! run_jit_function {
|
macro_rules! run_jit_function {
|
||||||
($lib: expr, $main_fn_name: expr, $ty:ty, $transform:expr) => {{
|
($lib: expr, $main_fn_name: expr, $ty:ty, $transform:expr) => {{
|
||||||
|
@ -89,7 +86,7 @@ macro_rules! run_jit_function_dynamic_type {
|
||||||
.ok_or(format!("Unable to JIT compile `{}`", $main_fn_name))
|
.ok_or(format!("Unable to JIT compile `{}`", $main_fn_name))
|
||||||
.expect("errored");
|
.expect("errored");
|
||||||
|
|
||||||
let size = RocCallResult::size_of_discriminant() + $bytes;
|
let size = roc_gen::run_roc::ROC_CALL_RESULT_DISCRIMINANT_SIZE + $bytes;
|
||||||
let layout = std::alloc::Layout::array::<u8>(size).unwrap();
|
let layout = std::alloc::Layout::array::<u8>(size).unwrap();
|
||||||
let result = std::alloc::alloc(layout);
|
let result = std::alloc::alloc(layout);
|
||||||
main(result);
|
main(result);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue