Skip to content

Commit

Permalink
Merge pull request HaxeFoundation#17 from frabbit/genpy
Browse files Browse the repository at this point in the history
more transformations
  • Loading branch information
Simn committed Mar 24, 2014
2 parents 5ef009c + c8fc805 commit 7d4daea
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions genpy.ml
Expand Up @@ -607,20 +607,51 @@ module Transformer = struct
let x = trans true [] x in
let r = { a_expr with eexpr = TThrow(x.a_expr)} in
lift false x.a_blocks r
| (_, TNew(c, tp, params)) -> assert false
| (_, TNew(c, tp, params)) ->
let params = List.map (trans true []) params in
let blocks = List.flatten (List.map (fun (p) -> p.a_blocks) params) in
let params = List.map (fun (p) -> p.a_expr) params in
let e = { a_expr with eexpr = TNew(c, tp, params) } in
lift false blocks e
| (_, TCall({ eexpr = TLocal({v_name = "__python_for__" })} as x, [param])) ->
let param = trans false [] param in
let call = { a_expr with eexpr = TCall(x, [param.a_expr])} in
lift_expr call
| (_, TCall(e, params)) -> assert false
| (_, TCall(e, params)) ->
let e = trans true [] e in
let params = List.map (trans true []) params in
let blocks = List.flatten (List.map (fun (p) -> p.a_blocks) params) in
let params = List.map (fun (p) -> p.a_expr) params in
let e = { a_expr with eexpr = TCall(e.a_expr, params) } in
lift_expr ~blocks:blocks e

| (true, TArray(e1, e2)) ->
let e1 = trans true [] e1 in
let e2 = trans true [] e2 in
let r = { a_expr with eexpr = TArray(e1.a_expr, e2.a_expr)} in
let blocks = List.append e1.a_blocks e2.a_blocks in
lift_expr ~blocks:blocks r
| (false, TTry(etry, catches)) -> assert false
| (true, TTry(etry, catches)) -> assert false
| (false, TTry(etry, catches)) ->
let etry = trans false [] etry in
let catches = List.map (fun(v,e) -> v, trans false [] e) catches in
let blocks = List.flatten (List.map (fun (_,e) -> e.a_blocks) catches) in
let catches = List.map (fun(v,e) -> v, e.a_expr) catches in
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)) ->

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 7d4daea

Please sign in to comment.