docs: prefer Nyash runner route (self-hosting); switch to NYASH_MACRO_PATHS; deprecations noted; update smokes to new envs

This commit is contained in:
Selfhosting Dev
2025-09-19 22:59:29 +09:00
parent 65cb504c7d
commit 9a0fe71215
8 changed files with 31 additions and 38 deletions

View File

@ -148,7 +148,7 @@ Imports/Namespace plan15.3late
### 直近タスクリストPhase15用
1. Macro 前段の正式導入完了PoC→実運用
- `NYASH_MACRO_BOX_NY=1` → PyVMランナー経由既定推奨
- `NYASH_MACRO_PATHS=...` でユーザーマクロ登録(ランナールート既定
- strict=1/timeout=2000ms既定
- `--dump-expanded-ast-json` を golden として活用
2. Selfhost フロントの簡素化

View File

@ -20,7 +20,7 @@ Status: Adopted (202509). This plan reframes Phase15 selfhosting to lev
## Work Items
1) Enable PyVM runner route for macros (done)
- `NYASH_MACRO_BOX_CHILD_RUNNER=1` → runner includes macro + calls `MacroBoxSpec.expand(json)`
- ランナールートが既定。内部子ルートは非推奨(`NYASH_MACRO_BOX_CHILD_RUNNER=0` でのみ強制)
2) Identity + upper_string templates (done)
- Examples under `apps/macros/examples/`
3) Golden tests
@ -36,4 +36,3 @@ Status: Adopted (202509). This plan reframes Phase15 selfhosting to lev
- Expanded AST JSON matches goldens for sample programs
- Macro runner path green under strict=1, timeout=2000ms
- MIR/LLVM/VM paths stable with expanded inputs

View File

@ -10,8 +10,8 @@ Philosophy
API (Nyash)
```nyash
box MacroBoxSpec {
// Required entry. Receives entire AST and returns a transformed AST.
static function expand(ast) { /* pure transform */ }
// Required entry. Receives AST JSON and returns transformed AST JSON.
static function expand(json, ctx) { /* pure transform over JSON string */ }
// Optional metadata.
static function name() { return "MyMacro" }
@ -27,7 +27,8 @@ paths = [
"apps/macros/json_lints.nyash"
]
```
- Loading policy (dev-only gate): `NYASH_MACRO_BOX_NY=1` enables loading Nyash MacroBoxes from configured paths.
- Loading policy: register via `NYASH_MACRO_PATHS=path1,path2`(推奨)。
- Runner route is defaultselfhosting優先。内部子ルートは非推奨`NYASH_MACRO_BOX_CHILD_RUNNER=0` 強制時のみ)。
- Isolation: loaded in a dedicated interpreter with IO disabled; only AST utilities and safe helpers exposed.
- Interim mapping (prototype): `name()` may map to built-in MacroBoxes for effects (e.g., `"UppercasePrintMacro"`). Otherwise, identity transform.

View File

@ -1,29 +1,32 @@
# MacroBox — User Extensible Macro Units (Experimental)
# MacroBox — User Extensible Macro Units
Status: Prototype, behind env gates (default OFF).
Status: Stable for user macros via Nyash runner routeselfhosting優先
Goals
- Allow users to implement procedural macro-like expansions in pure Nyash (future) and Rust (prototype) with a clean, deterministic interface.
- Preserve “Box independence” (loose coupling). Operate on public interfaces; avoid relying on private internals.
Enabling
- Enable MacroBox execution: `NYASH_MACRO_BOX=1`
- Enable built-in example: `NYASH_MACRO_BOX_EXAMPLE=1`
- Macro engine is ON by default; disable with `NYASH_MACRO_DISABLE=1`.
- Macro engine is ON by default. Disable with `NYASH_MACRO_DISABLE=1`.
- Register user macro files via `NYASH_MACRO_PATHS=path1,path2`.
- Runner routeNyashでの実行が既定。内部子ルートは非推奨`NYASH_MACRO_BOX_CHILD_RUNNER=0` でのみ強制)。
API (Rust, prototype)
- Trait: `trait MacroBox { fn name(&self) -> &'static str; fn expand(&self, ast: &ASTNode) -> ASTNode }`
- Register: `macro::macro_box::register(&MY_BOX)`
- Execution: Engine applies all registered boxes once per expansion pass (after built-in expansions). Order is registration order.
APINyash, 推奨)
- Box: `static box MacroBoxSpec { static function expand(json[, ctx]) -> json }`
- Contract: AST JSON v0docs/reference/ir/ast-json-v0.md。ctxはJSON文字列MVP: {caps:{io,net,env}})。
- 実行: エンジンは登録されたファイルをNyashランナールートで呼び出し、展開JSONを受け取る。
APIRust, 内部/開発者向け)
- Trait: `MacroBox { name() -> &'static str; expand(&ASTNode) -> ASTNode }`
- 用途: 最小のビルトイン(例: deriveやプロトタイピング。一般ユーザーはNyash版を使う。
Constraints (philosophy)
- Deterministic; side-effect free; no IO.
- Respect Box independence: operate on public interfaces only where applicable.
- Deterministic; side-effect free by defaultio/net/envはcapabilitiesで明示
- Respect Box independence: 公開インターフェースを基本に、疎結合を維持
Built-in example
- `UppercasePrintMacro` (guarded by `NYASH_MACRO_BOX_EXAMPLE=1`): transforms `print("UPPER:...")` to uppercase.
- `UppercasePrintMacro`開発者向けの内蔵例。通常はNyashで実装されたユーザーマクロを使用。
Future plan
- MacroBox in Nyash: `box MacroBox { static function expand(ast) -> ast }` with sandboxing and package registration via `nyash.toml`.
- Attribute-style macros: `@derive`-like hooks executed as MacroBoxes.
- nyash.toml による登録/パッケージ管理
- Attribute-style macros@derive/@lint)の整理

