diff --git a/crates/starlight/src/bin/sl.rs b/crates/starlight/src/bin/sl.rs index ee346091..9a192000 100644 --- a/crates/starlight/src/bin/sl.rs +++ b/crates/starlight/src/bin/sl.rs @@ -16,7 +16,6 @@ const SNAPSHOT_FILENAME: &str = ".startup-snapshot"; fn main() { Platform::initialize(); let options = Options::from_args(); - let mut deserialized = false; let mut rt = if Path::new(SNAPSHOT_FILENAME).exists() { let mut src = std::fs::read(SNAPSHOT_FILENAME); diff --git a/crates/starlight/src/bytecode/opcodes.rs b/crates/starlight/src/bytecode/opcodes.rs index 079b98bd..2bb694a4 100644 --- a/crates/starlight/src/bytecode/opcodes.rs +++ b/crates/starlight/src/bytecode/opcodes.rs @@ -280,4 +280,7 @@ pub enum Opcode { OP_YIELD_STAR, OP_AWAIT, OP_NEWGENERATOR, + + OP_FAST_CALL, + OP_FAST_RET } diff --git a/crates/starlight/src/bytecompiler.rs b/crates/starlight/src/bytecompiler.rs index 9a6babf8..9bfb9b20 100644 --- a/crates/starlight/src/bytecompiler.rs +++ b/crates/starlight/src/bytecompiler.rs @@ -111,9 +111,31 @@ pub struct ByteCompiler { pub variable_freelist: Vec, pub info: Option, FileLocation)>>, + + pub in_try_stmt: bool, + pub fast_calls: Vec> } impl ByteCompiler { + pub fn new( rt: RuntimeRef, builtins: bool,code:GcPointer,scope: Rc>)-> Self { + Self { + lci: Vec::new(), + builtins, + variable_freelist: Vec::with_capacity(4), + code, + tail_pos: false, + info: None, + fmap: HashMap::new(), + val_map: HashMap::new(), + name_map: HashMap::new(), + top_level: false, + scope, + rt: rt, + in_try_stmt: false, + fast_calls: Vec::new() + } + } + pub fn get_val(&mut self, vm: &mut Runtime, val: Val) -> u32 { if let Some(ix) = self.val_map.get(&val) { return *ix; @@ -472,20 +494,7 @@ impl ByteCompiler { depth: 0, })); let mut code = CodeBlock::new(vm, "".intern(), false, rel_path.into()); - let mut compiler = ByteCompiler { - lci: Vec::new(), - builtins, - variable_freelist: Vec::with_capacity(4), - code, - tail_pos: false, - info: None, - fmap: HashMap::new(), - val_map: HashMap::new(), - name_map: HashMap::new(), - top_level: false, - scope, - rt: RuntimeRef(&mut *vm), - }; + let mut compiler = ByteCompiler::new(RuntimeRef(vm),builtins,code,scope); let mut p = 0; for x in params_.iter() { params.push(x.intern()); @@ -573,20 +582,7 @@ impl ByteCompiler { depth: self.scope.borrow().depth + 1, })); - let mut compiler = ByteCompiler { - lci: Vec::new(), - builtins: self.builtins, - variable_freelist: Vec::with_capacity(4), - code, - info: None, - tail_pos: false, - fmap: HashMap::new(), - val_map: HashMap::new(), - name_map: HashMap::new(), - top_level: false, - scope, - rt: RuntimeRef(&mut *self.rt), - }; + let mut compiler = ByteCompiler::new(self.rt,self.builtins,code,scope); let mut p = 0; for x in function.params.iter() { match x.pat { @@ -667,24 +663,11 @@ impl ByteCompiler { let mut code = CodeBlock::new(&mut vm, name, false, path.into()); code.file_name = file.to_string(); - let mut compiler = ByteCompiler { - lci: Vec::new(), - top_level: true, - info: None, - tail_pos: false, - builtins: false, - scope: Rc::new(RefCell::new(Scope { - parent: None, - variables: Default::default(), - depth: 0, - })), - variable_freelist: vec![], - code, - val_map: Default::default(), - name_map: Default::default(), - fmap: Default::default(), - rt: RuntimeRef(vm), - }; + let mut compiler = ByteCompiler::new(RuntimeRef(vm),false,code,Rc::new(RefCell::new(Scope { + parent: None, + variables: Default::default(), + depth: 0 + }))); code.var_count = 1; code.param_count = 1; compiler.scope.borrow_mut().add_var("@module".intern(), 0); @@ -857,24 +840,13 @@ impl ByteCompiler { let name = "