diff options
author | Son Ho | 2022-01-28 22:22:56 +0100 |
---|---|---|
committer | Son Ho | 2022-01-28 22:22:56 +0100 |
commit | 04b05665f70ebb45b8d29adbd0529df197d8d5f3 (patch) | |
tree | 2a8a2b0c646de944c73bc829fbbbf8941de5a85f /src | |
parent | 2d40d81b4b9fde44fd924bad5a44b7392a1c9f1e (diff) |
Implement unfold_monadic_let_bindings
Diffstat (limited to 'src')
-rw-r--r-- | src/PureMicroPasses.ml | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/src/PureMicroPasses.ml b/src/PureMicroPasses.ml index 2a7293c8..7e74835a 100644 --- a/src/PureMicroPasses.ml +++ b/src/PureMicroPasses.ml @@ -678,34 +678,30 @@ let unit_vars_to_unit (def : fun_def) : fun_def = (** Unfold the monadic let-bindings to explicit matches. *) let unfold_monadic_let_bindings (ctx : trans_ctx) (def : fun_def) : fun_def = - def -(* (* It is a very simple map *) - let obj = - object - inherit [_] map_expression as super - - method! visit_Let env monadic lv re e = - if not monadic then super#visit_Let env monadic lv re e - else - let fail_pat = mk_result_fail_lvalue lv.ty in - let fail_value = mk_result_fail_rvalue .. in - let fail_branch = {pat=fail_pat; branch=Value(fail_value,None)} in - let success_pat = mk_result_return_lvalue lv in - let success_branch = {pat=success_pat; branch=e} in - let switch_body = - Match [ fail_branch; success_branch - - ] - in - let e = Switch (lv, switch_body) in - self#visit_expression e - - end - in - (* Update the body *) - let body = obj#visit_expression () def.body in - (* Return *) - { def with body}*) + (* It is a very simple map *) + let obj = + object (self) + inherit [_] map_expression as super + + method! visit_Let env monadic lv re e = + if not monadic then super#visit_Let env monadic lv re e + else + let fail_pat = mk_result_fail_lvalue lv.ty in + let fail_value = mk_result_fail_rvalue e.ty in + let fail_branch = + { pat = fail_pat; branch = mk_value_expression fail_value None } + in + let success_pat = mk_result_return_lvalue lv in + let success_branch = { pat = success_pat; branch = e } in + let switch_body = Match [ fail_branch; success_branch ] in + let e = Switch (re, switch_body) in + self#visit_expression env e + end + in + (* Update the body *) + let body = obj#visit_texpression () def.body in + (* Return *) + { def with body } (** Apply all the micro-passes to a function. |