diff --git a/src/protocol/parser/mod.rs b/src/protocol/parser/mod.rs index 9ef01e4a58319347b06620e5b7012a140d093c5d..f8099e570194ba10d7b2caadbf7ec7786b472e32 100644 --- a/src/protocol/parser/mod.rs +++ b/src/protocol/parser/mod.rs @@ -298,7 +298,7 @@ impl Parser { types: &mut self.type_table, arch: &self.arch, }; - PassTyping::queue_module_definitions(&mut ctx, &mut queue); + self.pass_typing.queue_module_definitions(&mut ctx, &mut queue); }; while !queue.is_empty() { let top = queue.pop().unwrap(); @@ -352,16 +352,21 @@ fn insert_builtin_type(type_table: &mut TypeTable, parts: Vec, &[] }; - return type_table.add_builtin_type(concrete_type, poly_var, size, alignment); + return type_table.add_builtin_data_type(concrete_type, poly_var, size, alignment); } // Note: args and return type need to be a function because we need to know the function ID. fn insert_builtin_function (Vec<(&'static str, ParserType)>, ParserType)> ( p: &mut Parser, func_name: &str, polymorphic: &[&str], arg_and_return_fn: T ) { - let mut poly_vars = Vec::with_capacity(polymorphic.len()); + // Insert into AST (to get an ID), also prepare the polymorphic variables + // we need later for the type table + let mut ast_poly_vars = Vec::with_capacity(polymorphic.len()); + let mut type_poly_vars = Vec::with_capacity(polymorphic.len()); for poly_var in polymorphic { - poly_vars.push(Identifier{ span: InputSpan::new(), value: p.string_pool.intern(poly_var.as_bytes()) }); + let identifier = Identifier{ span: InputSpan::new(), value: p.string_pool.intern(poly_var.as_bytes()) } ; + ast_poly_vars.push(identifier.clone()); + type_poly_vars.push(PolymorphicVariable{ identifier, is_in_use: false }); } let func_ident_ref = p.string_pool.intern(func_name.as_bytes()); @@ -372,14 +377,15 @@ fn insert_builtin_function (Vec<(&'static str, P kind: ProcedureKind::Function, span: InputSpan::new(), identifier: Identifier{ span: InputSpan::new(), value: func_ident_ref.clone() }, - poly_vars, + poly_vars: ast_poly_vars, return_type: None, parameters: Vec::new(), scope: ScopeId::new_invalid(), body: BlockStatementId::new_invalid(), - num_expressions_in_body: -1, + monomorphs: Vec::new(), }); + // Modify AST with more information about the procedure let (arguments, return_type) = arg_and_return_fn(procedure_id); let mut parameters = Vec::with_capacity(arguments.len()); @@ -400,6 +406,7 @@ fn insert_builtin_function (Vec<(&'static str, P func.parameters = parameters; func.return_type = Some(return_type); + // Insert into symbol table p.symbol_table.insert_symbol(SymbolScope::Global, Symbol{ name: func_ident_ref, variant: SymbolVariant::Definition(SymbolDefinition{ @@ -412,4 +419,13 @@ fn insert_builtin_function (Vec<(&'static str, P definition_id: procedure_id.upcast(), }) }).unwrap(); + + // Insert into type table + let mut concrete_type = ConcreteType::default(); + concrete_type.parts.push(ConcreteTypePart::Function(procedure_id, type_poly_vars.len() as u32)); + + for _ in 0..type_poly_vars.len() { + concrete_type.parts.push(ConcreteTypePart::Void); // doesn't matter (I hope...) + } + p.type_table.add_builtin_procedure_type(concrete_type, &type_poly_vars); } \ No newline at end of file