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

Commit bf928a1

Browse files
committed
Allow eir interpreter tests to run concurrently
1 parent f20d57b commit bf928a1

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

liblumen_eir_interpreter/src/bin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use liblumen_eir_interpreter::{call_erlang, VM};
1616

1717
use liblumen_alloc::erts::term::Atom;
1818

19-
use lumen_runtime::registry;
19+
use lumen_runtime::scheduler::Scheduler;
2020

2121
fn parse_file<T, P>(path: P, config: ParseConfig) -> (T, Parser)
2222
where
@@ -70,8 +70,8 @@ fn main() {
7070

7171
&*VM;
7272

73-
let init_atom = Atom::try_from_str("init").unwrap();
74-
let init_arc_process = registry::atom_to_process(&init_atom).unwrap();
73+
let arc_scheduler = Scheduler::current();
74+
let init_arc_process = arc_scheduler.spawn_init(0).unwrap();
7575

7676
let module = Atom::try_from_str(&ident.module.as_str()).unwrap();
7777
let function = Atom::try_from_str(&ident.name.as_str()).unwrap();

liblumen_eir_interpreter/src/lib.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,22 @@ pub fn call_erlang(
135135

136136
#[cfg(test)]
137137
mod tests {
138-
139-
use liblumen_alloc::erts::term::Atom;
140-
use lumen_runtime::registry;
138+
use super::call_erlang;
139+
use super::VM;
141140

142141
use libeir_diagnostics::{ColorChoice, Emitter, StandardStreamEmitter};
142+
143143
use libeir_ir::Module;
144+
144145
use libeir_passes::PassManager;
146+
145147
use libeir_syntax_erl::ast::Module as ErlAstModule;
146148
use libeir_syntax_erl::lower_module;
147149
use libeir_syntax_erl::{Parse, ParseConfig, Parser};
148150

149-
use super::call_erlang;
150-
use super::VM;
151+
use liblumen_alloc::erts::term::Atom;
152+
153+
use lumen_runtime::scheduler::Scheduler;
151154

152155
fn parse<T>(input: &str, config: ParseConfig) -> (T, Parser)
153156
where
@@ -183,8 +186,8 @@ mod tests {
183186
fn nonexistent_function_call() {
184187
&*VM;
185188

186-
let init_atom = Atom::try_from_str("init").unwrap();
187-
let init_arc_process = registry::atom_to_process(&init_atom).unwrap();
189+
let arc_scheduler = Scheduler::current();
190+
let init_arc_process = arc_scheduler.spawn_init(0).unwrap();
188191

189192
let module = Atom::try_from_str("foo").unwrap();
190193
let function = Atom::try_from_str("bar").unwrap();
@@ -198,8 +201,8 @@ mod tests {
198201
fn simple_function() {
199202
&*VM;
200203

201-
let init_atom = Atom::try_from_str("init").unwrap();
202-
let init_arc_process = registry::atom_to_process(&init_atom).unwrap();
204+
let arc_scheduler = Scheduler::current();
205+
let init_arc_process = arc_scheduler.spawn_init(0).unwrap();
203206

204207
let module = Atom::try_from_str("simple_function_test").unwrap();
205208
let function = Atom::try_from_str("run").unwrap();
@@ -233,8 +236,8 @@ run() -> yay.
233236
fn fib() {
234237
&*VM;
235238

236-
let init_atom = Atom::try_from_str("init").unwrap();
237-
let init_arc_process = registry::atom_to_process(&init_atom).unwrap();
239+
let arc_scheduler = Scheduler::current();
240+
let init_arc_process = arc_scheduler.spawn_init(0).unwrap();
238241

239242
let module = Atom::try_from_str("fib").unwrap();
240243
let function = Atom::try_from_str("fib").unwrap();

liblumen_eir_interpreter/src/vm.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::rc::Rc;
2-
use std::sync::{Arc, RwLock};
2+
use std::sync::RwLock;
33

44
use libeir_ir::FunctionIdent;
55

66
use liblumen_alloc::erts::exception;
77
use liblumen_alloc::erts::process::{heap, next_heap_size, Status};
88
use liblumen_alloc::erts::term::{atom_unchecked, Atom, Term};
9-
use lumen_runtime::registry;
109
use lumen_runtime::scheduler::Scheduler;
1110
use lumen_runtime::system;
1211

@@ -21,15 +20,6 @@ impl VMState {
2120
pub fn new() -> Self {
2221
lumen_runtime::otp::erlang::apply_3::set_code(crate::code::apply);
2322

24-
let arc_scheduler = Scheduler::current();
25-
let init_arc_scheduler = Arc::clone(&arc_scheduler);
26-
let init_arc_process = init_arc_scheduler.spawn_init(0).unwrap();
27-
let init_atom = Atom::try_from_str("init").unwrap();
28-
29-
if !registry::put_atom_to_process(init_atom, init_arc_process) {
30-
panic!("Could not register init process");
31-
};
32-
3323
let mut modules = ModuleRegistry::new();
3424
modules.register_native_module(crate::native::make_erlang());
3525

@@ -44,8 +34,8 @@ impl VMState {
4434
fun: &FunctionIdent,
4535
args: &[Term],
4636
) -> Result<Rc<Term>, (Rc<Term>, Rc<Term>, Rc<Term>)> {
47-
let init_atom = Atom::try_from_str("init").unwrap();
48-
let init_arc_process = registry::atom_to_process(&init_atom).unwrap();
37+
let arc_scheduler = Scheduler::current();
38+
let init_arc_process = arc_scheduler.spawn_init(0).unwrap();
4939

5040
let module = Atom::try_from_str(&fun.module.as_str()).unwrap();
5141
let function = Atom::try_from_str(&fun.name.as_str()).unwrap();

0 commit comments

Comments
 (0)