-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from xffxff/lazy_compile
refactor: make the compiler work lazily
- Loading branch information
Showing
47 changed files
with
221 additions
and
697 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use lox_ir::bytecode::CompiledFunction; | ||
|
||
use crate::compile::compile; | ||
|
||
pub trait FunctionCompileExt { | ||
fn compile(&self, db: &dyn crate::Db) -> CompiledFunction; | ||
} | ||
|
||
impl FunctionCompileExt for lox_ir::function::Function { | ||
fn compile(&self, db: &dyn crate::Db) -> CompiledFunction { | ||
compile(db, *self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
use lox_compile::compile; | ||
use lox_ir::{bytecode, input_file::InputFile}; | ||
|
||
use crate::vm::{ControlFlow, VM}; | ||
|
||
#[salsa::tracked] | ||
pub fn main_function(db: &dyn crate::Db, input_file: InputFile) -> lox_ir::function::Function { | ||
let tree = lox_lex::lex_file(db, input_file); | ||
let name = lox_ir::word::Word::new(db, "main".to_string()); | ||
lox_ir::function::Function::new(db, name, vec![], tree) | ||
} | ||
|
||
pub fn execute_file( | ||
db: &impl crate::Db, | ||
input_file: InputFile, | ||
step_inspect: Option<impl FnMut(Option<bytecode::Code>, &VM) + Clone>, | ||
) -> String { | ||
let function = compile::compile_file(db, input_file); | ||
let mut vm = VM::new(function); | ||
let main = main_function(db, input_file); | ||
let mut vm = VM::new(main, db); | ||
|
||
while let ControlFlow::Next = vm.step(step_inspect.clone()) {} | ||
while let ControlFlow::Next = vm.step(db, step_inspect.clone()) {} | ||
|
||
vm.output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.