Phase v2-B loopform.hako 完全実装: 【実装】 - loopform.hako (258行): 6-block LoopForm 完全実装 - Header PHI: incoming 配列 + computed フラグ - Dispatch PHI (tag/payload): break/continue 処理 - Condition: MIR/Payload/Guard 全モード対応 - Safepoint: GC 安全点統合 - builder.hako (392行): 9 LLVM instructions 統合 - instructions/*.hako (9ファイル): 全命令実装 【テスト】 - Unit test: test_basic.hako (4 tests, 159行) - Smoke tests (3本, 130行): - while_simple.hako: 基本 while ループ - for_counter.hako: payload mode カウンタ - if_loop_merge.hako: 複合制御フロー + guard 【進捗】 - Stage 1: スケルトン実装 ✅ - Stage 2: PHI incoming 配列化 ✅ - Stage 3: Safepoint & Condition ✅ (Stage 1に含む) - Stage 4: スモークテスト3本 ✅ 【成果】 - 実装: 258行 (Python 224行 + 機能拡張) - テスト: 289行 (unit 159行 + smoke 130行) - ビルド: 成功 (0 errors) 次: Phase v2-C MIR Call 統合 + C++ backend 実装 Ref: docs/private/roadmap/phases/phase-33/PHASE_V2_LOOPFORM_*.md
66 lines
1.8 KiB
Plaintext
66 lines
1.8 KiB
Plaintext
// LoopForm Smoke Test 3: if-else + loop + merge
|
|
// Tests complex control flow with loopform
|
|
//
|
|
// Expected behavior (when C++ backend implements loopform):
|
|
// - Conditional branch before loop
|
|
// - Loop with early exit (break)
|
|
// - Merge point after loop
|
|
// - Return merged result
|
|
|
|
using "lang/src/llvm_ir/instructions/loopform.hako" as LoopFormInst
|
|
|
|
static box Main {
|
|
main() {
|
|
print("=== LoopForm Smoke Test 3: if_loop_merge ===")
|
|
|
|
// Simulate: if (cond) { while (i < 3) { if (i == 2) break; i++; } }
|
|
local blocks = new MapBox()
|
|
blocks.set("preheader", 20)
|
|
blocks.set("header", 21)
|
|
blocks.set("body", 22)
|
|
blocks.set("dispatch", 23)
|
|
blocks.set("latch", 24)
|
|
blocks.set("exit", 25)
|
|
|
|
// Use guard to combine condition and structural limit
|
|
local options = new MapBox()
|
|
options.set("mode", "mir")
|
|
options.set("use_guard", 1)
|
|
options.set("payload_max", 1000000)
|
|
options.set("enable_safepoint", 1)
|
|
|
|
// Generate loopform JSON
|
|
local json = LoopFormInst.lower_loopform(3, blocks, 30, options)
|
|
|
|
// Verify JSON structure
|
|
local has_loopform = json.indexOf("\"op\":\"loopform\"")
|
|
if has_loopform < 0 {
|
|
print("ERROR: loopform op not found")
|
|
return 1
|
|
}
|
|
|
|
local has_guard = json.indexOf("\"use_guard\":true")
|
|
if has_guard < 0 {
|
|
print("ERROR: use_guard not found")
|
|
return 1
|
|
}
|
|
|
|
local has_dispatch_tag = json.indexOf("\"tag\"")
|
|
if has_dispatch_tag < 0 {
|
|
print("ERROR: dispatch tag PHI not found")
|
|
return 1
|
|
}
|
|
|
|
local has_dispatch_payload = json.indexOf("\"payload\"")
|
|
if has_dispatch_payload < 0 {
|
|
print("ERROR: dispatch payload PHI not found")
|
|
return 1
|
|
}
|
|
|
|
print("✓ PASS: if_loop_merge loopform generated")
|
|
print("Note: Actual loop execution requires C++ backend implementation")
|
|
|
|
return 0
|
|
}
|
|
}
|