Skip to content

Commit

Permalink
Merge pull request HaxeFoundation#23 from frabbit/genpy
Browse files Browse the repository at this point in the history
list all cases explicit in transform1, fix minor do while problem
  • Loading branch information
Simn committed Mar 29, 2014
2 parents cb30931 + 9e2b736 commit b00ae08
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
23 changes: 20 additions & 3 deletions genpy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ module Transformer = struct
and exprs_to_func exprs name base =
let convert_return_expr (expr:texpr) =
match expr.eexpr with
| TWhile(_,_,_) ->
let ret = { expr with eexpr = TReturn (None) } in
[expr; ret]
| TFunction(f) ->
let ret = var_to_treturn_expr name f.tf_type f.tf_expr.epos in
[expr;ret]
Expand Down Expand Up @@ -622,7 +625,7 @@ module Transformer = struct
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)) ->
| (_, 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
Expand Down Expand Up @@ -673,8 +676,22 @@ module Transformer = struct
let e = trans is_value [] e in
let r = { a_expr with eexpr = TMeta(m, e.a_expr) } in
lift_expr ~blocks:e.a_blocks r
| _ ->
lift_expr ae.a_expr
| ( _, TPatMatch _ ) -> assert false
| ( _, TLocal _ ) -> lift_expr a_expr

| ( _, TConst _ ) -> lift_expr a_expr
| ( _, TTypeExpr _ ) -> lift_expr a_expr
| ( _, TEnumParameter _ ) -> lift_expr a_expr
| ( _, TUnop _ ) -> assert false
| ( true, TWhile(econd, ebody, DoWhile) ) ->
let new_expr = trans false [] a_expr in
let f = exprs_to_func (new_expr.a_blocks @ [new_expr.a_expr]) (ae.a_next_id()) ae in
lift_expr ~is_value:true ~blocks:f.a_blocks f.a_expr

| ( _, TBreak ) | ( _, TContinue ) ->
lift_expr a_expr
(*| _ ->
lift_expr ae.a_expr*)

and transform e =
to_expr (transform1 (lift_expr e))
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/Test.hx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ class Test #if swf_mark implements mt.Protect #end {
#if java
new TestJava(),
#end
#if python
new TestPython(),
#end
#if php
new TestPhp(),
#end
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/TestPython.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

package unit;

class TestPython extends Test {

public function testDoWhileAsExpression () {
var x = 1;
var z = function () return (do {
x++;
} while (x < 3));

z();

eq(3, x);
}

}

0 comments on commit b00ae08

Please sign in to comment.