diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 35c5bacf..4aeb0691 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2045,6 +2045,7 @@ class CompilerBase extends \PhpAot\Core\Translator $var = $this->parseIdentifier($node->var); $expr = $this->parseIdentifier($node->expr); $leftExprType = $node->var->getType(); + if ($this->isVarExpr($node->var)) { if (!$this->hasVar($var)) { $this->fatalError($node->var, 'Cannot assign to undefined variable'); @@ -2055,16 +2056,15 @@ class CompilerBase extends \PhpAot\Core\Translator if ($this->isArrayVar($node->var)) { $this->fatalError($node->var, 'Cannot concat string to array'); } - return $var . '.append(' . $rightExprStr . ')'; } if ($this->isAssignOpPow($op)) { - $powExpr = 'php::call(php::pow, {' . $var . ', ' . $rightExprStr . '})'; - + $powExpr = 'php::math::pow(' . $var . ', ' . $rightExprStr . ')'; return $var . ' = ' . $this->convertVarType($var, $powExpr); } return $var . ' ' . $op . ' ' . $rightExprStr; } + if ($leftExprType === self::EXPR_ARRAY_DIM_FETCH) { /** * $count[$r] -= 1; @@ -2313,8 +2313,7 @@ class CompilerBase extends \PhpAot\Core\Translator $fn = $this->getFuncPtr($name); $this->context->beforeStmtLines[] = '// Func Call: ' . $name . '()'; } else { - $tmpVar = $this->genTmpVarName(); - $this->addLocalVar($tmpVar, self::TYPE_VAR); + $tmpVar = $this->addTmpVar(self::TYPE_VAR); $this->context->beforeStmtLines[] = $tmpVar . ' = ' . $this->parseExpr($expr->name) . ';'; $placeHolder = $fn = $tmpVar; $name = ''; @@ -2633,7 +2632,7 @@ class CompilerBase extends \PhpAot\Core\Translator $left = $this->parseIdentifier($expr->left); $right = $this->parseIdentifier($expr->right); - return 'php::pow(' . $left . ', ' . $right . ')'; + return 'php::math::pow(' . $left . ', ' . $right . ')'; } protected function parsePreDec(Node\Expr\PreDec $expr): string diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index 44e9c9b5..be16620b 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -44,6 +44,9 @@ trait FuncCallOptimizer if ($name === 'abs') { return 'php::math::abs(' . $getArg(0) . ')'; } + if ($name === 'pow') { + return 'php::math::pow(' . $getArg(0) . ', ' . $getArg(1) . ')'; + } if ($name === 'ord') { return 'php::fn::ord(' . $getArg(0) . ')'; } diff --git a/tests/aot/pow-assign-op.phpt b/tests/aot/pow-assign-op.phpt index ce6a0b13..5efab255 100644 --- a/tests/aot/pow-assign-op.phpt +++ b/tests/aot/pow-assign-op.phpt @@ -5,6 +5,9 @@ strlen $a = 2; $a **= 10; var_dump($a); + +$d = pow(3, 4); +assert($d == 81); ?> --EXPECT-- int(1024)