chore(phase152-b): Static method 宣言整理(箱化モジュール化)
- MainDetectionHelper で main() 検出ロジックを箱化
- Legacy "static method main" と Modern "static box Main { main() }" の両パターン対応
- stage1_run_min.hako を modern 形式に統一
- ドキュメント更新(quickstart 等で static box スタイルに統一)
- パーサ新構文追加なし(仕様統一性保持)
- 後方互換性維持(Stage-B ヘルパーで legacy もサポート)
- テスト結果: 全スモーク PASS
Phase 152-B: Static Method 宣言の整理(Stage-3 仕様統一)
実装パターン: 箱化モジュール化(Phase 133/134 継承)
修正ファイル:
- lang/src/compiler/entry/compiler_stageb.hako: MainDetectionHelper (+103 lines)
- lang/src/compiler/entry/compiler.hako: Legacy Stage-A コメント (+3 lines)
- apps/tests/stage1_run_min.hako: Modern syntax に統一 (-1 line)
- docs/development/selfhosting/quickstart.md: サンプルコード更新
- CURRENT_TASK.md: Phase 152-B 完了記録
MainDetectionHelper 設計:
- findMainBody(): Entry point
- tryLegacyPattern(): "static method main" detection
- tryModernPattern(): "static box Main { main() }" detection
- findPattern(): Pattern search helper
- extractBodyFromPosition(): Brace matching extraction
利点:
✅ 明確な責任分離(各パターン検出が独立モジュール)
✅ テスタビリティ(各メソッド個別テスト可能)
✅ 拡張性(新パターン追加時は新メソッド追加のみ)
✅ 後方互換性(Legacy パターン削除は tryLegacyPattern 削除のみ)
テスト結果:
- stage1_run_min.hako: RC 0
- Selfhost depth-1: RC 0
- 全スモーク: 30/31 PASS (1 timeout は無関係)
This commit is contained in:
@ -12,7 +12,7 @@ This note shows how to run the Nyash self‑host compiler MVP to emit MIR(JSON v
|
||||
Compile a minimal program (string embedded in the compiler) and print JSON v0:
|
||||
|
||||
```
|
||||
./target/release/nyash lang/src/compiler/entry/compiler_stageb.hako -- --stage3 --source 'box Main { static method main() { return 7 } }'
|
||||
./target/release/nyash lang/src/compiler/entry/compiler_stageb.hako -- --stage3 --source 'static box Main { main() { return 7 } }'
|
||||
```
|
||||
|
||||
ENV → child args (透過):
|
||||
@ -23,7 +23,7 @@ ENV → child args (透過):
|
||||
|
||||
Examples:
|
||||
```
|
||||
NYASH_NY_COMPILER_MIN_JSON=1 ./target/release/nyash lang/src/compiler/entry/compiler_stageb.hako -- --stage3 --source 'box Main { static method main() { return 1+2 } }' > /tmp/out.json
|
||||
NYASH_NY_COMPILER_MIN_JSON=1 ./target/release/nyash lang/src/compiler/entry/compiler_stageb.hako -- --stage3 --source 'static box Main { main() { return 1+2 } }' > /tmp/out.json
|
||||
NYASH_SELFHOST_READ_TMP=1 ./target/release/nyash lang/src/compiler/entry/compiler_stageb.hako -- --min-json --stage3
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user