summaryrefslogtreecommitdiff
path: root/compiler/Errors.ml
diff options
context:
space:
mode:
authorEscherichia2024-03-12 15:02:17 +0100
committerEscherichia2024-03-28 14:59:01 +0100
commita64fdc8b1be70de43afe35ff788ba3240318daac (patch)
tree779601c91a6f034ed3e53c9d139eb9b6fdab1ba2 /compiler/Errors.ml
parent65f7deb0043949049129c6a8e490d151b555fa16 (diff)
WIP Beginning working on better errors: began replacing raise (Failure) and assert by craise and cassert. Does not compile yet, still need to propagate the meta variable where it's relevant
Diffstat (limited to '')
-rw-r--r--compiler/Errors.ml27
1 files changed, 27 insertions, 0 deletions
diff --git a/compiler/Errors.ml b/compiler/Errors.ml
new file mode 100644
index 00000000..65c2cbb0
--- /dev/null
+++ b/compiler/Errors.ml
@@ -0,0 +1,27 @@
+let meta_to_string (span : Meta.span ) =
+ let file = match span.file with Virtual s | Local s -> s in
+ let loc_to_string (l : Meta.loc) : string =
+ string_of_int l.line ^ ":" ^ string_of_int l.col
+ in
+ "Source: '" ^ file ^ "', lines " ^ loc_to_string span.beg_loc ^ "-"
+ ^ loc_to_string span.end_loc
+
+let format_error_message (meta : Meta.meta) msg =
+ msg ^ ":" ^ meta_to_string meta.span
+
+exception CFailure of string
+
+
+let error_list : (Meta.meta * string) list ref = ref []
+let save_error (meta : Meta.meta ) (msg : string) = error_list := (meta, msg)::(!error_list)
+
+let craise (meta : Meta.meta) (msg : string) =
+ if !Config.fail_hard then
+ raise (Failure (format_error_message meta msg))
+ else
+ let () = save_error meta msg in
+ raise (CFailure msg)
+
+let cassert (b : bool) (meta : Meta.meta) (msg : string) =
+ if b then
+ craise meta msg \ No newline at end of file