diff options
author | Escherichia | 2024-03-21 12:34:40 +0100 |
---|---|---|
committer | Escherichia | 2024-03-28 15:24:42 +0100 |
commit | 5209cea7012cfa3b39a5a289e65e2ea5e166d730 (patch) | |
tree | b9f159ccc9dad0d24bd2dd619e77909b78578c20 /compiler/Errors.ml | |
parent | 8f89bd8df9f382284eabb5a2020a2fa634f92fac (diff) |
WIP: translate.ml and extract.ml do not compile. Some assert left to do and we need to see how translate_crate can give meta to the functions it calls
Diffstat (limited to '')
-rw-r--r-- | compiler/Errors.ml | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/compiler/Errors.ml b/compiler/Errors.ml index 65c2cbb0..8fb65bc1 100644 --- a/compiler/Errors.ml +++ b/compiler/Errors.ml @@ -12,16 +12,31 @@ let format_error_message (meta : Meta.meta) msg = 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 error_list : (Meta.meta option * string) list ref = ref [] +let save_error (meta : Meta.meta option) (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 + let () = save_error (Some 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 + craise meta msg + +let craise_opt_meta (meta : Meta.meta option) (msg : string) = + match meta with + | Some m -> craise m msg + | None -> + let () = save_error (None) msg in + raise (CFailure msg) + +let cassert_opt_meta (b : bool) (meta : Meta.meta option) (msg : string) = + match meta with + | Some m -> cassert b m msg + | None -> + if b then + let () = save_error (None) msg in + raise (CFailure msg)
\ No newline at end of file |