Spawn process on_submit to allow heap to be sized correctly
+use std::convert::TryInto;
use std::sync::Arc;
use liblumen_alloc::erts::process::code::stack::frame::{Frame, Placement};
use liblumen_alloc::erts::process::{code, ProcessControlBlock};
+use liblumen_alloc::erts::term::atom_unchecked;
-use crate::elixir;
+use lumen_runtime::otp::erlang;
/// ```elixir
/// # label: 4
@@ -11,7 +13,7 @@ use crate::elixir;
/// # returned from call: n
/// # full stack: (n)
/// # returns: {time, value}
-/// dom(n)
+/// :erlang.spawn_opt(Chain, dom, [n], [min_heap_size: 79 + n *5])
/// ```
pub fn place_frame(process: &ProcessControlBlock, placement: Placement) {
process.place_frame(frame(process), placement);
@@ -24,8 +26,19 @@ fn code(arc_process: &Arc<ProcessControlBlock>) -> code::Result {
let n = arc_process.stack_pop().unwrap();
assert!(n.is_integer());
-
- elixir::chain::dom_1::place_frame_with_arguments(arc_process, Placement::Replace, n)?;
+ let n_usize: usize = n.try_into().unwrap();
+
+ erlang::spawn_opt_4::place_frame_with_arguments(
+ arc_process,
+ Placement::Replace,
+ atom_unchecked("Elixir.Chain"),
+ atom_unchecked("dom"),
+ arc_process.list_from_slice(&[n])?,
+ arc_process.list_from_slice(&[arc_process.tuple_from_slice(&[
+ atom_unchecked("min_heap_size"),
+ arc_process.integer(79 + n_usize * 5)?,
+ ])?])?,
+ )?;
ProcessControlBlock::call_code(arc_process)
}
