File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed
Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 11mod stdlib;
2- let x;
32
43fn 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}
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ use alloc::string::*;
99pub fn compile_stdlib_module ( ) -> Module {
1010 let code = String :: from (
1111 r#"
12+ let File;
13+
1214fn #[naked] print str {
1315 vmcall 1;
1416 return null;
@@ -99,6 +101,16 @@ fn number str {
99101}
100102fn 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 ( ) ) ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments