diff options
Diffstat (limited to 'src/compiler.c')
-rw-r--r-- | src/compiler.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/compiler.c b/src/compiler.c index fd9e4ae..3ccb86a 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -373,14 +373,17 @@ int amal_compiler_load_file(amal_compiler_options *options, amal_program *progra return result; } -/* TODO: Verify main func has correct signature */ +/* + TODO: Instead of using amal_log_error, print error message with tokenizer to show where the error is. + This requires finding tokenizer by code reference. +*/ static CHECK_RESULT int validate_main_func(FileScopeReference *main_file_scope, LhsExpr **main_func) { const BufferView main_func_name = { "main", 4 }; LhsExpr *main_func_expr; main_func_expr = structdecl_get_field_by_name(&main_file_scope->parser->struct_decl, main_func_name); if(!main_func_expr) { - amal_log_error("main function missing from start file \"%.*s\"", main_file_scope->canonical_path.size, main_file_scope->canonical_path.data); + amal_log_error("main function missing from start file \"%.*s\". Note: the main function has to be in the file scope.", main_file_scope->canonical_path.size, main_file_scope->canonical_path.data); return AMAL_COMPILER_ERR; } *main_func = main_func_expr; @@ -400,6 +403,19 @@ static CHECK_RESULT int validate_main_func(FileScopeReference *main_file_scope, return AMAL_COMPILER_ERR; } + { + const FunctionDecl *func_decl = main_func_expr->rhs_expr->value.func_decl; + if(buffer_get_size(&func_decl->signature->parameters, FunctionParameter) != 0) { + amal_log_error("main function in start file \"%.*s\" has to be a closure with no parameters", main_file_scope->canonical_path.size, main_file_scope->canonical_path.data); + return AMAL_COMPILER_ERR; + } + + if(buffer_get_size(&func_decl->signature->return_types, FunctionReturnType) != 0) { + amal_log_error("main function in start file \"%.*s\" has to be a closure that doesn't return anything", main_file_scope->canonical_path.size, main_file_scope->canonical_path.data); + return AMAL_COMPILER_ERR; + } + } + return 0; } @@ -437,6 +453,7 @@ int amal_compiler_internal_load_file(amal_compiler *self, const char *filepath, */ LhsExpr *main_func; + /* Wait for all parsing to be done */ if(!thread_pool_join_all_tasks(&self->stage_task_thread_pool)) return -1; amal_log_info("Finished parsing all files, resolving AST"); |