Files
hakorune/tests/phase33/smoke/loopform/for_counter.hako
nyash-codex 1a1d223749 feat(phase33): loopform.hako complete implementation - All Stages (1-4) finished
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
2025-11-01 08:32:20 +09:00

58 lines
1.6 KiB
Plaintext

// LoopForm Smoke Test 2: Counter-based for loop
// Tests for loop with explicit counter using loopform
//
// Expected behavior (when C++ backend implements loopform):
// - Loop from 0 to 9 (10 iterations)
// - Use payload mode for structural counter
// - Return total iterations
using "lang/src/llvm_ir/instructions/loopform.hako" as LoopFormInst
static box Main {
main() {
print("=== LoopForm Smoke Test 2: for_counter ===")
// Simulate for loop: for (i = 0; i < 10; i++)
local blocks = new MapBox()
blocks.set("preheader", 10)
blocks.set("header", 11)
blocks.set("body", 12)
blocks.set("dispatch", 13)
blocks.set("latch", 14)
blocks.set("exit", 15)
// Use payload mode with max iterations
local options = new MapBox()
options.set("mode", "payload")
options.set("payload_max", 10)
options.set("enable_safepoint", 1)
// Generate loopform JSON
local json = LoopFormInst.lower_loopform(2, blocks, 20, 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_payload_mode = json.indexOf("\"mode\":\"payload\"")
if has_payload_mode < 0 {
print("ERROR: payload mode not found")
return 1
}
local has_max = json.indexOf("\"payload_max\":10")
if has_max < 0 {
print("ERROR: payload_max not found")
return 1
}
print("✓ PASS: for_counter loopform generated")
print("Note: Actual loop execution requires C++ backend implementation")
return 0
}
}