feat: using system完全実装完了!nyashstdビルトイン名前空間対応
✅ 実装内容: - ビルトイン名前空間解決: nyashstd → builtin:nyashstd - 自動コード生成: static box群(string/integer/bool/array/console) - 環境変数デフォルト化: NYASH_ENABLE_USING, NYASH_RESOLVE_FIX_BRACES, NYASH_LLVM_USE_HARNESS ✅ 動作確認: - パース→解決→読み込み→コード生成の全段階が正常動作 - 環境変数8個→6個に削減(25%改善) ✅ 主要変更: - src/runner/pipeline.rs: builtin namespace特別処理追加 - src/runner/modes/common_util/resolve/strip.rs: builtin:プレフィックス処理 - src/config/env.rs: 3つの環境変数をデフォルトON化 🎯 次: Mini-VM開発でusing nyashstd活用可能 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -1,6 +1,56 @@
|
||||
use crate::runner::NyashRunner;
|
||||
use std::collections::HashSet;
|
||||
|
||||
/// Generate content for built-in namespaces like builtin:nyashstd
|
||||
fn generate_builtin_namespace_content(namespace_key: &str) -> String {
|
||||
match namespace_key {
|
||||
"builtin:nyashstd" => {
|
||||
// Generate Nyash code that provides nyashstd functionality
|
||||
// This exposes the built-in stdlib boxes as regular Nyash static boxes
|
||||
format!(r#"
|
||||
// Built-in nyashstd namespace (auto-generated)
|
||||
static box string {{
|
||||
create(text) {{
|
||||
return new StringBox(text)
|
||||
}}
|
||||
upper(str) {{
|
||||
return new StringBox(str.upper())
|
||||
}}
|
||||
}}
|
||||
|
||||
static box integer {{
|
||||
create(value) {{
|
||||
return new IntegerBox(value)
|
||||
}}
|
||||
}}
|
||||
|
||||
static box bool {{
|
||||
create(value) {{
|
||||
return new BoolBox(value)
|
||||
}}
|
||||
}}
|
||||
|
||||
static box array {{
|
||||
create() {{
|
||||
return new ArrayBox()
|
||||
}}
|
||||
}}
|
||||
|
||||
static box console {{
|
||||
log(message) {{
|
||||
print(message)
|
||||
return null
|
||||
}}
|
||||
}}
|
||||
"#)
|
||||
}
|
||||
_ => {
|
||||
// Unknown built-in namespace
|
||||
format!("// Unknown built-in namespace: {}\n", namespace_key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Strip `using` lines and register modules/aliases into the runtime registry.
|
||||
/// Returns cleaned source. No-op when `NYASH_ENABLE_USING` is not set.
|
||||
#[allow(dead_code)]
|
||||
@ -14,7 +64,7 @@ pub fn strip_using_and_register(
|
||||
}
|
||||
// Optional external combiner (default OFF): NYASH_USING_COMBINER=1
|
||||
if std::env::var("NYASH_USING_COMBINER").ok().as_deref() == Some("1") {
|
||||
let fix_braces = std::env::var("NYASH_RESOLVE_FIX_BRACES").ok().as_deref() == Some("1");
|
||||
let fix_braces = crate::config::env::resolve_fix_braces();
|
||||
let dedup_box = std::env::var("NYASH_RESOLVE_DEDUP_BOX").ok().as_deref() == Some("1");
|
||||
let dedup_fn = std::env::var("NYASH_RESOLVE_DEDUP_FN").ok().as_deref() == Some("1");
|
||||
let seam_dbg = std::env::var("NYASH_RESOLVE_SEAM_DEBUG").ok().as_deref() == Some("1");
|
||||
@ -176,6 +226,14 @@ pub fn strip_using_and_register(
|
||||
prelude.push_str(&inlined);
|
||||
prelude.push_str("\n");
|
||||
crate::runner::modes::common_util::resolve::seam::log_inlined_tail(&key, &inlined, seam_dbg);
|
||||
} else if key.starts_with("builtin:") {
|
||||
// Handle built-in namespaces like builtin:nyashstd
|
||||
let builtin_content = generate_builtin_namespace_content(&key);
|
||||
prelude.push_str(&builtin_content);
|
||||
prelude.push_str("\n");
|
||||
if verbose {
|
||||
eprintln!("[using] loaded builtin namespace: {}", key);
|
||||
}
|
||||
} else if verbose {
|
||||
eprintln!("[using] warn: could not read {}", p.display());
|
||||
}
|
||||
|
||||
@ -242,7 +242,16 @@ pub(super) fn resolve_using_target(
|
||||
crate::runner::box_index::cache_put(&key, out.clone());
|
||||
return Ok(out);
|
||||
}
|
||||
// 2) build candidate list: relative then using-paths
|
||||
// 2) Special handling for built-in namespaces
|
||||
if tgt == "nyashstd" {
|
||||
let out = "builtin:nyashstd".to_string();
|
||||
if trace {
|
||||
crate::runner::trace::log(format!("[using/resolve] builtin '{}' -> '{}'", tgt, out));
|
||||
}
|
||||
crate::runner::box_index::cache_put(&key, out.clone());
|
||||
return Ok(out);
|
||||
}
|
||||
// 3) build candidate list: relative then using-paths
|
||||
let rel = tgt.replace('.', "/") + ".nyash";
|
||||
let mut cand: Vec<String> = Vec::new();
|
||||
if let Some(dir) = context_dir {
|
||||
|
||||
Reference in New Issue
Block a user