summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlasdair Armstrong2018-07-12 16:14:13 +0100
committerAlasdair Armstrong2018-07-12 16:14:13 +0100
commitd482dcd0152b1f44faf1ad3b1ae06c029a048dab (patch)
tree0c92d89e12c7872592571558ba400eb6b0e64a00
parent79ecf8b83b06a6bd1330e1f243826cbe951a9e7d (diff)
Handle failures during interpreting better
Changes to the interpreter to better support constant folding during compilation mean it can now throw exceptions to the caller, allow the caller to handle the error, rather than simply printing an error. This broke the ARM interpreter test because exit() is handled by throwing an Exit exception in the interpreter.
-rw-r--r--src/isail.ml25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/isail.ml b/src/isail.ml
index 593167f9..4adc1cd2 100644
--- a/src/isail.ml
+++ b/src/isail.ml
@@ -127,7 +127,12 @@ let rec run () =
print_endline ("Result = " ^ Value.string_of_value v);
current_mode := Normal
| Step (out, state, _, stack) ->
- current_mode := Evaluation (eval_frame !interactive_ast frame);
+ begin
+ try
+ current_mode := Evaluation (eval_frame !interactive_ast frame)
+ with
+ | Failure str -> print_endline str; current_mode := Normal
+ end;
run ()
| Break frame ->
print_endline "Breakpoint";
@@ -147,7 +152,12 @@ let rec run_steps n =
print_endline ("Result = " ^ Value.string_of_value v);
current_mode := Normal
| Step (out, state, _, stack) ->
- current_mode := Evaluation (eval_frame !interactive_ast frame);
+ begin
+ try
+ current_mode := Evaluation (eval_frame !interactive_ast frame)
+ with
+ | Failure str -> print_endline str; current_mode := Normal
+ end;
run_steps (n - 1)
| Break frame ->
print_endline "Breakpoint";
@@ -352,9 +362,14 @@ let handle_input' input =
print_endline ("Result = " ^ Value.string_of_value v);
current_mode := Normal
| Step (out, state, _, stack) ->
- interactive_state := state;
- current_mode := Evaluation (eval_frame !interactive_ast frame);
- print_program ()
+ begin
+ try
+ interactive_state := state;
+ current_mode := Evaluation (eval_frame !interactive_ast frame);
+ print_program ()
+ with
+ | Failure str -> print_endline str; current_mode := Normal
+ end
| Break frame ->
print_endline "Breakpoint";
current_mode := Evaluation frame