From 3416da783bfc24d062c6bb01343395880e39ce5a Mon Sep 17 00:00:00 2001 From: Piotr Polesiuk Date: Wed, 8 May 2024 10:48:28 +0200 Subject: [PATCH] Early abort of pipeline in REPL (#67) Fixes #66 --- src/DblParser/Main.ml | 3 +++ src/InterpLib/Error.ml | 5 +++++ src/InterpLib/Error.mli | 5 +++++ src/TypeInference/Expr.ml | 2 +- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/DblParser/Main.ml b/src/DblParser/Main.ml index a48af9b4..86a1d0a6 100644 --- a/src/DblParser/Main.ml +++ b/src/DblParser/Main.ml @@ -18,6 +18,9 @@ let make_nowhere data = } let rec repl_seq imported () = + InterpLib.Error.wrap_repl_cont (repl_seq_main imported) () + +and repl_seq_main imported () = flush stderr; Printf.printf "> %!"; let lexbuf = Lexing.from_channel stdin in diff --git a/src/InterpLib/Error.ml b/src/InterpLib/Error.ml index 2d6d5aa5..3e0af27c 100644 --- a/src/InterpLib/Error.ml +++ b/src/InterpLib/Error.ml @@ -40,5 +40,10 @@ let assert_no_error () = if !err_counter <> 0 then raise Fatal_error +let wrap_repl_cont cont () = + let v = cont () in + assert_no_error (); + v + let reset () = err_counter := 0 diff --git a/src/InterpLib/Error.mli b/src/InterpLib/Error.mli index a3fc6981..76290d64 100644 --- a/src/InterpLib/Error.mli +++ b/src/InterpLib/Error.mli @@ -28,5 +28,10 @@ val report : ?pos:Position.t -> cls:error_class -> string -> unit of each phase. *) val assert_no_error : unit -> unit +(** Wrap REPL continuation around additional call of [assert_no_error]. This + function should be used in transforming REPL continuations (e.g. those + stored in [Surface.ERepl]) in each phase that may raise an error. *) +val wrap_repl_cont : (unit -> 'a) -> unit -> 'a + (** Reset state of reported errors. Used in REPL in case of an error. *) val reset : unit -> unit diff --git a/src/TypeInference/Expr.ml b/src/TypeInference/Expr.ml index 17a3fd12..d2841ca1 100644 --- a/src/TypeInference/Expr.ml +++ b/src/TypeInference/Expr.ml @@ -160,7 +160,7 @@ let rec check_repl_def_seq ~tcfix env ienv def_seq tp eff = in let e = { T.pos = Position.nowhere; - T.data = T.ERepl(func, tp, eff) + T.data = T.ERepl(InterpLib.Error.wrap_repl_cont func, tp, eff) } in e