diff --git a/src/protocol/parser/mod.rs b/src/protocol/parser/mod.rs index 3dca61f0109c63bbe526e10dfd69e8e9cbf6feeb..acd963e0feb294e292cbf95b758b73d0c18a421c 100644 --- a/src/protocol/parser/mod.rs +++ b/src/protocol/parser/mod.rs @@ -10,6 +10,7 @@ pub(crate) mod pass_definitions_types; pub(crate) mod pass_validation_linking; pub(crate) mod pass_rewriting; pub(crate) mod pass_typing; +pub(crate) mod pass_stack_size; mod visitor; use tokens::*; @@ -21,6 +22,8 @@ use pass_imports::PassImport; use pass_definitions::PassDefinitions; use pass_validation_linking::PassValidationLinking; use pass_typing::{PassTyping, ResolveQueue}; +use pass_rewriting::PassRewriting; +use pass_stack_size::PassStackSize; use symbol_table::*; use type_table::TypeTable; @@ -37,9 +40,10 @@ pub enum ModuleCompilationPhase { DefinitionsParsed, // produced the AST for the entire module TypesAddedToTable, // added all definitions to the type table ValidatedAndLinked, // AST is traversed and has linked the required AST nodes + Typed, // Type inference and checking has been performed Rewritten, // Special AST nodes are rewritten into regular AST nodes // When we continue with the compiler: - // Typed, // Type inference and checking has been performed + // StackSize } pub struct Module { @@ -87,6 +91,8 @@ pub struct Parser { pass_definitions: PassDefinitions, pass_validation: PassValidationLinking, pass_typing: PassTyping, + pass_rewriting: PassRewriting, + pass_stack_size: PassStackSize, // Compiler options pub write_ast_to: Option, pub(crate) arch: TargetArch, @@ -106,6 +112,8 @@ impl Parser { pass_definitions: PassDefinitions::new(), pass_validation: PassValidationLinking::new(), pass_typing: PassTyping::new(), + pass_rewriting: PassRewriting::new(), + pass_stack_size: PassStackSize::new(), write_ast_to: None, arch: TargetArch { array_size_alignment: (3*8, 8), // pointer, length, capacity @@ -254,6 +262,21 @@ impl Parser { self.pass_typing.handle_module_definition(&mut ctx, &mut queue, top)?; } + // Rewrite nodes in tree, then prepare for execution of code + for module_idx in 0..self.modules.len() { + self.modules[module_idx].phase = ModuleCompilationPhase::Typed; + let mut ctx = visitor::Ctx{ + heap: &mut self.heap, + modules: &mut self.modules, + module_idx, + symbols: &mut self.symbol_table, + types: &mut self.type_table, + arch: &self.arch, + }; + self.pass_rewriting.visit_module(&mut ctx); + self.pass_stack_size.visit_module(&mut ctx); + } + // Write out desired information if let Some(filename) = &self.write_ast_to { let mut writer = ASTWriter::new();