From f8830edb3ba835c03afe5fbf6bf248165a676f72 Mon Sep 17 00:00:00 2001 From: matyhtf Date: Wed, 27 Aug 2025 14:28:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/compiler.php | 2 +- cases/panel.py | 14 ++++++++++++++ src/Php/Translator.php | 17 +++++++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 cases/panel.py diff --git a/bin/compiler.php b/bin/compiler.php index a618102d..f8ffa9bc 100644 --- a/bin/compiler.php +++ b/bin/compiler.php @@ -33,7 +33,7 @@ try { $info = pathinfo($file); $cppFile = './tmp/' . $info['filename'] . '.cc'; $translator->save($code, $cppFile); - //$translator->compileFile($cppFile); + $translator->compileFile($cppFile); } catch (Error $error) { echo "Parse error: {$error->getMessage()}\n"; return; diff --git a/cases/panel.py b/cases/panel.py new file mode 100644 index 00000000..c33f009b --- /dev/null +++ b/cases/panel.py @@ -0,0 +1,14 @@ +import panel as pn + +pn.extension() + +slider = pn.widgets.IntSlider(value=5, start=1, end=10) + +def model(n): + return "⭐" * n + +interactive_model = pn.bind(model, n=slider) + +layout = pn.Column(slider, interactive_model) + +layout.servable() # For deploying as a web app \ No newline at end of file diff --git a/src/Php/Translator.php b/src/Php/Translator.php index fbdf23c8..1eaaf4a9 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -333,7 +333,7 @@ class Translator extends \PhpAot\Core\Translator $this->indentLevel++; foreach ($items as $item) { if ($item->key) { - $list[] = $this->getIndent() . '{ php::Variant(' . $this->parseIdentifier($item->key) . '), php::Variant(' . $this->parseIdentifier($item->value) . ') }'; + $list[] = $this->getIndent() . '{ ' . $this->parseIdentifier($item->key) . ', php::Variant(' . $this->parseIdentifier($item->value) . ') }'; } else { $list[] = $this->getIndent() . 'php::Variant(' . $this->parseIdentifier($item->value) . ')'; } @@ -413,22 +413,23 @@ class Translator extends \PhpAot\Core\Translator return $left . ' + ' . $right; } - private function parseFor(mixed $v) + private function parseFor(mixed $v): string { $init = $v->init; $cond = $v->cond; $loop = $v->loop; $stmts = $v->stmts; + $code = ''; - $code = 'for ('; $list_expr = []; foreach ($init as $expr) { $list_expr[] = $this->parseExpr($expr); } - $code .= implode(', ', $list_expr); - $code .= '; '; + $list_expr[] = ''; + $code .= implode(";\n" . $this->getIndent(), $list_expr); + $code .= 'for (;'; $list_cond = []; foreach ($cond as $expr) { $list_cond[] = $this->parseExpr($expr); @@ -521,7 +522,11 @@ class Translator extends \PhpAot\Core\Translator private function parseFuncCall(mixed $expr): string { $name = $this->parseIdentifier($expr->name); - return $name . '(' . $this->parseArgs($expr->args) . ')'; + if (empty($expr->args)) { + return 'php::exec("' . $name . '")'; + } else { + return 'php::exec("' . $name . '", ' . $this->parseArgs($expr->args) . ')'; + } } private function parseArgs($args): string