From 5a9779b143f30b113c0eadc949d9473497776e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD=E4=BA=91?= <71159641+littlewhitecloud@users.noreply.github.com> Date: Wed, 21 Aug 2024 20:05:02 +0800 Subject: [PATCH] fix and update --- self_hosted/main.jou | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/self_hosted/main.jou b/self_hosted/main.jou index 8485fe60..75932da6 100644 --- a/self_hosted/main.jou +++ b/self_hosted/main.jou @@ -90,10 +90,11 @@ def parse_args(argc: int, argv: byte**) -> CommandLineArgs: return result -def find_file(files: FileState*, nfiles: int, path: byte*) -> FileState: +def find_file(files: FileState*, nfiles: int, path: byte*) -> FileState*: for i = 0; i < nfiles; i++: if strcmp(files[i].ast.path, path) == 0: - return files[i] + return &files[i] + return NULL # C:\Users\myname\.foo-bar.jou --> "_foo_bar" # Result never contains "-", so you can add "-" separated suffixes without conflicts. @@ -125,7 +126,7 @@ def get_sane_filename(path: byte*) -> byte[50]: def check_main_function(ast: AstFile*) -> bool: for i = 0; i < ast->body.nstatements; i++: s = &ast->body.statements[i] - if (s->kind == AstStatementKind::Function and strcmp(s->function.signature.name, "main") == 0): + if s->kind == AstStatementKind::Function and strcmp(s->function.signature.name, "main") == 0: return True return False @@ -222,7 +223,7 @@ class Compiler: evaluate_compile_time_if_statements_in_body(&ast.body) - if (strcmp(item.path, self->args->main_path) == 0 and check_main_function(&self->files->ast)): + if item.is_imported and check_main_function(&ast): assert item.import_location.path != NULL fail(item.import_location, "imported file should not have `main` function") @@ -484,10 +485,10 @@ def main(argc: int, argv: byte**) -> int: compiler.typecheck_stage3_all_files() mainfile = find_file(compiler.files, compiler.nfiles, args.main_path) - assert mainfile + assert mainfile != NULL - if (not check_main_function(&mainfile.ast)): - l = Location{path=mainfile->path, lineno=0} + if not check_main_function(&mainfile->ast): + l = Location{path=mainfile->ast.path, lineno=0} fail(l, "missing `main` function to execute the program") object_files = compiler.create_object_files()