From e86151e20f2a16ded81ee32ea9f9339e98b127f8 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Sat, 1 Nov 2025 17:01:14 +0900 Subject: [PATCH] =?UTF-8?q?llvm(phis):=20=E9=9D=99=E7=9A=84Box=20self=20?= =?UTF-8?q?=E5=85=88=E9=A0=AD=E8=A6=8F=E7=B4=84=E3=82=92=20phi=20=E3=81=AB?= =?UTF-8?q?=E6=AE=B5=E9=9A=8E=E5=B0=8E=E5=85=A5=E3=81=97=E3=80=81=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E6=A4=9C=E8=A8=BC=E3=82=B9=E3=83=A2=E3=83=BC=E3=82=AF?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0\n\n-=20lang/src/llvm=5Fir/instructi?= =?UTF-8?q?ons/phi.hako:=20lower=5F*=20=E7=BE=A4=E3=81=AB=20self=20?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=EF=BC=88=E5=91=BC=E3=81=B3=E5=87=BA?= =?UTF-8?q?=E3=81=97=E5=81=B4=E3=81=AF=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF?= =?UTF-8?q?=E3=83=B3=E3=82=B9=E7=B5=8C=E7=94=B1=E3=81=A7=E4=BA=92=E6=8F=9B?= =?UTF-8?q?=EF=BC=89\n-=20smokes:=20quick/core/phi/self=5Fparam=5Fphi=5Fvm?= =?UTF-8?q?.sh=20=E3=81=A7=20JSON=20=E7=94=9F=E6=88=90=E3=82=92=E7=A2=BA?= =?UTF-8?q?=E8=AA=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lang/src/llvm_ir/instructions/phi.hako | 26 ++++++++--------- .../quick/core/phi/self_param_phi_vm.sh | 29 +++++++++++++++++++ 2 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 tools/smokes/v2/profiles/quick/core/phi/self_param_phi_vm.sh diff --git a/lang/src/llvm_ir/instructions/phi.hako b/lang/src/llvm_ir/instructions/phi.hako index d809b0f7..54d8c51b 100644 --- a/lang/src/llvm_ir/instructions/phi.hako +++ b/lang/src/llvm_ir/instructions/phi.hako @@ -19,7 +19,7 @@ static box LLVMPhiInstructionBox { // Returns: // JSON文字列: {"op":"phi","dst":5,"incoming":[...]} // - lower_phi(dst, incoming_list) { + lower_phi(self, dst, incoming_list) { // 空チェック: incoming が空の場合は 0 定数を返す // Python: phi.py 34-37行の動作と同じ if incoming_list == null { @@ -41,7 +41,7 @@ static box LLVMPhiInstructionBox { // 空のPHI: 0定数にフォールバック // Python: phi.py 34-37行 - _phi_empty_fallback(dst) { + _phi_empty_fallback(self, dst) { // No incoming edges - use zero constant return "{\"op\":\"const\",\"dst\":" + dst + ",\"value\":{\"type\":\"i64\",\"value\":0}}" } @@ -54,7 +54,7 @@ static box LLVMPhiInstructionBox { // Returns: // JSON配列文字列: [{"value":1,"block":1},{"value":2,"block":2}] // - _build_incoming_array(incoming_list) { + _build_incoming_array(self, incoming_list) { local result = "[" local first = 1 @@ -86,8 +86,8 @@ static box LLVMPhiInstructionBox { } // デバッグ用 - 生成された命令の確認 - debug_phi(dst, incoming_list) { - local json = me.lower_phi(dst, incoming_list) + debug_phi(self, dst, incoming_list) { + local json = me.lower_phi(self, dst, incoming_list) print("Generated PHI instruction: " + json) return json } @@ -95,33 +95,33 @@ static box LLVMPhiInstructionBox { // Stage 2 プレースホルダー: Block End Values管理(将来実装) // Python: phi.py 69-79行の block_end_values スナップショット処理 // 注: Hakorune版では不要(C++バックエンドが処理) - lower_phi_with_snapshot(dst, incoming_list, block_end_values) { + lower_phi_with_snapshot(self, dst, incoming_list, block_end_values) { // 現時点では基本版と同じ動作 - return me.lower_phi(dst, incoming_list) + return me.lower_phi(self, incoming_list) } // Stage 3 プレースホルダー: 型変換処理(将来実装) // Python: phi.py 84-103行の型変換処理 // 注: Hakorune版では不要(C++バックエンドが処理) - lower_phi_with_type_info(dst, incoming_list, type_info) { + lower_phi_with_type_info(self, dst, incoming_list, type_info) { // 現時点では基本版と同じ動作 - return me.lower_phi(dst, incoming_list) + return me.lower_phi(self, incoming_list) } // Stage 4 プレースホルダー: Strict Mode(将来実装) // Python: phi.py 118-121行の NYASH_LLVM_PHI_STRICT チェック // 注: C++バックエンドで実装予定 - lower_phi_strict(dst, incoming_list, strict_mode) { + lower_phi_strict(self, dst, incoming_list, strict_mode) { // 現時点では基本版と同じ動作 - return me.lower_phi(dst, incoming_list) + return me.lower_phi(self, incoming_list) } // Stage 5 プレースホルダー: 文字列性伝播(将来実装) // Python: phi.py 131-142行の resolver.is_stringish() 処理 // 注: C++バックエンドで実装予定 - lower_phi_with_string_propagation(dst, incoming_list, resolver) { + lower_phi_with_string_propagation(self, dst, incoming_list, resolver) { // 現時点では基本版と同じ動作 - return me.lower_phi(dst, incoming_list) + return me.lower_phi(self, incoming_list) } // ヘルパー: incoming要素の検証(デバッグ用) diff --git a/tools/smokes/v2/profiles/quick/core/phi/self_param_phi_vm.sh b/tools/smokes/v2/profiles/quick/core/phi/self_param_phi_vm.sh new file mode 100644 index 00000000..2dcd8e53 --- /dev/null +++ b/tools/smokes/v2/profiles/quick/core/phi/self_param_phi_vm.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# Verify LLVMPhiInstructionBox.lower_phi requires self (implicit receiver) and returns JSON + +source "$(dirname "$0")/../../../lib/test_runner.sh" +source "$(dirname "$0")/../../../lib/result_checker.sh" + +require_env || exit 2 +preflight_plugins || exit 2 + +test_self_param_phi() { + local src=' +using "lang/src/llvm_ir/instructions/phi.hako" as PhiInst +box Main { + static method main() { + local incoming = new ArrayBox() + local item = new MapBox(); item.set("value", 1); item.set("block", 0); incoming.push(item) + local phi = new PhiInst.LLVMPhiInstructionBox().lower_phi(5, incoming) + # 判定: 生成文字列に op":"phi が含まれるか(最小) + if phi.contains("\"op\":\"phi\"") { print(1) } else { print(0) } + } +} +' + local out + out=$(run_nyash_vm -c "$src" 2>&1) + check_exact "1" "$out" "self_param_phi" +} + +run_test "self_param_phi" test_self_param_phi +