diff --git a/.gitignore b/.gitignore index 8a68c72a6..971a568c4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ # Local files rivetc -main.ri \ No newline at end of file +main.ri +tests/gen_out_files +tests/run_tests \ No newline at end of file diff --git a/compiler/ast/File.v b/compiler/ast/File.v index 640f829f6..381d39396 100644 --- a/compiler/ast/File.v +++ b/compiler/ast/File.v @@ -11,6 +11,7 @@ pub struct File { pub: filename string content string + mod_name string pub mut: errors int mut: @@ -51,11 +52,12 @@ pub: col int } -pub fn File.new(file string) &File { - content := read_file(file) +pub fn File.new(filename string) &File { + content := read_file(filename) return &File{ - filename: file + filename: filename content: content + mod_name: os.base(filename).all_before('.') } } @@ -63,6 +65,7 @@ pub fn File.from_memory(content string) &File { return &File{ filename: '' content: content + mod_name: '' } } diff --git a/compiler/context/mod.v b/compiler/context/mod.v index 5ce4fbdf1..573e5ac8a 100644 --- a/compiler/context/mod.v +++ b/compiler/context/mod.v @@ -36,7 +36,8 @@ pub mut: options Options report Report - files []&ast.File + root_file &ast.File = unsafe { nil } + files []&ast.File } pub fn (ctx &CContext) abort_if_errors() { @@ -46,6 +47,6 @@ pub fn (ctx &CContext) abort_if_errors() { } else { 'aborting due to ${ctx.report.errors} previous errors' } - ic_error('could not compile source code, ${reason}') + ic_error('could not compile `${ctx.root_file.mod_name}` module, ${reason}') } } diff --git a/compiler/parser/mod.v b/compiler/parser/mod.v index 587925d1d..b955b4ee9 100644 --- a/compiler/parser/mod.v +++ b/compiler/parser/mod.v @@ -28,11 +28,14 @@ pub fn new(ctx &context.CContext) &Parser { } pub fn (mut p Parser) parse() { - p.parse_file(p.ctx.options.input) + p.parse_file(p.ctx.options.input, true) } -fn (mut p Parser) parse_file(filename string) { +fn (mut p Parser) parse_file(filename string, is_root bool) { p.file = ast.File.new(filename) + if is_root { + p.ctx.root_file = p.file + } p.ctx.files << p.file p.tokenizer = tokenizer.from_file(p.ctx, p.file) diff --git a/tests/tokenizer/invalid_character.err.out b/tests/tokenizer/invalid_character.err.out index ef9f875ef..15831d10c 100644 --- a/tests/tokenizer/invalid_character.err.out +++ b/tests/tokenizer/invalid_character.err.out @@ -2,4 +2,4 @@ tests/tokenizer/invalid_character.err.ri:1:1: error: invalid character `¿` | 1 | ¿ | ^ -error: could not compile source code, aborting due to previous error \ No newline at end of file +error: could not compile `invalid_character` module, aborting due to previous error \ No newline at end of file diff --git a/tests/tokenizer/invalid_character_literal.err.out b/tests/tokenizer/invalid_character_literal.err.out index 4549d3a43..127cc75f7 100644 --- a/tests/tokenizer/invalid_character_literal.err.out +++ b/tests/tokenizer/invalid_character_literal.err.out @@ -7,4 +7,4 @@ tests/tokenizer/invalid_character_literal.err.ri:2:5: error: character literal m 2 | 'abc' | ^ = help: if you meant to write a string literal, use double quotes -error: could not compile source code, aborting due to 2 previous errors \ No newline at end of file +error: could not compile `invalid_character_literal` module, aborting due to 2 previous errors \ No newline at end of file diff --git a/tests/tokenizer/invalid_number_literal.err.out b/tests/tokenizer/invalid_number_literal.err.out index 89a0c332d..f3dc5da0e 100644 --- a/tests/tokenizer/invalid_number_literal.err.out +++ b/tests/tokenizer/invalid_number_literal.err.out @@ -60,4 +60,4 @@ tests/tokenizer/invalid_number_literal.err.ri:22:4: error: cannot use `_` at the | 22 | 123_ // fail | ^ -error: could not compile source code, aborting due to 15 previous errors \ No newline at end of file +error: could not compile `invalid_number_literal` module, aborting due to 15 previous errors \ No newline at end of file diff --git a/tests/tokenizer/invalid_string_literal.err.out b/tests/tokenizer/invalid_string_literal.err.out index 32bc3bc10..78fbc2aa6 100644 --- a/tests/tokenizer/invalid_string_literal.err.out +++ b/tests/tokenizer/invalid_string_literal.err.out @@ -2,4 +2,4 @@ tests/tokenizer/invalid_string_literal.err.ri:1:1: error: unfinished string lite | 1 | "unfinished string literal | ^ -error: could not compile source code, aborting due to previous error \ No newline at end of file +error: could not compile `invalid_string_literal` module, aborting due to previous error \ No newline at end of file diff --git a/tests/tokenizer/unterminated_multiline_comment.err.out b/tests/tokenizer/unterminated_multiline_comment.err.out index 23714d900..d70daee8c 100644 --- a/tests/tokenizer/unterminated_multiline_comment.err.out +++ b/tests/tokenizer/unterminated_multiline_comment.err.out @@ -2,4 +2,4 @@ tests/tokenizer/unterminated_multiline_comment.err.ri:2:1: error: unterminated m | 2 | unterminated multiline comment :( | ^ -error: could not compile source code, aborting due to previous error \ No newline at end of file +error: could not compile `unterminated_multiline_comment` module, aborting due to previous error \ No newline at end of file