diff --git a/components/lox-compile/src/compile.rs b/components/lox-compile/src/compile.rs index 58e2ac6..9939883 100644 --- a/components/lox-compile/src/compile.rs +++ b/components/lox-compile/src/compile.rs @@ -14,7 +14,7 @@ pub fn compile_file(db: &dyn crate::Db, input_file: InputFile) -> Chunk { syntax::Stmt::Print(expr) => { compile_expr(db, expr, &mut chunk); chunk.emit_byte(Code::Print) - }, + } syntax::Stmt::Var { name, initializer } => { if let Some(initializer) = initializer { compile_expr(db, initializer, &mut chunk); @@ -79,6 +79,6 @@ fn compile_expr(db: &dyn crate::Db, expr: &syntax::Expr, chunk: &mut Chunk) { syntax::Expr::Variable(word) => { let word_str = word.as_str(db); chunk.emit_byte(Code::Variable(word_str.to_string())) - }, + } } } diff --git a/components/lox-execute/src/vm.rs b/components/lox-execute/src/vm.rs index 33333c9..58ca10c 100644 --- a/components/lox-execute/src/vm.rs +++ b/components/lox-execute/src/vm.rs @@ -222,18 +222,18 @@ impl VM { let value = self.pop(); // FIXME: This should be a call to a intrinsic function. println!("{:?}", value); - }, + } bytecode::Code::VarDeclaration(name) => { let value = self.pop(); self.globals.insert(name, value); - }, + } bytecode::Code::Nil => { self.push(Value::Nil); - }, + } bytecode::Code::Variable(name) => { let value = self.globals.get(&name).expect("variable not found"); self.push(value.clone()); - }, + } } if let Some(step_inspect) = &mut step_inspect { step_inspect(instruction, self); diff --git a/components/lox-ir/src/bytecode.rs b/components/lox-ir/src/bytecode.rs index 2a0b140..bc1cc96 100644 --- a/components/lox-ir/src/bytecode.rs +++ b/components/lox-ir/src/bytecode.rs @@ -18,8 +18,8 @@ pub enum Code { LessEqual, String(String), Print, - VarDeclaration(String), - Variable(String), + VarDeclaration(String), + Variable(String), Nil, } diff --git a/components/lox-ir/src/kw.rs b/components/lox-ir/src/kw.rs index d870a7b..7c93abf 100644 --- a/components/lox-ir/src/kw.rs +++ b/components/lox-ir/src/kw.rs @@ -62,4 +62,4 @@ pub struct Keywords {} #[salsa::tracked(return_ref)] pub(crate) fn keywords_map(db: &dyn crate::Db, _k: Keywords) -> HashMap { Keyword::all().map(|kw| (kw.word(db), kw)).collect() -} \ No newline at end of file +} diff --git a/components/lox-ir/src/lib.rs b/components/lox-ir/src/lib.rs index 23af4af..0b45a45 100644 --- a/components/lox-ir/src/lib.rs +++ b/components/lox-ir/src/lib.rs @@ -15,7 +15,7 @@ pub struct Jar( token_tree::TokenTree, diagnostic::Diagnostics, kw::Keywords, - kw::keywords_map + kw::keywords_map, ); pub trait Db: salsa::DbWithJar {} diff --git a/components/lox-ir/src/syntax.rs b/components/lox-ir/src/syntax.rs index bc4e207..a302ace 100644 --- a/components/lox-ir/src/syntax.rs +++ b/components/lox-ir/src/syntax.rs @@ -62,7 +62,6 @@ impl<'db> salsa::DebugWithDb for Expr { } } - #[derive(Debug, Clone, PartialEq, Eq)] pub enum Stmt { // expression statement, like `1 + 2;` @@ -75,20 +74,30 @@ pub enum Stmt { Var { name: Word, initializer: Option, - } + }, } impl salsa::DebugWithDb for Stmt { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>, db: &dyn crate::Db, _include_all_fields: bool) -> std::fmt::Result { + fn fmt( + &self, + f: &mut std::fmt::Formatter<'_>, + db: &dyn crate::Db, + _include_all_fields: bool, + ) -> std::fmt::Result { match self { - Stmt::Expr(expr) => f.debug_struct("Expr").field("expr", &expr.debug(db)).finish(), - Stmt::Print(expr) => f.debug_struct("Print").field("expr", &expr.debug(db)).finish(), - Stmt::Var { name, initializer } => { - f.debug_struct("Var") - .field("name", &name.as_str(db)) - .field("initializer", &initializer.debug(db)) - .finish() - } + Stmt::Expr(expr) => f + .debug_struct("Expr") + .field("expr", &expr.debug(db)) + .finish(), + Stmt::Print(expr) => f + .debug_struct("Print") + .field("expr", &expr.debug(db)) + .finish(), + Stmt::Var { name, initializer } => f + .debug_struct("Var") + .field("name", &name.as_str(db)) + .field("initializer", &initializer.debug(db)) + .finish(), } } -} \ No newline at end of file +} diff --git a/components/lox-parse/src/parser.rs b/components/lox-parse/src/parser.rs index c97290b..38d2197 100644 --- a/components/lox-parse/src/parser.rs +++ b/components/lox-parse/src/parser.rs @@ -9,7 +9,7 @@ use lox_ir::{ }; use crate::{ - token_test::{AnyTree, Number, StringLiteral, TokenTest, Identifier}, + token_test::{AnyTree, Identifier, Number, StringLiteral, TokenTest}, tokens::Tokens, }; diff --git a/src/main.rs b/src/main.rs index 7de845f..8db6ab4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,12 +3,11 @@ use std::{ path::{Path, PathBuf}, }; +use clap::{Parser, Subcommand}; use expect_test::expect_file; use lox_ir::{bytecode, diagnostic::Diagnostics, input_file::InputFile, word::Word}; use salsa::DebugWithDb; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; -use clap::{Parser, Subcommand}; - #[salsa::db( lox_parse::Jar, @@ -43,7 +42,7 @@ impl TestCase { let lox = TestCase::absolute_path(lox); if lox.extension().unwrap_or_default() != "lox" { panic!("expected lox file, got {}", lox.display()); - } + } // if the lox file is `foo/bar.lox`, then the generated files will be // `foo/bar/{token,syntax,bytecode,execute}` @@ -164,7 +163,6 @@ fn main() { .with(EnvFilter::from_default_env()) .init(); - let cli = Cli::parse(); let db = Database::default(); @@ -184,6 +182,6 @@ fn main() { let test_case = TestCase::new(&path); test_case.test(&db); } - }, + } } }