Skip to content

Commit 210f00a

Browse files
committed
fix self
1 parent 573e0ca commit 210f00a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

zenlang/src/vm/opcodes/vm_call.rs

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

67
impl VM {
78
pub fn op_call(&mut self) {
@@ -15,6 +16,12 @@ impl VM {
1516

1617
self.push_environment();
1718

19+
let this_name = &String::from("self");
20+
let environ = self.environs.last_mut().unwrap();
21+
let environ = &mut *environ.borrow_mut();
22+
environ.create_if_doesnt_exist(this_name);
23+
*environ.get_mut(this_name).unwrap() = core::mem::take(&mut self.self_var);
24+
1825
let start = self.bfas_stack_start.pop().unwrap();
1926
let end = self.bfas_stack_end.pop().unwrap();
2027
let diff = end - start;
@@ -35,6 +42,12 @@ impl VM {
3542

3643
self.environs.push(env);
3744

45+
let this_name = &String::from("self");
46+
let environ = self.environs.last_mut().unwrap();
47+
let environ = &mut *environ.borrow_mut();
48+
environ.create_if_doesnt_exist(this_name);
49+
*environ.get_mut(this_name).unwrap() = core::mem::take(&mut self.self_var);
50+
3851
let start = self.bfas_stack_start.pop().unwrap();
3952
let end = self.bfas_stack_end.pop().unwrap();
4053
let diff = end - start;

0 commit comments

Comments
 (0)