소스 검색

- php : fixed bug in overridden dynamic functions
- php : fixed round to be consistent with other platforms
- php : fixed bug concatenating two dynamic variables
- php : php.Lib.rethrow now works as expected

Franco Ponticelli 16 년 전
부모
커밋
f8e03f23b0
6개의 변경된 파일48개의 추가작업 그리고 72개의 파일을 삭제
  1. 6 0
      doc/CHANGES.txt
  2. 24 67
      genphp.ml
  3. 1 1
      std/flash9/display/ShaderJob.hx
  4. 8 0
      std/php/Boot.hx
  5. 7 2
      std/php/Lib.hx
  6. 2 2
      std/php/PhpMath__.hx

+ 6 - 0
doc/CHANGES.txt

@@ -32,6 +32,12 @@ TODO :
 	cpp : added CPP platform
 	all : added 'using' syntax
 	neko : added 'domains' optional param to ThreadRemotingServer to answer policy-file-request
+	php : fixed php.db.Mysql so that getResult is consistent with Neko behavior
+	php : fixed __toString for anonymouse objects
+	php : fixed bug in overridden dynamic functions
+	php : fixed round to be consistent with other platforms
+	php : fixed bug concatenating two dynamic variables
+	php : php.Lib.rethrow now works as expected
 
 2009-03-22: 2.03
 	optimized Type.enumEq : use index instead of tag comparison for neko/flash9/php

+ 24 - 67
genphp.ml

@@ -1,40 +1,12 @@
 (*
-TODO
+TODO:
 
-var a:Dynamic = { a:"aaaa", b:"bbb" };
-trace(a.a + a.b);
-
-in flash:   aaaabbb
-in php:   0
-
-
-
-- check for static method name clashes
 - debug version
 - runtime check for undefined fields
 OPTIMIZATION
 - replace eval for statements with functions/inlines
 - replace closures (eval) with functions
 
-RETHROW:
-
-        try 
-        {
-            app.run();
-            
-        } catch(e:Dynamic){
-            
-            if (app.debug) 
-            {
-                // fail to catch the exception for debugging
-                throw(untyped __php__("$__e__"));
-                
-            } else {
-                Lib.print("Sorry the site has died. Please kick us in the head.");
-            }
-        }
-
-*)
 (*
  *  haXe/PHP Compiler
  *  Copyright (c)2008 Franco Ponticelli
@@ -217,14 +189,14 @@ haxe reserved words that match php ones: break, case, class, continue, default,
  *)
 (* PHP only (for future use): cfunction, old_function *)
 	match n with
-	| "and" | "or" | "xor" | "__FILE__" | "exception" (* PHP 5 *) | "__LINE__" | "array"
+	| "and" | "or" | "xor" | "__FILE__" | "exception" | "__LINE__" | "array"
 	| "as" | "const" | "declare" | "die" | "echo"| "elseif" | "empty"
 	| "enddeclare" | "endfor" | "endforeach" | "endif" | "endswitch"
 	| "endwhile" | "eval" | "exit" | "foreach"| "global" | "include"
 	| "include_once" | "isset" | "list" | "print" | "require" | "require_once"
-	| "unset" | "use" | "__FUNCTION__" | "__CLASS__" | "__METHOD__" | "final" (* PHP 5 *)
-	| "php_user_filter" (* PHP 5 *) | "protected" (* PHP 5 *) | "abstract" (* PHP 5 *)
-	| "clone" (* PHP 5 *) -> suf ^ n
+	| "unset" | "use" | "__FUNCTION__" | "__CLASS__" | "__METHOD__" | "final" 
+	| "php_user_filter" | "protected" | "abstract" 
+	| "clone" -> suf ^ n
 	| _ -> n
 
 let write_resource dir name data =
@@ -437,23 +409,6 @@ let is_dynamic_method f =
 	(match f.cf_set with
 		| MethodAccess true -> true
 		| _ -> false)
-(*
-	match follow f.cf_type with
-	| TFun _ when f.cf_expr = None -> true
-	| _ ->
-		(match f.cf_expr with
-		| Some { eexpr = TFunction fd } -> f.cf_set = MethodAccess true 
-		| _ -> false)
-		*)
-(*
-let is_dynamic_method f =
-	match follow f.cf_type with
-	| TFun _ when f.cf_expr = None -> true
-	| _ ->
-		(match f.cf_expr with
-		| Some { eexpr = TFunction fd } -> f.cf_set = NormalAccess 
-		| _ -> false)
-*)
 let fun_block ctx f p =
 	let e = (match f.tf_expr with { eexpr = TBlock [{ eexpr = TBlock _ } as e] } -> e | e -> e) in
 	let e = List.fold_left (fun e (a,c,t) ->
@@ -953,14 +908,17 @@ and gen_expr ctx e =
 				gen_value_op ctx e2;
 				spr ctx ")";
 			| _ ->
-(*
-				gen_field_op ctx e1;
-*)
-
 				leftsidef e1;
 				spr ctx " = ";
-				
 				gen_value_op ctx e2;)
+		| Ast.OpAssignOp(Ast.OpAdd) when (is_uncertain_expr e1 && is_uncertain_expr e2) ->
+			leftside e1;
+			spr ctx " = ";
+			spr ctx "_hx_add(";
+			gen_value_op ctx e1;
+			spr ctx ", ";
+			gen_value_op ctx e2;
+			spr ctx ")";
 		| Ast.OpAssignOp(Ast.OpAdd) when (is_string_expr e1 || is_string_expr e2) ->
 			leftside e1;
 			spr ctx " .= ";
