Skip to content

Commit

Permalink
add second of two try transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
frabbit committed Mar 24, 2014
1 parent 0e0dbbf commit c8fc805
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion genpy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,19 @@ module Transformer = struct
let r = { a_expr with eexpr = TTry(etry.a_expr, catches)} in
let blocks = List.append etry.a_blocks blocks in
lift false blocks r
| (true, TTry(etry, catches)) -> assert false
| (true, TTry(etry, catches)) ->

let id = ae.a_next_id () in
let temp_var = to_tvar id a_expr.etype in
let temp_var_def = { a_expr with eexpr = TVar(temp_var, None) } in
let temp_local = { a_expr with eexpr = TLocal(temp_var)} in
let mk_temp_assign right = { a_expr with eexpr = TBinop(OpAssign, temp_local, right)} in
let etry = mk_temp_assign etry in
let catches = List.map (fun (v,e)-> v, mk_temp_assign e) catches in
let new_try = { a_expr with eexpr = TTry(etry, catches)} in
let block = [temp_var_def; new_try; temp_local] in
let new_block = { a_expr with eexpr = TBlock(block)} in
forward_transform new_block ae
| (_, TObjectDecl(fields)) ->
let fields = List.map (fun (name,ex) -> name, trans true [] ex) fields in
let blocks = List.flatten (List.map (fun (_,ex) -> ex.a_blocks) fields) in
Expand Down

0 comments on commit c8fc805

Please sign in to comment.