mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
fix calling convention problems
This commit is contained in:
parent
29df340a26
commit
d5bf526d66
2 changed files with 44 additions and 40 deletions
|
@ -975,7 +975,7 @@ fn overflow_frees_list() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
|
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
|
||||||
#[should_panic(expected = "Roc failed with message: ")]
|
#[should_panic(expected = "Roc failed with message: ")]
|
||||||
fn undefined_variable() {
|
fn undefined_variable() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
|
|
|
@ -285,7 +285,7 @@ impl<T> RocCallResult<T> {
|
||||||
let tag = (n - 1) as u32;
|
let tag = (n - 1) as u32;
|
||||||
let tag = tag
|
let tag = tag
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap_or_else(|_| panic!("received illegal tag: {tag}"));
|
.unwrap_or_else(|_| panic!("received illegal tag: {tag} {msg}"));
|
||||||
|
|
||||||
(msg.as_str().to_owned(), tag)
|
(msg.as_str().to_owned(), tag)
|
||||||
}),
|
}),
|
||||||
|
@ -293,6 +293,27 @@ impl<T> RocCallResult<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_test_main_fn<T>(
|
||||||
|
lib: &libloading::Library,
|
||||||
|
) -> libloading::Symbol<unsafe extern "C" fn() -> RocCallResult<T>> {
|
||||||
|
let main_fn_name = "test_main";
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
lib.get(main_fn_name.as_bytes())
|
||||||
|
.ok()
|
||||||
|
.ok_or(format!("Unable to JIT compile `{main_fn_name}`"))
|
||||||
|
.expect("errored")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn run_test_main<T>(lib: &libloading::Library) -> Result<T, (String, CrashTag)> {
|
||||||
|
let main = get_test_main_fn::<T>(lib);
|
||||||
|
|
||||||
|
let result = unsafe { main() };
|
||||||
|
|
||||||
|
result.into_result()
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Sized> From<RocCallResult<T>> for Result<T, (String, CrashTag)> {
|
impl<T: Sized> From<RocCallResult<T>> for Result<T, (String, CrashTag)> {
|
||||||
fn from(call_result: RocCallResult<T>) -> Self {
|
fn from(call_result: RocCallResult<T>) -> Self {
|
||||||
call_result.into_result()
|
call_result.into_result()
|
||||||
|
@ -321,54 +342,37 @@ macro_rules! assert_evals_to {
|
||||||
};
|
};
|
||||||
($src:expr, $expected:expr, $ty:ty, $transform:expr, $leak:expr, $lazy_literals:expr) => {
|
($src:expr, $expected:expr, $ty:ty, $transform:expr, $leak:expr, $lazy_literals:expr) => {
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use $crate::helpers::dev::RocCallResult;
|
|
||||||
|
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let (_main_fn_name, errors, lib) =
|
let (_main_fn_name, errors, lib) =
|
||||||
$crate::helpers::dev::helper(&arena, $src, $leak, $lazy_literals);
|
$crate::helpers::dev::helper(&arena, $src, $leak, $lazy_literals);
|
||||||
|
|
||||||
let transform = |success| {
|
let result = $crate::helpers::dev::run_test_main::<$ty>(&lib);
|
||||||
let expected = $expected;
|
|
||||||
#[allow(clippy::redundant_closure_call)]
|
|
||||||
let given = $transform(success);
|
|
||||||
assert_eq!(&given, &expected, "output is different");
|
|
||||||
};
|
|
||||||
|
|
||||||
let main_fn_name = "test_main";
|
if !errors.is_empty() {
|
||||||
|
dbg!(&errors);
|
||||||
|
|
||||||
type Main = unsafe extern "C" fn(*mut RocCallResult<$ty>);
|
assert_eq!(
|
||||||
|
errors,
|
||||||
|
std::vec::Vec::new(),
|
||||||
|
"Encountered errors: {:?}",
|
||||||
|
errors
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
unsafe {
|
match result {
|
||||||
let main: libloading::Symbol<Main> = lib
|
Ok(value) => {
|
||||||
.get(main_fn_name.as_bytes())
|
let expected = $expected;
|
||||||
.ok()
|
#[allow(clippy::redundant_closure_call)]
|
||||||
.ok_or(format!("Unable to JIT compile `{}`", main_fn_name))
|
let given = $transform(value);
|
||||||
.expect("errored");
|
assert_eq!(&given, &expected, "output is different");
|
||||||
|
|
||||||
let mut result = std::mem::MaybeUninit::uninit();
|
|
||||||
main(result.as_mut_ptr());
|
|
||||||
let result = result.assume_init();
|
|
||||||
|
|
||||||
if !errors.is_empty() {
|
|
||||||
dbg!(&errors);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
errors,
|
|
||||||
std::vec::Vec::new(),
|
|
||||||
"Encountered errors: {:?}",
|
|
||||||
errors
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
Err((msg, tag)) => {
|
||||||
|
use roc_mono::ir::CrashTag;
|
||||||
|
|
||||||
match result.into_result() {
|
match tag {
|
||||||
Ok(value) => transform(value),
|
CrashTag::Roc => panic!(r#"Roc failed with message: "{msg}""#),
|
||||||
Err((msg, tag)) => {
|
CrashTag::User => panic!(r#"User crash with message: "{msg}""#),
|
||||||
use roc_mono::ir::CrashTag;
|
|
||||||
|
|
||||||
match tag {
|
|
||||||
CrashTag::Roc => panic!(r#"Roc failed with message: "{msg}""#),
|
|
||||||
CrashTag::User => panic!(r#"User crash with message: "{msg}""#),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue