Skip to content

Commit 75cdf0b

Browse files
committed
did stuff
1 parent 565c0ba commit 75cdf0b

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

a.zen

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
mod stdlib;
2-
let x;
32

43
fn main {
5-
let x = [1,2,3];
6-
return x;
4+
println("main");
5+
println(get_ok(File.read("a.zen")));
6+
println(File.a);
7+
return null;
78
}

zenlang/src/stdlib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use alloc::string::*;
99
pub fn compile_stdlib_module() -> Module {
1010
let code = String::from(
1111
r#"
12+
let File;
13+
1214
fn #[naked] print str {
1315
vmcall 1;
1416
return null;
@@ -99,6 +101,16 @@ fn number str {
99101
}
100102
fn clone obj {
101103
return _vmcall_ret_unsafe_2(obj, 19);
104+
}
105+
fn #[ctor] stdlib_init {
106+
println("ctor");
107+
let File = {
108+
"read" = read_file,
109+
"read_bytes" = read_file_bytes,
110+
"write" = write_file,
111+
"write_bytes" = write_file_bytes,
112+
"test" = 123
113+
};
102114
}
103115
"#,
104116
);
@@ -152,6 +164,7 @@ fn clone obj {
152164
"gc".into(),
153165
module.opcodes.len() as u32,
154166
0,
167+
false,
155168
));
156169
module.opcodes.push(Opcode::Gc());
157170
module.opcodes.push(Opcode::Ret());
@@ -160,6 +173,7 @@ fn clone obj {
160173
"gcoff".into(),
161174
module.opcodes.len() as u32,
162175
0,
176+
false,
163177
));
164178
module.opcodes.push(Opcode::Gcoff());
165179
module.opcodes.push(Opcode::Ret());
@@ -168,6 +182,7 @@ fn clone obj {
168182
"gcon".into(),
169183
module.opcodes.len() as u32,
170184
0,
185+
false,
171186
));
172187
module.opcodes.push(Opcode::Gcon());
173188
module.opcodes.push(Opcode::Ret());

zenlang/src/vm/vm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ impl VM {
7777

7878
for func in module.functions.iter() {
7979
if func.ctor {
80-
self.pc.set_low((func.addr - 1) as u32);
80+
self.pc.set_low((func.addr) as u32);
8181
self.pc.set_high((self.modules.len() - 1) as u32);
82-
self.add_scope();
8382

84-
loop {
83+
while !self.halted {
8584
if !self.step() {
8685
break;
8786
}
@@ -90,6 +89,7 @@ impl VM {
9089
self.scopes.clear();
9190

9291
if !self.error.is_empty() {
92+
self.halted = true;
9393
return Err(format!(
9494
"in constructor of module {}: {}",
9595
module.name, self.error

0 commit comments

Comments
 (0)