diff --git a/bin/mv.php b/bin/mv.php new file mode 100755 index 00000000..0742a658 --- /dev/null +++ b/bin/mv.php @@ -0,0 +1,18 @@ +#!/usr/bin/env php +\n"; + exit(1); +} +$file = $argv[1]; +if (!file_exists($file)) { + echo "File not found: " . $file . "\n"; + exit(1); +} +$newFile = str_replace('-raw', '', $file); +$dir = dirname($newFile); +if (!is_dir($dir)) { + mkdir($dir, 0755, true); +} +rename($file, $newFile); +shell_exec('git add ' . $newFile); diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index b2f56923..1a8adace 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -61,6 +61,7 @@ class CompilerBase extends \PhpAot\Core\Translator public const string PREFIX = 'php_'; public const string OP_ISSET = 'isset'; public const string OP_EMPTY = 'empty'; + public const string OP_NOP = "if (0) {}\n"; protected string $phpxDir = '~/workspace/projects/phpx'; protected string $lang = 'PHP'; protected string $cppCompiler = 'g++'; @@ -872,7 +873,8 @@ class CompilerBase extends \PhpAot\Core\Translator { $lines = []; $inLoopTop = $this->inLoop; - foreach ($stmts as $v) { + $last = array_key_last($stmts); + foreach ($stmts as $i => $v) { $class = $v->getType(); $this->beforeStmtLines = []; $this->afterStmtLines = []; @@ -926,6 +928,9 @@ class CompilerBase extends \PhpAot\Core\Translator break; case 'Stmt_Label': $result = $this->parseLabel($v); + if ($i === $last) { + $result .= self::OP_NOP; + } break; case 'Stmt_Continue': $result = $this->parseContinue($v); diff --git a/tests/zend/jump/jump02.phpt b/tests/zend/jump/jump02.phpt new file mode 100644 index 00000000..ff83bc4b --- /dev/null +++ b/tests/zend/jump/jump02.phpt @@ -0,0 +1,16 @@ +--TEST-- +jump 02: goto forward +--FILE-- + 3) goto L2; +echo "$n: ok\n"; +$n++; +goto L1; +L2: +?> +--EXPECT-- +1: ok +2: ok +3: ok diff --git a/tests/zend/jump/jump03.phpt b/tests/zend/jump/jump03.phpt new file mode 100644 index 00000000..c43bb154 --- /dev/null +++ b/tests/zend/jump/jump03.phpt @@ -0,0 +1,18 @@ +--TEST-- +jump 03: goto inside control structures +--FILE-- + +--EXPECT-- +1: ok +2: ok