Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 67dd0dc

Browse files
committed
exit_1 to code/native module
1 parent e9e0917 commit 67dd0dc

File tree

4 files changed

+72
-8
lines changed

4 files changed

+72
-8
lines changed

lumen_runtime/src/otp/erlang.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
pub mod add_2;
44
pub mod apply_3;
55
pub mod convert_time_unit_3;
6+
pub mod exit_1;
7+
pub mod link_1;
68
pub mod monotonic_time_0;
79
pub mod number_or_badarith_1;
810
pub mod self_0;
@@ -38,7 +40,7 @@ use liblumen_alloc::erts::term::{
3840
Term, Tuple, TypedTerm,
3941
};
4042
use liblumen_alloc::erts::ProcessControlBlock;
41-
use liblumen_alloc::{badarg, badarith, badkey, badmap, error, exit, raise, throw};
43+
use liblumen_alloc::{badarg, badarith, badkey, badmap, error, raise, throw};
4244

4345
use crate::binary::{start_length_to_part_range, PartRange, ToTermOptions};
4446
use crate::node;
@@ -822,10 +824,6 @@ pub fn error_2(reason: Term, arguments: Term) -> Result {
822824
Err(error!(reason, Some(arguments)).into())
823825
}
824826

825-
pub fn exit_1(reason: Term) -> Result {
826-
Err(exit!(reason).into())
827-
}
828-
829827
pub fn hd_1(list: Term) -> Result {
830828
let cons: Boxed<Cons> = list.try_into()?;
831829

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// wasm32 proptest cannot be compiled at the same time as non-wasm32 proptest, so disable tests that
2+
// use proptest completely for wasm32
3+
//
4+
// See https://github.com/rust-lang/cargo/issues/4866
5+
#[cfg(all(not(target_arch = "wasm32"), test))]
6+
mod test;
7+
8+
use std::sync::Arc;
9+
10+
use liblumen_alloc::erts::exception;
11+
use liblumen_alloc::erts::exception::system::Alloc;
12+
use liblumen_alloc::erts::process::code::stack::frame::{Frame, Placement};
13+
use liblumen_alloc::erts::process::code::{self, result_from_exception};
14+
use liblumen_alloc::erts::process::ProcessControlBlock;
15+
use liblumen_alloc::erts::term::{Atom, Term};
16+
use liblumen_alloc::{exit, ModuleFunctionArity};
17+
18+
pub fn place_frame_with_arguments(
19+
process: &ProcessControlBlock,
20+
placement: Placement,
21+
reason: Term,
22+
) -> Result<(), Alloc> {
23+
process.stack_push(reason)?;
24+
process.place_frame(frame(), placement);
25+
26+
Ok(())
27+
}
28+
29+
// Private
30+
31+
fn code(arc_process: &Arc<ProcessControlBlock>) -> code::Result {
32+
arc_process.reduce();
33+
34+
let reason = arc_process.stack_pop().unwrap();
35+
36+
match native(reason) {
37+
Ok(_) => unreachable!(),
38+
Err(exception) => result_from_exception(arc_process, exception),
39+
}
40+
}
41+
42+
fn frame() -> Frame {
43+
Frame::new(module_function_arity(), code)
44+
}
45+
46+
fn function() -> Atom {
47+
Atom::try_from_str("exit").unwrap()
48+
}
49+
50+
fn module_function_arity() -> Arc<ModuleFunctionArity> {
51+
Arc::new(ModuleFunctionArity {
52+
module: super::module(),
53+
function: function(),
54+
arity: 1,
55+
})
56+
}
57+
58+
fn native(reason: Term) -> exception::Result {
59+
Err(exit!(reason).into())
60+
}

lumen_runtime/src/otp/erlang/tests/exit_1.rs renamed to lumen_runtime/src/otp/erlang/exit_1/test.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
use super::*;
1+
use proptest::prop_assert_eq;
2+
use proptest::test_runner::{Config, TestRunner};
3+
4+
use liblumen_alloc::exit;
5+
6+
use crate::otp::erlang::exit_1;
7+
use crate::scheduler::with_process_arc;
8+
use crate::test::strategy;
29

310
#[test]
411
fn exits_with_reason() {
512
with_process_arc(|arc_process| {
613
TestRunner::new(Config::with_source_file(file!()))
714
.run(&strategy::term(arc_process.clone()), |reason| {
8-
prop_assert_eq!(erlang::exit_1(reason), Err(exit!(reason).into()));
15+
prop_assert_eq!(exit_1::native(reason), Err(exit!(reason).into()));
916

1017
Ok(())
1118
})

lumen_runtime/src/otp/erlang/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ mod divide_2;
5858
mod element_2;
5959
mod error_1;
6060
mod error_2;
61-
mod exit_1;
6261
mod hd_1;
6362
mod insert_element_3;
6463
mod is_alive_0;

0 commit comments

Comments
 (0)