From 5af4ef88acb68b66d38846b398e1e34845cccfbf Mon Sep 17 00:00:00 2001 From: Josh Wolfe Date: Thu, 3 Dec 2015 10:56:17 -0700 Subject: local variables work --- src/analyze.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index dc7af6b809..c0ce2f7e8e 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -115,12 +115,7 @@ static void resolve_function_proto(CodeGen *g, AstNode *node, FnTableEntry *fn_t for (int i = 0; i < node->data.fn_proto.params.length; i += 1) { AstNode *child = node->data.fn_proto.params.at(i); assert(child->type == NodeTypeParamDecl); - - Buf *param_name = &child->data.param_decl.name; - SymbolTableEntry *symbol_entry = allocate(1); - symbol_entry->type_entry = resolve_type(g, child->data.param_decl.type); - symbol_entry->param_index = i; - fn_table_entry->symbol_table.put(param_name, symbol_entry); + resolve_type(g, child->data.param_decl.type); } resolve_type(g, node->data.fn_proto.return_type); @@ -171,7 +166,6 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import, fn_table_entry->is_extern = true; fn_table_entry->calling_convention = LLVMCCallConv; fn_table_entry->import_entry = import; - fn_table_entry->symbol_table.init(8); fn_table_entry->label_table.init(8); resolve_function_proto(g, fn_proto, fn_table_entry); @@ -222,7 +216,6 @@ static void preview_function_declarations(CodeGen *g, ImportTableEntry *import, fn_table_entry->fn_def_node = node; fn_table_entry->internal_linkage = is_internal; fn_table_entry->calling_convention = is_internal ? LLVMFastCallConv : LLVMCCallConv; - fn_table_entry->symbol_table.init(8); fn_table_entry->label_table.init(8); g->fn_protos.append(fn_table_entry); @@ -363,7 +356,7 @@ static BlockContext *new_block_context(AstNode *node, BlockContext *parent) { return context; } -static LocalVariableTableEntry *find_local_variable(BlockContext *context, Buf *name) { +LocalVariableTableEntry *find_local_variable(BlockContext *context, Buf *name) { while (true) { auto entry = context->variable_table.maybe_get(name); if (entry != nullptr) @@ -432,6 +425,10 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import, TypeTableEntry *implicit_type = variable_declaration->expr != nullptr ? analyze_expression(g, import, context, explicit_type, variable_declaration->expr) : nullptr; + if (implicit_type == nullptr) { + add_node_error(g, node, buf_sprintf("initial values are required for variable declaration.")); + } + TypeTableEntry *type = explicit_type != nullptr ? explicit_type : implicit_type; assert(type != nullptr); // should have been caught by the parser @@ -736,6 +733,7 @@ static void analyze_top_level_declaration(CodeGen *g, ImportTableEntry *import, node->codegen_node = allocate(1); node->codegen_node->data.fn_def_node.implicit_return_type = block_return_type; + node->codegen_node->data.fn_def_node.block_context = context; } break; -- cgit v1.2.3