From 5209cea7012cfa3b39a5a289e65e2ea5e166d730 Mon Sep 17 00:00:00 2001 From: Escherichia Date: Thu, 21 Mar 2024 12:34:40 +0100 Subject: 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 --- compiler/Errors.ml | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'compiler/Errors.ml') 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 -- cgit v1.2.3