summaryrefslogtreecommitdiff
path: root/src/rewriter.ml
diff options
context:
space:
mode:
authorThomas Bauereiss2017-12-19 11:53:23 +0000
committerThomas Bauereiss2017-12-19 12:03:48 +0000
commitb938fd99a9f16d4bb2ef1c483574a2850aa6e640 (patch)
tree0e160767d304677005c06222a28a574792257f4f /src/rewriter.ml
parent5c0b807f89b99b1f7adb2a2f6aebdea52a8bdd80 (diff)
Support user-defined exceptions in Lem shallow embedding
The type-checker already supports a user-defined "exception" type that can be used in throw and try-catch expressions. This patch adds support for that to the Lem shallow embedding by adapting the existing exception mechanisms of the state and prompt monads. User-defined exceptions are distinguished from builtin exception cases. For example, the state monad uses type ex 'e = | Exit | Assert of string | Throw of 'e to distinguish between calls to "exit", failed assertions, and user-defined exceptions, respectively. Early return is also handled using the exception mechanism, by lifting to a monad with "either 'r exception" as the exception type, where 'r is the expected return type and "exception" is the user-defined exception type.
Diffstat (limited to 'src/rewriter.ml')
-rw-r--r--src/rewriter.ml5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/rewriter.ml b/src/rewriter.ml
index 88fb17a5..31bcb577 100644
--- a/src/rewriter.ml
+++ b/src/rewriter.ml
@@ -130,12 +130,11 @@ let fix_eff_exp (E_aux (e,((l,_) as annot))) = match snd annot with
| E_record_update(e,fexps) ->
union_effects (effect_of e) (effect_of_fexps fexps)
| E_field (e,_) -> effect_of e
- | E_case (e,pexps) ->
+ | E_case (e,pexps) | E_try (e,pexps) ->
List.fold_left union_effects (effect_of e) (List.map effect_of_pexp pexps)
| E_let (lb,e) -> union_effects (effect_of_lb lb) (effect_of e)
| E_assign (lexp,e) -> union_effects (effect_of_lexp lexp) (effect_of e)
- | E_exit e -> union_effects eff (effect_of e)
- | E_return e -> union_effects eff (effect_of e)
+ | E_exit e | E_return e | E_throw e -> union_effects eff (effect_of e)
| E_sizeof _ | E_sizeof_internal _ | E_constraint _ -> no_effect
| E_assert (c,m) -> union_effects eff (union_eff_exps [c; m])
| E_comment _ | E_comment_struc _ -> no_effect