|
|
638182a8a2
|
feat(joinir): Phase 188-Impl-3 Pattern 3 (Loop with If-Else PHI) implementation
Add Pattern 3 lowerer for `loop { if cond { x = a } else { x = b } ... }` pattern.
New files:
- loop_with_if_phi_minimal.rs (381 lines): JoinIR lowerer for Pattern 3
- Multiple loop variables (counter + accumulator)
- In-loop if/else PHI using Select instruction
- Carriers passed to next iteration via tail recursion
Modified files:
- join_ir/mod.rs: Add Mod to BinOpKind, Select to MirLikeInst
- loop_pattern_detection.rs: Add is_loop_with_conditional_phi_pattern() detection
- lowering/mod.rs: Pattern 3 router integration
- loop_patterns.rs: Pattern 3 entry point delegation
- json.rs: Mod/Select JSON serialization
- join_ir_ops.rs: Mod operation evaluation (a % b)
- join_ir_runner.rs: Select instruction execution
- join_ir_vm_bridge/convert.rs: Mod/Select conversion handlers
Implementation:
- Pattern 3 generates 3 JoinIR functions: main, loop_step(i, sum), k_exit(sum_final)
- Exit condition: !(i <= 5) with Jump to k_exit
- In-loop if/else: if (i % 2 == 1) { sum + i } else { sum + 0 }
- Select instruction: sum_new = Select(if_cond, sum_then, sum_else)
- Both carriers updated: Call(loop_step, [i_next, sum_new])
Build status: ✅ Compiles successfully (0 errors, 34 warnings)
Integration: Infrastructure complete, MIR boundary mapping pending
All 3 patterns now have lowering infrastructure in place for Phase 188.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
2025-12-05 15:45:42 +09:00 |
|
|
|
466e636af6
|
Span trace utilities and runner source hint
|
2025-11-24 14:17:02 +09:00 |
|
|
|
03cb0a49c7
|
feat(joinir): Phase 27-shortterm S-5.1 完了 - JoinValue を VMValue ベースに統合
## 実装内容
### JoinValue 型の拡張
- **BoxRef variant 追加**: `BoxRef(Arc<dyn NyashBox>)` で VM と値を共有
- **Manual PartialEq 実装**: BoxRef は Arc::ptr_eq で比較
### VMValue との相互変換強化
- `to_vm_value()`: BoxRef サポート追加
- `into_vm_value()`: Zero-cost 変換(owned values)
- `from_vm_value()`: BoxRef サポート追加
### 後方互換性
- 既存の Int/Bool/Str/Unit variant は変更なし
- すべての既存コードがそのまま動作
- 16個の unit test 全て PASS ✅
### S-5.2 への準備
- BoxRef を method_router 経由で使用する準備完了
- 「VM 2号機」を避けるための基盤確立
## テスト結果
- join_ir_ops unit tests: 16 passed / 0 failed
|
2025-11-24 07:31:34 +09:00 |
|
|
|
7a9b23c9d1
|
feat(joinir): Phase 27-shortterm S-4.1~S-4.3 - JoinIR→VM Bridge基本実装
## S-4.1: VM インターフェース調査
- VMValue 型定義確認 (Integer, Bool, String, Void, BoxRef)
- VM API 確認 (execute_module, stats_counters)
- Task tool による詳細レポート取得
## S-4.2: JoinValue ↔ VMValue 変換関数実装
**新規追加**: src/mir/join_ir_ops.rs (+121行)
- JoinValue::to_vm_value() - 4型すべて対応
- JoinValue::from_vm_value() - エラーハンドリング付き
- Float/Future/BoxRef は非対応(エラー返却)
- 包括的テスト追加 (正常系・異常系)
## S-4.3: join_ir_vm_bridge.rs 基本構造実装
**新規ファイル**: src/mir/join_ir_vm_bridge.rs (350行)
### Public API
- run_joinir_via_vm() - JoinIR モジュールを VM で実行
### JoinIR → MIR 変換
- convert_joinir_to_mir() - JoinModule → MirModule
- convert_join_function_to_mir() - JoinFunction → MirFunction
- convert_mir_like_inst() - Compute命令変換
### 最小実装スコープ (Phase 27-shortterm)
✅ Compute 命令 (Const, BinOp, Compare, BoxCall)
✅ Ret 命令
⏳ Call/Jump 命令 (TODO: S-4.4 で実装)
### 設計方針
- JoinIR の正規化構造 (Pinned/Carrier, Exit φ) を保持
- マッピングだけで済ませる(正規化は消えない)
- VM の機能 (GC, plugins, error handling) を活用
## コンパイル
✅ 完全成功 (0エラー)
## 次のステップ
S-4.4: skip_ws で A/B テスト green 化
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
2025-11-24 06:16:45 +09:00 |
|
|
|
78c9d4d7fc
|
feat(joinir): Phase 27.8-1~3 — Ops Box導入 + Toggle対応完了
## Phase 27.8-1: JoinIR 命令意味箱(Ops Box)作成 ✅
**新規ファイル**: `src/mir/join_ir_ops.rs`
- `eval_binop()`: Add, Sub, Mul, Div, Or, And の評価ロジック一元化
- `eval_compare()`: Lt, Le, Gt, Ge, Eq, Ne の比較ロジック一元化
- エラー処理: `JoinIrOpError` 型で型安全
- 完全テストカバレッジ: 13個のユニットテスト
**効果**:
- BinOp/Compare の評価ロジックを一箇所に集約
- 再利用可能な API で将来の拡張が容易
- テスタビリティ向上
## Phase 27.8-2: join_ir_runner.rs の Ops Box 統合 ✅
**変更**: `src/mir/join_ir_runner.rs`
- BinOp/Compare の実装を ops box に完全移譲(約70行削減)
- `JoinValue` / `JoinIrOpError` を ops box から再エクスポート
- 後方互換性維持: `JoinRuntimeError = JoinIrOpError`
**効果**:
- コード重複削減(約70行)
- 実装の一貫性保証(ops box の単一実装を使用)
## Phase 27.8-3: MIR→JoinIR Toggle 対応 ✅
**変更**: `src/mir/join_ir.rs`
- `lower_skip_ws_to_joinir()`: トグル対応ディスパッチャー
- `lower_skip_ws_handwritten()`: 既存実装をリネーム(Phase 27.1-27.7)
- `lower_skip_ws_from_mir()`: MIR自動解析版スタブ(Phase 27.8-4 で実装予定)
**環境変数制御**:
```bash
# 手書き版(デフォルト)
./target/release/hakorune program.hako
# MIR自動解析版(Phase 27.8-4 実装予定)
NYASH_JOINIR_LOWER_FROM_MIR=1 ./target/release/hakorune program.hako
```
**効果**:
- 段階的な移行が可能(既存動作を完全に維持)
- A/B テストによる検証が容易
## 変更ファイル
- `src/mir/join_ir_ops.rs` (新規): Ops Box 実装
- `src/mir/join_ir_runner.rs`: Ops Box 使用に変更
- `src/mir/join_ir.rs`: Toggle 対応ディスパッチャー追加
- `src/mir/mod.rs`: join_ir_ops モジュール追加
## コンパイル結果
✅ 0 errors, 18 warnings(既存警告のみ)
✅ ビルド成功
## 次のステップ
**Phase 27.8-4**: `lower_skip_ws_from_mir()` 本実装
- MirQuery を使った MIR 解析
- パターンマッチング(init, header, break checks, body)
- JoinIR 自動生成(entry function + loop_step function)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
2025-11-23 14:47:00 +09:00 |
|