✅ **Phase 2.2達成項目**: - LLVMスモークテスト完全成功(1648バイト生成) - プラグイン統合動作確認(StringBox/IntegerBox@LLVM) - 静的コンパイル核心技術実証(MIR→LLVM→オブジェクト) - Everything is Plugin革命のLLVM対応確認 🔍 **Task先生nyrt調査成果**: - nyrt正体解明:AOT/LLVMランタイム必須インフラ - 機能分類:58%必須(ハンドル・GC・エントリー)42%代替可能 - 設計一貫性:75%達成(Box操作完全プラグイン化) - 削減戦略:Phase A実装で26個関数→プラグイン統合(42%削減) 🎯 **Everything is Plugin完全実現への道筋**: - 現状:プラグインファクトリー(StrictPluginFirst)完全動作 - 課題:nyrt中央集権 vs プラグイン哲学の矛盾 - 解決:Hybrid Plugin Architecture推進 - 目標:String/Box API→プラグイン統合で設計一貫性完成 📊 **技術的成果**: - LLVM static plugin integration: ✅ 完全動作 - Plugin priority system: ✅ 完全動作 - Object code generation: ✅ 実証済み - nyrt architectural analysis: ✅ 完全解明 🚀 **Phase 15.5革命基盤確立**: プラグイン優先アーキテクチャ実用化完了 次段階Phase 2.3でビルトインBox段階削除+nyrt Plugin統合推進へ 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
8.7 KiB
8.7 KiB
using — Imports and Namespaces (Phase 15+)
実装状況: Phase 15.5後に本格実装予定 | 基本ドット記法は実装済み
Status: Accepted (Runner‑side resolution). Selfhost parser accepts using as no‑op and attaches meta.usings for future use.
🎯 設計思想:Everything has Namespace
核心コンセプト
すべてのBox、関数、メンバーが明確な名前空間を持ち、衝突・曖昧性を根本解決。
// ✅ 実装済み:ドット記法
network.HttpClient() // プラグイン修飾名
plugin.network.HttpClient() // フルパス
// 🚧 Phase 15.5後:明示的スコープ演算子
::print("global") // グローバルスコープ
builtin::StringBox("test") // 内蔵版明示
plugin::StringBox("test") // プラグイン版明示
MIR Callee革新との統合
MIR Callee革新設計と完全統合:
// Phase 1: 型安全関数呼び出し(実装済み)
pub enum Callee {
Global(String), // ::print, global::func
Method { box_name, method, receiver }, // obj.method()
Extern(String), // nyash.console.log
Value(ValueId), // 第一級関数
}
// Phase 3: 完全修飾名対応(Phase 15.5後)
pub enum QualifiedCallee {
Qualified { namespace: Vec<String>, name: String },
Scoped { scope: ScopeKind, name: String },
}
📊 実装状況
✅ 現在実装済み
- ドット記法:
plugin.BoxName、namespace.member - using基本構文: ファイルトップでの宣言
- エイリアス:
using long.path as Alias - プラグイン修飾:
network.HttpClient
🚧 Phase 15.5後実装予定
- built-in namespace:
builtin.StringBoxvsplugin.StringBox - 完全修飾名:
nyash.builtin.print、std.console.log - スコープ演算子:
::global_func、Type::static_method - 厳密解決: コンパイル時名前空間検証
Policy
- Accept
usinglines at the top of the file to declare module namespaces or file imports. - Resolution is performed by the Rust Runner when
NYASH_ENABLE_USING=1.- Runner strips
usinglines from the source before parsing/execution. - Registers modules into an internal registry for path/namespace hints.
- Runner strips
- Selfhost compiler (Ny→JSON v0) collects using lines and emits
meta.usingswhen present. The bridge currently ignores this meta field.
Namespace Resolution (Runner‑side)
- Goal: keep IR/VM/JIT untouched. All resolution happens in Runner/Registry.
- Default search order (3 stages, deterministic):
- Local/Core Boxes (nyrt)
- Aliases (nyash.toml [imports] /
needs … as …) - Plugins (short name if unique, otherwise qualified
pluginName.BoxName)
- On ambiguity: error with candidates and remediation (qualify or define alias).
- Modes:
- Relaxed (default): short names allowed when unique。
- Strict: plugin短名にprefix必須(env
NYASH_PLUGIN_REQUIRE_PREFIX=1または nyash.toml[plugins] require_prefix=true)。
- Aliases:
- nyash.toml
[imports] HttpClient = "network.HttpClient" - needs sugar:
needs plugin.network.HttpClient as HttpClient(file‑scoped alias)
- nyash.toml
Plugins
- Unified namespace with Boxes. Prefer short names when unique.
- Qualified form:
network.HttpClient - Per‑plugin control (nyash.toml):
prefix,require_prefix,expose_short_names- 現状は設定の読み取りのみ(導線)。挙動への反映は段階的に実施予定。
needs sugar (optional)
- Treated as a synonym to
usingon the Runner side; registers aliases only. - Examples:
needs utils.StringHelper,needs plugin.network.HttpClient as HttpClient,needs plugin.network.*
nyash.toml keys (MVP)
[imports]/[aliases]: short name → fully qualified[plugins.<name>]:path,prefix,require_prefix,expose_short_names
Index and Cache (Runner)
- BoxIndex(グローバル):プラグインBox一覧とaliasesを集約し、Runner起動時(plugins init後)に構築・更新。
aliases: HashMap<String,String>(nyash.toml[aliases]と envNYASH_ALIASES)plugin_boxes: HashSet<String>(読み取り専用)
- 解決キャッシュ:グローバルの小さなキャッシュで同一キーの再解決を回避(キー:
tgt|base|strict|paths)。 - トレース:
NYASH_RESOLVE_TRACE=1で解決手順やキャッシュヒット、未解決候補を出力。
Syntax
- Namespace:
using core.stdorusing core.std as Std - File path:
using "apps/examples/string_p0.nyash" as Strings - Relative path is allowed; absolute paths are discouraged.
Style
- Place all
usinglines at the top of the file, before any code. - One using per line; avoid trailing semicolons. Newline separation is preferred.
- Order: sort alphabetically by target. Group namespaces before file paths.
- Prefer an explicit alias (
as ...) when the target is long. Suggested alias style isPascalCase(e.g.,Std,Json,UI).
Examples
using core.std as Std
using "apps/examples/string_p0.nyash" as Strings
static box Main {
main(args) {
local console = new ConsoleBox()
console.println("hello")
return 0
}
}
Qualified/Plugins/Aliases examples
# nyash.toml
[plugins.network]
path = "plugins/network.so"
prefix = "network"
require_prefix = false
[imports]
HttpClient = "network.HttpClient"
# code
needs plugin.network.HttpClient as HttpClient
static box Main {
main(args) {
let a = new HttpClient() # alias
let b = new network.HttpClient() # qualified
}
}
Runner Configuration
- Enable using pre‑processing:
NYASH_ENABLE_USING=1 - CLI from-the-top registration:
--using "ns as Alias"or--using '"apps/foo.nyash" as Foo'(repeatable) - Strict mode (plugin prefix required):
NYASH_PLUGIN_REQUIRE_PREFIX=1またはnyash.tomlの[plugins] require_prefix=true - Aliases from env:
NYASH_ALIASES="Foo=apps/foo/main.nyash,Bar=lib/bar.nyash" - Additional search paths:
NYASH_USING_PATH="apps:lib:." - Selfhost pipeline keeps child stdout quiet and extracts JSON only:
NYASH_JSON_ONLY=1(set by Runner automatically for child) - Selfhost emits
meta.usingsautomatically when present; no additional flags required.
🔗 関連ドキュメント
設計・アーキテクチャ
- MIR Callee革新設計 - 型安全関数呼び出し
- Phase 15.5 Core Box統一 - プラグイン統一計画
- Box Factory設計 - builtin vs plugin優先順位
実装ガイド
- Callee実装ロードマップ
- プラグインシステム - プラグイン開発ガイド
- 完全言語リファレンス - 全構文仕様
📝 実装ノート
Notes
- Phase 15 keeps resolution in the Runner to minimize parser complexity. Future phases may leverage
meta.usingsfor compiler decisions. - Unknown fields in the top‑level JSON (like
meta) are ignored by the current bridge. - 未解決時(非strict)は実行を継続し、
NYASH_RESOLVE_TRACE=1で候補を提示。strict時はエラーで候補を表示。 - Phase 15.5完了により、現代的な名前空間システムを実現予定
Include/Export (Phase 1)
Simple include expression for file‑scoped modules(Phase 1 提案)。将来は using/Runner 解決へ統合予定。
Overview
- One file exports one static box.
include(path)evaluates the file and returns that Box instance.
Syntax
local Math = include "lib/math.nyash"
local r = Math.add(1, 2)
Rules
- Single static box per file(0/複数はエラー)
- Expression form:
include(...)は Box インスタンスを返す式 - Caching: 同一パスは一度だけ評価(2回目以降はキャッシュ返却)
- Path resolution(MVP):
- Relative allowed; absolute discouraged
- nyash.toml
[include.roots]でstd=/stdlib等のルート定義を許可 - 省略拡張は
.nyash、ディレクトリならindex.nyash
Backends
- Interpreter: 実行時に評価し Box を返す
- VM/AOT: MIR Builder が対象ファイルを読み取り、同一 MIR モジュールに static box を降ろす(専用 MIR 命令は追加しない)
Limitations
- 循環 include の検出/診断は未実装(後続で active-load 追跡と経路表示を追加)
Rationale
- MIR 仕様に変更を入れず、実用的なモジュール分割を提供
- Everything‑is‑Box に整合(モジュール=Box、メソッド/フィールド=API)