Skip to content

Commit

Permalink
fix and update
Browse files Browse the repository at this point in the history
  • Loading branch information
littlewhitecloud authored Aug 21, 2024
1 parent d05da70 commit 5a9779b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions self_hosted/main.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 5a9779b

Please sign in to comment.