Skip to content

Commit

Permalink
Add flag to stop compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorious3 committed Apr 13, 2024
1 parent 0205e96 commit 71e36da
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/errors.pr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import compiler
import map
import parser
import progress
import toolchain

export var error_count = 0
export var suppress_errors = false
Expand Down Expand Up @@ -120,6 +121,10 @@ export def errorn(node: &parser::Node, msg: String...) {
message = message
] !Diagnostic
error_handler(diagnostic)

if toolchain::exit_on_first_error {
abort("Compilation failure\n")
}
}

export def errort(token: lexer::Token, state: &parser::ParseState, msg: String...) {
Expand Down Expand Up @@ -150,5 +155,9 @@ export def errort(token: lexer::Token, state: &parser::ParseState, msg: String..
] !Diagnostic
error_handler(diagnostic)

if toolchain::exit_on_first_error {
abort("Compilation failure\n")
}

state.has_error = true
}
2 changes: 2 additions & 0 deletions src/main.pr
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ let options = [
.set_help("Compile without importing std")),
(option(*toolchain::trace_consteval, "--trace-consteval")
.set_help("Trace code generated for consteval")),
(option(*toolchain::exit_on_first_error, "--exit-on-first-error")
.set_help("Abort compilation on first error")),
(option(*filename, "compile")
.set_help("File to compile")
.set_metavar("FILE"))
Expand Down
1 change: 1 addition & 0 deletions src/toolchain.pr
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export var print_typed_ast = false
export var emit_only_functions = false
export var emit_all_modules = false
export var continue_on_output = false
export var exit_on_first_error = false
// This flag controls emitting debug information to llvm
export var debug_sym = false
export var main_file_name: Str
Expand Down

0 comments on commit 71e36da

Please sign in to comment.