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

Commit 2bb7d11

Browse files
committed
hacked together eir interperter on lumen runtime
1 parent 8707401 commit 2bb7d11

File tree

20 files changed

+2464
-379
lines changed

20 files changed

+2464
-379
lines changed

Cargo.lock

Lines changed: 662 additions & 374 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ members = [
1414
"liblumen_core",
1515
"liblumen_diagnostics",
1616
"liblumen_syntax",
17+
"liblumen_eir_interpreter",
1718
]
1819

1920
[profile.release]

liblumen_alloc/src/erts/process.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,10 @@ impl ProcessControlBlock {
387387
creator: Term,
388388
module_function_arity: Arc<ModuleFunctionArity>,
389389
code: Code,
390+
env_hack: Vec<Term>,
390391
) -> Result<Term, Alloc> {
391392
self.acquire_heap()
392-
.closure(creator, module_function_arity, code)
393+
.closure(creator, module_function_arity, code, env_hack)
393394
}
394395

395396
/// Constructs a list of only the head and tail, and associated with the given process.

liblumen_alloc/src/erts/process/alloc/heap_alloc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ pub trait HeapAlloc {
158158
creator: Term,
159159
module_function_arity: Arc<ModuleFunctionArity>,
160160
code: Code,
161+
env_hack: Vec<Term>,
161162
) -> Result<Term, Alloc> {
162-
let closure = Closure::new(module_function_arity, code, creator);
163+
let closure = Closure::new(module_function_arity, code, creator, env_hack);
163164

164165
unsafe {
165166
let ptr = self.alloc_layout(Layout::new::<Closure>())?.as_ptr() as *mut Closure;

liblumen_alloc/src/erts/process/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ mod tuple_from_slice {
147147
};
148148

149149
process
150-
.closure(creator, module_function_arity, code)
150+
.closure(creator, module_function_arity, code, vec![])
151151
.unwrap()
152152
}
153153
}

liblumen_alloc/src/erts/term/closure.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ pub struct Closure {
2121
module_function_arity: Arc<ModuleFunctionArity>,
2222
code: Code, // pointer to function entry
2323
next: *mut u8, // off heap header
24+
pub env_hack: Vec<Term>,
2425
env_len: usize, // the number of free variables
2526
env: *mut Term, // pointer to first element of free variable array
2627
}
2728

2829
impl Closure {
29-
pub fn new(module_function_arity: Arc<ModuleFunctionArity>, code: Code, creator: Term) -> Self {
30+
pub fn new(module_function_arity: Arc<ModuleFunctionArity>, code: Code, creator: Term, env_hack: Vec<Term>) -> Self {
3031
let env_len = 0;
3132

3233
Self {
@@ -35,6 +36,7 @@ impl Closure {
3536
module_function_arity,
3637
code,
3738
next: ptr::null_mut(),
39+
env_hack,
3840
env_len,
3941
env: ptr::null_mut(),
4042
}

liblumen_alloc/src/erts/term/term.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,7 @@ pub enum BoolError {
16731673
#[derive(Debug)]
16741674
pub struct TypeError;
16751675

1676+
#[derive(Debug)]
16761677
pub enum TryIntoIntegerError {
16771678
Type,
16781679
OutOfRange,

liblumen_alloc/src/erts/term/tuple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ mod tests {
495495
};
496496

497497
process
498-
.closure(creator, module_function_arity, code)
498+
.closure(creator, module_function_arity, code, vec![])
499499
.unwrap()
500500
}
501501

liblumen_eir_interpreter/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "liblumen_eir_interpreter"
3+
version = "0.1.0"
4+
authors = ["Hans Elias B. Josephsen <me@hansihe.com>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[[bin]]
10+
name = "run_file"
11+
path = "src/bin.rs"
12+
13+
[dependencies]
14+
libeir_ir = { path = "../../core_erlang_3/libeir_ir" }
15+
libeir_syntax_erl = { path = "../../core_erlang_3/libeir_syntax_erl" }
16+
libeir_intern = { path = "../../core_erlang_3/libeir_intern" }
17+
libeir_diagnostics = { path = "../../core_erlang_3/libeir_diagnostics" }
18+
libeir_passes = { path = "../../core_erlang_3/libeir_passes" }
19+
cranelift-entity = "0.30.0"
20+
21+
liblumen_alloc = { path = "../liblumen_alloc" }
22+
lumen_runtime = { path = "../lumen_runtime" }
23+
24+
lazy_static = "1.3.0"
25+
clap = "2.33.0"

liblumen_eir_interpreter/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`cargo run -- --ident fib:run/0 fib.erl`

0 commit comments

Comments
 (0)