some compiler lib cleanup

This commit is contained in:
gluax 2022-06-08 10:53:41 -07:00
parent 5129276a4b
commit 3c7de6e389
4 changed files with 14 additions and 11 deletions

1
Cargo.lock generated
View File

@ -1355,6 +1355,7 @@ dependencies = [
name = "leo-test-framework" name = "leo-test-framework"
version = "1.5.3" version = "1.5.3"
dependencies = [ dependencies = [
"backtrace",
"leo-errors", "leo-errors",
"regex", "regex",
"serde", "serde",

View File

@ -147,23 +147,24 @@ impl<'a> Compiler<'a> {
/// ///
/// Runs the type checker pass. /// Runs the type checker pass.
/// ///
pub fn type_checker_pass(&'a self, symbol_table: &'a mut SymbolTable<'a>) -> Result<()> { pub fn type_checker_pass(&'a self, symbol_table: &mut SymbolTable<'_>) -> Result<()> {
TypeChecker::do_pass((&self.ast, symbol_table, self.handler)) TypeChecker::do_pass((&self.ast, &mut symbol_table.clone(), self.handler))
} }
/// ///
/// Runs the compiler stages. /// Runs the compiler stages.
/// ///
fn compiler_stages(&self) -> Result<SymbolTable<'_>> { pub fn compiler_stages(&self) -> Result<SymbolTable<'_>> {
let symbol_table = self.symbol_table_pass()?; let mut st = self.symbol_table_pass()?;
self.type_checker_pass(&mut symbol_table.clone())?; self.type_checker_pass(&mut st)?;
Ok(symbol_table) Ok(st)
} }
/// ///
/// Returns a compiled Leo program. /// Returns a compiled Leo program.
/// ///
pub fn compile(&self) -> Result<SymbolTable<'_>> { pub fn compile(&mut self) -> Result<SymbolTable<'_>> {
self.parse_program()?;
self.compiler_stages() self.compiler_stages()
} }
} }

View File

@ -132,8 +132,10 @@ fn collect_all_inputs(test: &Test) -> Result<Vec<PathBuf>, String> {
Ok(list) Ok(list)
} }
fn compile_and_process<'a>(parsed: &'a mut Compiler<'a>) -> Result<SymbolTable<'a>, LeoError> { fn compile_and_process<'a>(parsed: &'a mut Compiler<'a>) -> Result<SymbolTable<'_>, LeoError> {
parsed.compile() let mut st = parsed.symbol_table_pass()?;
parsed.type_checker_pass(&mut st)?;
Ok(st)
} }
// Errors used in this module. // Errors used in this module.
@ -203,7 +205,7 @@ fn run_test(test: Test, handler: &Handler, err_buf: &BufferEmitter) -> Result<Va
for input in inputs { for input in inputs {
let mut parsed = parsed.clone(); let mut parsed = parsed.clone();
handler.extend_if_error(parsed.parse_input(input))?; handler.extend_if_error(parsed.parse_input(input))?;
let initial_input_ast = hash_file("/tmp/output/inital_input_ast.json"); let initial_input_ast = hash_file("/tmp/output/initial_input_ast.json");
output_items.push(OutputItem { initial_input_ast }); output_items.push(OutputItem { initial_input_ast });
} }

View File

@ -181,7 +181,6 @@ impl Command for Build {
output_directory, output_directory,
Some(self.compiler_options.into()), Some(self.compiler_options.into()),
); );
program.parse_program()?;
program.parse_input(input_path.to_path_buf())?; program.parse_input(input_path.to_path_buf())?;
// Compute the current program checksum // Compute the current program checksum