feat(tazjin/rlox): Implement variable depth resolver
Implements the first part of the resolver from https://craftinginterpreters.com/resolving-and-binding.html This is wired up to the execution paths in main, but not yet in the tests. The resolved depth is also not actually used for variable lookups (yet). Change-Id: I3a8615252b7b9b12d5a290c5ddf85988f61b9184 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2403 Reviewed-by: tazjin <mail@tazj.in> Tested-by: BuildkiteCI
This commit is contained in:
parent
f472c82427
commit
29335a8b63
5 changed files with 217 additions and 16 deletions
|
|
@ -7,6 +7,7 @@ use std::process;
|
|||
mod errors;
|
||||
mod interpreter;
|
||||
mod parser;
|
||||
mod resolver;
|
||||
mod scanner;
|
||||
|
||||
fn main() {
|
||||
|
|
@ -48,17 +49,13 @@ fn run_prompt() {
|
|||
fn run(lox: &mut interpreter::Interpreter, code: &str) {
|
||||
let chars: Vec<char> = code.chars().collect();
|
||||
|
||||
match scanner::scan(&chars) {
|
||||
Ok(tokens) => match parser::parse(tokens) {
|
||||
Ok(program) => {
|
||||
println!("Program:\n{:?}", program);
|
||||
if let Err(err) = lox.interpret(&program) {
|
||||
println!("Error in program: {:?}", err);
|
||||
}
|
||||
}
|
||||
Err(errors) => report_errors(errors),
|
||||
},
|
||||
Err(errors) => report_errors(errors),
|
||||
let result = scanner::scan(&chars)
|
||||
.and_then(|tokens| parser::parse(tokens))
|
||||
.and_then(|program| resolver::resolve(program).map_err(|e| vec![e]))
|
||||
.and_then(|program| lox.interpret(&program).map_err(|e| vec![e]));
|
||||
|
||||
if let Err(errors) = result {
|
||||
report_errors(errors);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue