Skip to content

Commit 573e0ca

Browse files
committed
move closure opcode into its own file
1 parent 5623551 commit 573e0ca

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

zenlang/src/parser/parser_expr.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use core::fmt::Error;
2-
31
use crate::ast::*;
42
use crate::parser::parser::Parser;
53
use crate::tokenizer::*;

zenlang/src/vm/opcodes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod vm_branch;
55
mod vm_cafse;
66
mod vm_call;
77
mod vm_cdfse;
8+
mod vm_closure;
89
mod vm_cmp;
910
mod vm_fn_args;
1011
mod vm_iafs;

zenlang/src/vm/opcodes/vm_call.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::strong_u64::U64BitsControl;
22
use crate::value::*;
33
use crate::vm::VM;
44
use alloc::format;
5-
use alloc::string::*;
65

76
impl VM {
87
pub fn op_call(&mut self) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use crate::strong_u64::U64BitsControl;
2+
use crate::value::Value;
3+
use crate::vm::VM;
4+
5+
impl VM {
6+
pub fn op_closure(&mut self, skip: u32, args: u64) {
7+
let value = Value::FunctionRefEnv(
8+
self.pc.get_low() as u64,
9+
args,
10+
self.environs.last().unwrap().clone(),
11+
);
12+
13+
self.pc.add_low(skip);
14+
15+
self.stack.push(value);
16+
}
17+
}

zenlang/src/vm/vm_opcode.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
use crate::opcode::*;
2-
use crate::strong_u64::U64BitsControl;
3-
use crate::value::Value;
42
use crate::vm::*;
53
use alloc::format;
64

@@ -117,16 +115,7 @@ impl VM {
117115
self.op_ret();
118116
}
119117
Opcode::Closure(skip, args) => {
120-
let value = Value::FunctionRefEnv(
121-
self.pc.get_low() as u64,
122-
*args,
123-
self.environs.last().unwrap().clone(),
124-
);
125-
126-
self.pc.add_low(*skip);
127-
128-
self.stack.push(value);
129-
//panic!();
118+
self.op_closure(*skip, *args);
130119
}
131120
}
132121
}

0 commit comments

Comments
 (0)