@@ -981,6 +939,12 @@ and gen_expr ctx e =
 			leftsidec e1;
 			print ctx " %s " (Ast.s_binop op);
 			gen_value_op ctx e2;
+		| Ast.OpAdd when (is_uncertain_expr e1 && is_uncertain_expr e2) ->
+			spr ctx "_hx_add(";
+			gen_value_op ctx e1;
+			spr ctx ", ";
+			gen_value_op ctx e2;
+			spr ctx ")";
 		| Ast.OpAdd when (is_string_expr e1 || is_string_expr e2) ->
 			gen_value_op ctx e1;
 			spr ctx " . ";
@@ -1157,7 +1121,7 @@ and gen_expr ctx e =
 					let name = f.cf_name in
 					match f.cf_expr with
 					| Some { eexpr = TFunction fd } ->
-						print ctx "$this->%s = array(new _hx_lambda(array(), $this, array(" name;
+						print ctx "if(!isset($this->%s)) $this->%s = array(new _hx_lambda(array(), $this, array(" name name;
 						let cargs = ref 0 in
 						concat ctx "," (fun (arg,o,t) ->
 							let arg = define_local ctx arg in
@@ -1177,7 +1141,10 @@ and gen_expr ctx e =
 				) ctx.dynamic_methods;
 				if Codegen.constructor_side_effects e then begin
 					print ctx "if( !%s::$skip_constructor ) {" (s_path ctx (["php"],"Boot") false e.epos);
-					(fun() -> print ctx "}")
+					(fun() -> print ctx "}";
+					
+					
+					)
 				end else
 					(fun() -> ());
 			end) in
@@ -1206,16 +1173,8 @@ and gen_expr ctx e =
 			gen_string_static_call ctx s ef el
 		| TField (ef,s) when is_string_expr ef ->
 			gen_string_call ctx s ef el
-(*		| TField (ef,s) when is_anonym_expr ef ->
-			if could_be_string_call s then begin
-				gen_uncertain_string_call ctx s ef el
-			end else
-				gen_call ctx ec el
-*)
 		| TField (ef,s) when is_anonym_expr ef && could_be_string_call s ->
 			gen_uncertain_string_call ctx s ef el
-(*		| TCall _ ->
-			gen_call ctx ec el *)
 		| _ ->
 			gen_call ctx ec el);
 	| TArrayDecl el ->
@@ -1603,7 +1562,6 @@ let generate_field ctx static f =
 		spr ctx (rights ^ " ");
 		(match f.cf_set with
 		| MethodAccess true ->
-(*		| NormalAccess when (match fd.tf_expr.eexpr with | TBlock _ -> true | _ -> false) -> *)
 			gen_dynamic_function ctx static (s_ident f.cf_name) fd f.cf_params p
 		| _ ->
 			gen_function ctx (s_ident f.cf_name) fd f.cf_params p
@@ -1666,7 +1624,6 @@ let generate_static_field_assign ctx path f =
 			| TFunction fd ->
 				(match f.cf_set with
 				| MethodAccess true ->
-(*				| NormalAccess when (match fd.tf_expr.eexpr with | TBlock _ -> true | _ -> false) -> *)
 					newline ctx;
 					print ctx "%s::$%s = " (s_path ctx path false p) (s_ident f.cf_name);
 					gen_value ctx e

+ 1 - 1
std/flash9/display/ShaderJob.hx

@@ -10,5 +10,5 @@ extern class ShaderJob extends flash.events.EventDispatcher {
 
 	function new(?shader : flash.display.Shader, ?target : Dynamic, ?width : Int, ?height : Int) : Void;
 	function cancel() : Void;
-	function start() : Void;
+	function start(?waitForCompletion : Bool) : Void;
 }

+ 8 - 0
std/php/Boot.hx

@@ -7,6 +7,14 @@ class Boot {
 	static var skip_constructor = false;
 	static function __init__() : Void {
 		untyped __php__("
+function _hx_add($a, $b) {
+	if(is_numeric($a) && is_numeric($b)) {
+		return $a + $b;
+	} else {
+		return $a . $b;
+	}
+}
+		
 function _hx_anonymous($p = array()) {
 	$o = new _hx_anonymous();
 	foreach($p as $k => $v)

+ 7 - 2
std/php/Lib.hx

@@ -65,8 +65,13 @@ class Lib {
 	/**
 		For neko compatibility only.
 	**/
-	public static function rethrow( e : Dynamic ) {
-		throw e;
+	public inline static function rethrow( e : Dynamic ) {
+		untyped __php__("if(isset($__e__)) throw $__e__");
+		if(Std.is(e, untyped __php__("Exception"))) {
+			var __rtex__ = e;
+			untyped __php__("throw $__rtex__");
+		}
+		else throw e;
 	}
 
 	static function appendType(o : Dynamic, path : Array<String>, t : Dynamic) {

+ 2 - 2
std/php/PhpMath__.hx

@@ -41,9 +41,9 @@ class PhpMath__
 	public static function exp(v)      { return untyped __call__("exp", v); }
 	public static function log(v)      { return untyped __call__("log", v); }
 	public static function sqrt(v)     { return untyped __call__("sqrt", v); }
-	public static function round(v)    { return untyped __call__("round", v); }
+	public static function round(v)    { return untyped __call__("(int) floor", v + 0.5); }
 	public static function floor(v)    { return untyped __call__("(int) floor", v); }
-	public static function ceil(v)     { return untyped __call__("ceil", v); }
+	public static function ceil(v)     { return untyped __call__("(int) ceil", v); }
 	public static function atan(v)     { return untyped __call__("atan", v); }
 	public static function asin(v)     { return untyped __call__("asin", v); }
 	public static function acos(v)     { return untyped __call__("acos", v); }