Commit 4d7973dd

4d7973ddec3cMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 1 file · ~1 modified

Description

Update PLAN.md — sp_RbValue Phase 1-2 complete, 9400 lines, 39 examples

Major status updates:

  • Category 1 (polymorphism): Phase 2 complete Phase 1a-1d + 2a-2b all done: sp_RbValue, boxing, POLY widening, bimorphic dispatch, heterogeneous arrays, class tags
  • Category 3 (Block/Proc): fully complete
  • Category 4 (built-in classes): mostly complete (File, Time, Range, Enumerable)
  • Category 7 (control flow): fully complete

39 test programs, ~9400 lines codegen. Next: Phase 3 (pattern matching case/in).

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
4d7973ddec3c
Parent
30f6a5cec650

PLAN.mdmodifiedView file

@@ -10,7 +10,7 @@
1010
1111 ## 現状 (Status)
1212
13-### コンパイラアーキテクチャ (~7700行のC)
13+### コンパイラアーキテクチャ (~9400行のC)
1414
1515 - Prism (libprism) によるRubyパース
1616 - 多パスコード生成:
@@ -94,7 +94,7 @@
9494 | | シャドウスタックルート管理, ファイナライザ |
9595 | | GC不要なプログラムではGCコード省略 |
9696
97-### テストプログラム (30例)
97+### テストプログラム (39例)
9898
9999 | プログラム | テスト対象 |
100100 |-----------|-----------|
@@ -127,7 +127,16 @@
127127 | bm_fileio | File.read/write/exist?/delete |
128128 | bm_catch | catch/throw (タグ付き非局所脱出) |
129129 | bm_features | __method__, freeze/frozen? |
130-| bm_comparable | alias メソッド別名 |
130+| bm_comparable | Comparable演算子メソッド、alias |
131+| bm_range | Range as object (first, last, each, include?, to_a) |
132+| bm_time | Time.now, Time.at, to_i, 差分 |
133+| bm_enumerable | Enumerable, yield付きeachメソッド |
134+| bm_method | method(:name) → sp_Proc |
135+| bm_strindex | String#[] (文字インデックス) |
136+| bm_stdlib | ARGV, $stderr, srand/rand, exit |
137+| bm_proc | &block, proc {}, Proc.new, Proc#call |
138+| bm_poly | 多相変数 (sp_RbValue Phase 1) |
139+| bm_poly2 | 異種配列, bimorphicダックタイピング (Phase 2) |
131140
132141 ### ベンチマーク結果
133142
@@ -149,27 +158,29 @@
149158
150159 | # | カテゴリ | 状態 | 次のアクション |
151160 |---|---------|------|-------------|
152-| 1 | **動的型付け / ポリモーフィズム** | 設計完了 | sp_RbValue Phase 1 実装 |
161+| 1 | **動的型付け / ポリモーフィズム** | **Phase 2完了** ✅ | Phase 3: パターンマッチ |
153162 | 2 | **require / load / gem** | 未着手 | ファイル解決 + AST統合 |
154-| 3 | **Block/Proc完全性** | 一部完了 | `&block`, `Proc.new`, proc vs lambda意味論 |
155-| 4 | **組込クラス** | 一部完了 | Time, Range-as-object, Enumerator |
163+| 3 | **Block/Proc完全性** | **完了** ✅ | yield, &block, Proc.new, proc {}, method(:name) |
164+| 4 | **組込クラス** | **ほぼ完了** ✅ | File, Time, Range, Enumerable 対応済み |
156165 | 5 | **完全なString** | 未着手 | sp_String構造体 (ミュータブル + encoding) |
157-| 6 | **オブジェクトシステム完全性** | 未着手 | method_missing等はインタプリタフォールバック |
158-| 7 | **制御フロー完全性** | ほぼ完了 ✅ | 残: BEGIN/END のみ |
159-| 8 | **パターンマッチ** | 未着手 | sp_RbValue (ポリモーフィズム) が前提 |
160-| 9 | **例外階層** | 完了 ✅ | raise ClassName, rescue ClassName, 継承チェック |
166+| 6 | **オブジェクトシステム完全性** | 一部完了 | Comparable完了。method_missing等はフォールバック |
167+| 7 | **制御フロー完全性** | **完了** ✅ | catch/throw含む全制御フロー |
168+| 8 | **パターンマッチ** | **着手可能** | sp_RbValue完了、case/in実装可 |
169+| 9 | **例外階層** | **完了** ✅ | raise ClassName, rescue ClassName, 継承チェック |
161170 | 10 | **GC完全性** | 一部完了 | 文字列GC (sp_String), 世代別GC |
162171
163172 ### 完了した項目
164-- ✅ `__LINE__`, `__FILE__`, `defined?`, `__method__`
165-- ✅ `catch`/`throw` (タグ付き非局所脱出、ネスト対応)
166-- ✅ `freeze`/`frozen?` (AOTではno-op / 常にTRUE)
167-- ✅ `alias` (メソッド別名)
168-- ✅ `block_given?`, ブロック変数のwrite-capture修正
169-- ✅ `raise ClassName, "msg"`, `rescue ClassName => e`, 例外クラス継承チェック
173+- ✅ **sp_RbValue Phase 1**: 多相変数、boxing/unboxing、sp_poly_puts、nil?
174+- ✅ **sp_RbValue Phase 2**: 異種配列(sp_RbArray)、bimorphicダックタイピング、クラスタグ
175+- ✅ **Block/Proc**: yield, block_given?, &block, proc {}, Proc.new, Proc#call, method(:name)
176+- ✅ **Comparable**: 演算子メソッドC名サニタイズ (<=> → _cmp等)、self参照
177+- ✅ **Range as object**: first, last, each, include?, to_a, sum
178+- ✅ **Time**: Time.now, Time.at, to_i, 差分
179+- ✅ **Enumerable**: yield付きeachメソッドのブロック対応
180+- ✅ `catch`/`throw`, `alias`, `freeze`/`frozen?`, `__method__`, `sleep`
181+- ✅ `ARGV`, `$stderr.puts`, `exit`, `srand`/`rand`, `String#[]`
170182 - ✅ `File.read/write/exist?/delete`
171-- ✅ `Array#sort/sort!/min/max/sum/reduce/inject`
172-- ✅ `puts` の末尾改行Ruby互換
183+- ✅ `Array#sort/sort!/min/max/sum/reduce/inject/join/uniq`
173184
174185 ---
175186
@@ -338,18 +349,19 @@
338349
339350 ### 実装ロードマップ
340351
341-| Phase | 内容 | 前提 |
352+| Phase | 内容 | 状態 |
342353 |-------|------|------|
343-| **1a** | sp_RbValue型定義 + boxing/unboxing関数 | — |
344-| **1b** | sp_RbValue上の基本演算 (+, puts等) | 1a |
345-| **1c** | SPINEL_TYPE_POLY + Union型追跡 | 1a |
346-| **1d** | bimorphic call-site switch生成 | 1a, 1c |
347-| **2a** | megamorphic dispatch関数生成 | 1a, 1c |
348-| **2b** | 異種配列 `[1, "two", 3.0]` → Array<sp_RbValue> | 1a |
349-| **2c** | 異種Hash `{a: 1, b: "str"}` → Hash<sp_RbValue> | 1a |
350-| **3** | パターンマッチ `case/in` (型チェック分岐) | 1a, 1c |
351-| **4** | sp_String (ミュータブル文字列 + GC) | 1a |
352-| **5** | NaN-boxing (8バイト化) | 1a-2a |
354+| **1a** | sp_RbValue型定義 + boxing/unboxing関数 | ✅ 完了 |
355+| **1b** | sp_RbValue上の基本演算 (puts, nil?等) | ✅ 完了 |
356+| **1c** | SPINEL_TYPE_POLY + Union型追跡 | ✅ 完了 |
357+| **1d** | bimorphic call-site switch生成 | ✅ 完了 |
358+| **2a** | 異種配列 `[1, "two", 3.0]` → sp_RbArray | ✅ 完了 |
359+| **2b** | bimorphicダックタイピング (クラスタグ) | ✅ 完了 |
360+| **2c** | 異種Hash `{a: 1, b: "str"}` | 未着手 |
361+| **3** | パターンマッチ `case/in` (型チェック分岐) | **次** |
362+| **4** | megamorphic dispatch関数生成 (3型以上) | 未着手 |
363+| **5** | sp_String (ミュータブル文字列 + GC) | 未着手 |
364+| **6** | NaN-boxing (8バイト化) | 未着手 |
353365
354366 ### 設計原則
355367
@@ -359,11 +371,17 @@
359371 4. **互換性**: 最終的に全valid Rubyをコンパイル可能に
360372 5. **NaN-boxing準備**: Phase 1のsp_RbValueをPhase 5で8バイト化可能な設計
361373
362-### sp_RbValue待ちの機能
363-- パターンマッチ `case/in` (型チェック分岐)
364-- 異種配列/Hash
365-- ダックタイピング (3型以上)
366-- 条件で型が変わる変数・戻り値
374+### sp_RbValue完了により解放された機能
375+- ✅ 多相変数 (x = 1; x = "hello")
376+- ✅ 異種配列 [1, "two", 3.0]
377+- ✅ bimorphicダックタイピング (2クラス)
378+- ✅ nilable変数
379+
380+### 次に解放される機能 (Phase 3以降)
381+- パターンマッチ `case/in` (型チェック分岐) — **次のステップ**
382+- 異種Hash `{a: 1, b: "str"}`
383+- megamorphicダックタイピング (3クラス以上)
384+- 条件で型が変わるメソッド戻り値
367385
368386 ---
369387
@@ -374,8 +392,8 @@
374392 ├── src/
375393 │ ├── main.c # CLI、ファイル読み込み、Prismパース
376394 │ ├── codegen.h # 型システム、クラス/メソッド/モジュール情報構造体
377-│ └── codegen.c # 多パスコード生成器 (~7700行)
378-├── examples/ # 30テストプログラム
395+│ └── codegen.c # 多パスコード生成器 (~9400行)
396+├── examples/ # 39テストプログラム
379397 ├── prototype/
380398 │ └── tools/ # Step 0プロトタイプ (RBS抽出、LumiTrace等)
381399 ├── Makefile