2
0
Эх сурвалжийг харах

fixed assign operator on arrays returned by functions

Franco Ponticelli 17 жил өмнө
parent
commit
b081090f4c
2 өөрчлөгдсөн 21 нэмэгдсэн , 31 устгасан
  1. 15 5
      genphp.ml
  2. 6 26
      std/php/Boot.hx

+ 15 - 5
genphp.ml

@@ -102,7 +102,7 @@ let s_expr_name e =
 
 let s_type_name t =
 	s_type (print_context()) t
-
+	
 let rec is_uncertain_type t =
 	match follow t with
 	| TInst (c, _) -> c.cl_interface
@@ -872,16 +872,26 @@ and gen_expr ctx e =
 			(match e.eexpr with
 			| TArray(te1, te2) ->
 				gen_value ctx te1;
-				spr ctx "[";
+				spr ctx "->__a[";
 				gen_value ctx te2;
 				spr ctx "]";
 			| _ ->
 				gen_field_op ctx e1;) in
 		(match op with
 		| Ast.OpAssign ->
-			leftside e1;
-			spr ctx " = ";
-			gen_value_op ctx e2;
+			(match e1.eexpr with
+			| TArray(te1, te2) when (match te1.eexpr with TCall _ -> true | _ -> false) ->
+				spr ctx "_hx_array_assign(";
+				gen_value ctx te1;
+				spr ctx ", ";
+				gen_value ctx te2;
+				spr ctx ", ";
+				gen_value_op ctx e2;
+				spr ctx ")";
+			| _ ->
+				gen_field_op ctx e1;
+				spr ctx " = ";
+				gen_value_op ctx e2;)
 		| Ast.OpAssignOp(Ast.OpAdd) when (is_string_expr e1 || is_string_expr e2) ->
 			leftside e1;
 			spr ctx " .= ";

+ 6 - 26
std/php/Boot.hx

@@ -82,15 +82,7 @@ class _hx_array implements ArrayAccess {
 	function reverse() {
 		$this->__a = array_reverse($this->__a, false);
 	}
-/*
-	function set($pos, $v) {
-		if($this->length <= $pos) {
-			$this->__a = array_merge($this->__a, array_fill(0, $pos+1-$this->length, null));
-			$this->length = $pos+1;
-		}
-		return $this->__a[$pos] = $v;
-	}
-*/
+
 	function shift() {
 		$r = array_shift($this->__a);
 		$this->length = count($this->__a);
@@ -105,23 +97,7 @@ class _hx_array implements ArrayAccess {
 	}
 
 	function sort($f) {
-		$i = 0;
-		while($i < $this->length) {
-			$swap = false;
-			$j = 0;
-			$max = $this->length - $i - 1;
-			while($j < $max) {
-				if(call_user_func($f, $this->__a[$j], $this->__a[$j+1]) > 0 ) {
-					$tmp = $this->__a[$j+1];
-					$this->__a[$j+1] = $this->__a[$j];
-					$this->__a[$j] = $tmp;
-					$swap = true;
-				}
-				$j += 1;
-			}
-			if(!$swap) break;
-			$i += 1;
-		}
+		usort($this->__a, $f);
 	}
 
 	function splice($pos, $len) {
@@ -171,6 +147,10 @@ function _hx_array_get($a, $pos) {
 	return $a[$pos];
 }
 
+function _hx_array_assign($a, $i, $v) {
+	return $a[$i] = $v;
+}
+
 function _hx_char_code_at($s, $pos) {
 	if(empty($s) || $pos >= strlen($s)) return null;
 	return ord($s{$pos});