View File

@ -11,11 +11,9 @@ if [ ! -x "$bin" ]; then
exit 1
fi
export NYASH_MACRO_BOX_NY=1
export NYASH_MACRO_BOX_CHILD_RUNNER=1
export NYASH_MACRO_BOX_NY_PATHS="apps/macros/examples/invalid_json_macro.nyash"
export NYASH_MACRO_ENABLE=1
export NYASH_MACRO_PATHS="apps/macros/examples/invalid_json_macro.nyash"
export NYASH_MACRO_STRICT=0 # non-strict should fall back to identity
export NYASH_MACRO_BOX=1
out=$("$bin" --dump-expanded-ast-json "$src")

View File

@ -10,11 +10,9 @@ if [ ! -x "$bin" ]; then
exit 1
fi
export NYASH_MACRO_BOX_NY=1
export NYASH_MACRO_BOX_CHILD_RUNNER=1
export NYASH_MACRO_BOX_NY_PATHS="apps/macros/examples/invalid_json_macro.nyash"
export NYASH_MACRO_ENABLE=1
export NYASH_MACRO_PATHS="apps/macros/examples/invalid_json_macro.nyash"
export NYASH_MACRO_STRICT=1 # strict should fail process on invalid JSON
export NYASH_MACRO_BOX=1
set +e
"$bin" --dump-expanded-ast-json "$src" >/dev/null 2>&1

View File

@ -10,12 +10,10 @@ if [ ! -x "$bin" ]; then
exit 1
fi
export NYASH_MACRO_BOX_NY=1
export NYASH_MACRO_BOX_CHILD_RUNNER=1
export NYASH_MACRO_BOX_NY_PATHS="apps/macros/examples/hang_macro.nyash"
export NYASH_MACRO_ENABLE=1
export NYASH_MACRO_PATHS="apps/macros/examples/hang_macro.nyash"
export NYASH_NY_COMPILER_TIMEOUT_MS=200 # keep test quick
export NYASH_MACRO_STRICT=1 # strict should fail process
export NYASH_MACRO_BOX=1
set +e
"$bin" --dump-expanded-ast-json "$src" >/dev/null 2>&1

View File

@ -12,10 +12,7 @@ fi
# Enable user macro (upper string) and macro engine
export NYASH_MACRO_ENABLE=1
export NYASH_MACRO_BOX_NY=1
export NYASH_MACRO_BOX_NY_PATHS="apps/macros/examples/upper_string_macro.nyash"
# Prefer internal child mode for speed/stability in CI
export NYASH_MACRO_BOX_CHILD_RUNNER=0
export NYASH_MACRO_PATHS="apps/macros/examples/upper_string_macro.nyash"
# Selfhost pre-expand: default auto (no explicit env); requires PyVM
export NYASH_USE_NY_COMPILER=1
@ -31,4 +28,3 @@ echo "$out" | rg -q "selfhost macro pre-expand: engaging" && echo "[OK] selfhost
echo "[WARN] selfhost pre-expand auto did not engage; printing logs:" >&2
echo "$out" >&2
exit 2