- ゴール: static box Main { main() } 形式に統一
- 方針: パーサ新構文追加なし、テスト/docs/ヘルパーで吸収
- 修正対象:
- stage1_run_min.hako - テストフィクスチャ
- compiler_stageb.hako::_find_main_body - ロジック両パターン対応
- quickstart 等docs - サンプルコード統一
- 言語リファレンス - legacy/非推奨明記
- 後方互換性: Stage-B ヘルパーで既存 static method も継続対応
- テスト: 全スモーク PASS 確認
- 工数: 2-3 時間(優先度: 低)
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
11 KiB
11 KiB
Phase 152-B: Static Method 宣言の整理(Stage-3 仕様への統一)
🎯 ゴール
Stage-3 の正式仕様に統一:「静的なエントリポイントは static box + メソッド定義だけ」
方針:
- パーサに新構文は追加しない
- テスト・ドキュメント・Stage-B ヘルパーを
static boxスタイルに統一 static methodは legacy/非推奨として明記
結果:
- Stage-3 仕様がクリーンになる
- 既存コードは継続動作(ヘルパーで両パターン対応)
- セルフホスティングパイプラインが仕様統一
📋 スコープ(やること・やらないこと)
✅ やること
apps/tests/stage1_run_min.hakoをstatic box Main { main() { } }形式に書き換えcompiler_stageb.hakoの_find_main_bodyロジックを修正static method mainパターンに加えてstatic box Main { main() { } }パターンにも対応
docs/development/selfhosting/quickstart.mdなど、legacystatic methodを例示している docs をstatic boxに統一- Stage-3 言語リファレンスに「
static methodは legacy/非推奨」を明記
❌ やらないこと
- Rust/Selfhost パーサに
static method新構文を追加しない - Stage-2 向けの言語仕様変更
- JoinIR/MIR の意味論変更
🏗️ 5 つのタスク
Task 1: 仕様ドキュメント作成(設計確認)
ファイル: docs/development/current/main/phase152b_static_method_cleanup.md(このファイル)
内容:
仕様確認
Stage-3 正式仕様:
// ✅ 正しい形(静的エントリポイント)
static box Main {
main(args) {
return 0
}
}
Legacy 形式(廃止予定):
// ❌ Legacy(Stage-3 では廃止方向)
static box Main {
static method main() {
return 0
}
}
影響範囲
| 対象 | 内容 | 修正方法 |
|---|---|---|
apps/tests/stage1_run_min.hako |
テストフィクスチャ | static box Main { main() { } } に書き換え |
compiler_stageb.hako::_find_main_body |
Stage-B ヘルパー | 両パターンに対応するロジック追加 |
quickstart.md など |
サンプルコード | static box スタイルに統一 |
| 言語リファレンス | 仕様 | "legacy/非推奨" 明記 |
方針
- パーサ: 新構文追加なし(既存の
static boxパーサで十分) - 後方互換性: Stage-B ヘルパーで
static methodパターンもサポート - 将来性: Phase 160+ では
static methodを廃止(ユーザーにはドキュメントで周知)
Task 2: stage1_run_min.hako の書き換え
対象ファイル: apps/tests/stage1_run_min.hako
現状:
// Minimal run path fixture for Stage-1 CLI.
// Produces a trivial Program(JSON v0) with Main.main returning 0.
static box Main {
static method main() {
return 0
}
}
変更後:
// Minimal run path fixture for Stage-1 CLI.
// Produces a trivial Program(JSON v0) with Main.main returning 0.
static box Main {
main() {
return 0
}
}
期待動作:
- Stage-1 CLI / Stage-B パイプラインで Program(JSON v0) が問題なく生成される
- Selfhost depth-1 / Stage-3 でも構文エラーなし
- すべての既存テスト PASS
Task 3: compiler_stageb.hako::_find_main_body ロジック調整
対象ファイル: lang/src/compiler/entry/compiler_stageb.hako(またはその周辺)
現在のロジック (概要):
_find_main_body(src) {
if src == null { return "" }
local key = "static method main"
local p = src.indexOf(key)
if p < 0 { return "" }
// ... parse body from position p
}
問題:
static method mainにハードコードされているstatic box Main { main() { } }パターンに対応できない
修正方針: 段階的フォールバック
_find_main_body(src) {
if src == null { return "" }
// Pattern 1: static method main (legacy)
local p = src.indexOf("static method main")
if p >= 0 {
return me.extractBodyFromPosition(src, p + 19) // Skip "static method main"
}
// Pattern 2: static box Main { main() (modern/Stage-3)
p = src.indexOf("static box Main")
if p < 0 {
p = src.indexOf("box Main")
}
if p >= 0 {
// Find "main(" after "Main"
local start = src.indexOf("main(", p)
if start >= 0 {
return me.extractBodyFromPosition(src, start)
}
}
// Fallback: no main found
return ""
}
extractBodyFromPosition(src, pos) {
// Find opening brace {
local bracePos = src.indexOf("{", pos)
if bracePos < 0 { return "" }
// Find matching closing brace }
local depth = 0
local i = bracePos
while i < src.length() {
local ch = src.substring(i, i + 1)
if ch == "{" {
depth = depth + 1
} else if ch == "}" {
depth = depth - 1
if depth == 0 {
return src.substring(bracePos, i + 1)
}
}
i = i + 1
}
return ""
}
実装参考:
- Phase 25.1c の
StageBBodyExtractorBox.build_body_srcに類似ロジックがある - String スライシング(
substring)を活用 - ブレースマッチングは基本的な手動実装で十分
期待動作:
static method mainパターン: 既存どおり動作static box Main { main() { } }パターン: 新規対応- エラーハンドリング: 両パターン見つからない場合は空文字(無変更)
Task 4: ドキュメント統一
更新対象:
-
docs/development/selfhosting/quickstart.mdなど quickstart 系- 現在:
static box Main { static method main() { } }を例示 - 変更:
static box Main { main() { } }に統一 - スニペットはすべて書き換え
- 現在:
-
docs/guides/language-guide.mdなど言語ガイド- Static box の紹介時に「
main()メソッドがエントリポイント」を明記 static methodは「legacy/非推奨」と注釈
- Static box の紹介時に「
-
LANGUAGE_REFERENCE_2025.mdなど仕様書- static box の定義で「Static method は Stage-3 では廃止予定」を追記
例:
### Static Box(静的ボックス)
エントリポイント:
✅ **推奨**: static box スタイル
\`\`\`nyash
static box Main {
main() {
return 0
}
}
\`\`\`
❌ **Legacy(Phase 160+ で廃止予定)**: static method スタイル
\`\`\`nyash
static box Main {
static method main() {
return 0
}
}
\`\`\`
Task 5: テスト・ドキュメント更新・CURRENT_TASK 記録
テスト実行:
-
Stage-1/Stage-B 経路:
# stage1_run_min.hako を使っている既存スモーク ./tools/smokes/v2/profiles/quick/selfhost/selfhost_stageb_*.sh # 期待: Program(JSON v0) 生成エラーなし -
Selfhost depth-1:
NYASH_FEATURES=stage3 NYASH_USE_NY_COMPILER=1 NYASH_JOINIR_STRICT=1 \ ./target/release/hakorune apps/tests/stage1_run_min.hako # 期待: RC 0, 構文エラーなし -
既存テスト互換性:
# 全スモークテスト実行 ./tools/smokes/v2/run.sh --profile quick # 期待: 回帰なし(既存テスト全て PASS)
ドキュメント更新:
phase152b_static_method_cleanup.mdに実装結果を追記CURRENT_TASK.mdに Phase 152-B 完了エントリ追加
CURRENT_TASK.md 追加内容:
### Phase 152-B: Static Method 宣言の整理(Stage-3 仕様統一)✅
**完了内容**:
- Static box エントリポイントを `static box Main { main() { } }` に統一
- Legacy `static method main()` は廃止方向として明記
- パーサ側は新構文追加なし(既存 static box パーサで対応)
**修正ファイル**:
- `apps/tests/stage1_run_min.hako` - テストフィクスチャ統一
- `compiler_stageb.hako` - _find_main_body ロジック調整(両パターン対応)
- `docs/development/selfhosting/quickstart.md` など - サンプルコード統一
- `LANGUAGE_REFERENCE_2025.md` - "legacy/非推奨" 明記
**テスト結果**:
- Stage-1/Stage-B パイプライン: ✅ 問題なし
- Selfhost depth-1: ✅ stage1_run_min.hako PASS
- 全スモークテスト: ✅ 回帰なし
**成果**:
- Stage-3 仕様がクリーンに(エントリポイント形式の統一)
- 既存コード継続動作(後方互換性维持)
- セルフホスティングパイプラインの仕様統一
**次フェーズ**: Phase 160+ - Static method 廃止(ユーザー周知済み)
Git commit:
chore(phase152-b): Static method 宣言の整理(Stage-3 仕様統一)
- stage1_run_min.hako を static box スタイルに統一
- compiler_stageb.hako のメイン検出ロジック修正(両パターン対応)
- quickstart 等ドキュメントのサンプルコード統一
- static method を legacy/非推奨として明記
- パーサ新構文追加なし(仕様統一性保持)
- テスト結果: 全スモークテスト PASS
✅ 完成チェックリスト(Phase 152-B)
- Task 1: 仕様ドキュメント作成
- 正式仕様と legacy 形式を明記
- 影響範囲と方針を整理
- Task 2:
stage1_run_min.hako書き換えstatic box Main { main() { } }に変更- 期待動作確認
- Task 3:
compiler_stageb.hakoロジック調整_find_main_bodyを両パターン対応に修正- ブレースマッチング実装
- ビルド・テスト確認
- Task 4: ドキュメント統一
- quickstart.md のサンプルコード統一
- 言語ガイド更新(legacy 注釈追加)
- 仕様書に「廃止予定」明記
- Task 5: テスト・CURRENT_TASK 更新
- Stage-1/Stage-B スモークテスト実行
- Selfhost depth-1 テスト実行
- 全スモークテスト確認
- CURRENT_TASK.md 更新
- git commit で記録
所要時間
2-3 時間程度
- Task 1(仕様確認): 30分
- Task 2(ファイル書き換え): 15分
- Task 3(ロジック修正): 1時間
- Task 4(ドキュメント): 30分
- Task 5(テスト・記録): 30分
次のステップ
Phase 200+: Python → Hakorune トランスパイラ構想への準備
- Stage-3 仕様が確定したので、より大きな野望に向けて土台が固まった
- Phase 160+ の .hako JoinIR/MIR 移植と並行して、Python 統合の準備を進める
進捗
- ✅ Phase 130-134: LLVM Python バックエンド整理
- ✅ Phase 150: Selfhost Stage-3 Depth-1 ベースライン強化
- ✅ Phase 151: ConsoleBox Selfhost Support
- ✅ Phase 152-A: 括弧付き代入式(Rust/Selfhost パーサ両対応)
- 🎯 Phase 152-B: Static Method 宣言整理(← 現在のフェーズ)
- 📋 Phase 160+: .hako JoinIR/MIR 移植章(予定)
- 🌟 Phase 200+: Python → Hakorune トランスパイラ構想(夢)