Files
hakorune/docs/abi/vm-kernel.md
nyash-codex 510f4cf523 builder/vm: stabilize json_lint_vm under unified calls
- Fix condition_fn resolution: Value call path + dev safety + stub injection
- VM bridge: handle Method::birth via BoxCall; ArrayBox push/get/length/set direct bridge
- Receiver safety: pin receiver in method_call_handlers to avoid undefined use across blocks
- Local vars: materialize on declaration (use init ValueId; void for uninit)
- Prefer legacy BoxCall for Array/Map/String/user boxes in emit_box_or_plugin_call (stability-first)
- Test runner: update LLVM hint to llvmlite harness (remove LLVM_SYS_180_PREFIX guidance)
- Docs/roadmap: update CURRENT_TASK with unified default-ON + guards

Note: NYASH_DEV_BIRTH_INJECT_BUILTINS=1 can re-enable builtin birth() injection during migration.
2025-09-28 12:19:49 +09:00

2.1 KiB
Raw Blame History

NYABI: VM Kernel Bridge (Draft)

Scope

  • Provide a minimal, stable ABI for delegating selected VM policies/decisions to Ny code.
  • Keep default behavior unchanged (OFF by default). Ny Kernel is a development aid only.

Design Principles

  • Coarse-grained: call per feature, not per instruction (avoid hot-path crossings).
  • FailFast: any error returns immediately; no silent fallbacks in dev.
  • Safe by default: reentry forbidden; each call has a deadline (timeout).
  • Backward compatible: API evolves via additive fields and optional methods only.

API (v0, draft)

  • VmKernel.caps() -> { version: i64, features: [string] }
  • VmKernel.stringify_policy(type: string) -> string
    • Returns: "direct" | "rewrite_stringify" | "fallback"
  • VmKernel.equals_policy(lhs_type: string, rhs_type: string) -> string
    • Returns: "object" | "value" | "fallback"
  • VmKernel.resolve_method_batch(reqs_json: string) -> string
    • Input JSON: { reqs: [{class, method, arity}], context?: {...} }
    • Output JSON: { plans: [{kind, target, notes?}], errors?: [...] }

Error & Timeout

  • All calls run with a percall deadline (NYASH_VM_NY_KERNEL_TIMEOUT_MS; default 200ms when enabled).
  • On timeout/NY error, Rust VM aborts the bridge call (OFF path remains intact).

Reentry Guard

  • A threadlocal flag prevents reentering the Ny Kernel from within an ongoing Ny Kernel call.
  • On violation, the bridge errors immediately (FailFast).

Data Model

  • Strings for structured data (JSON) across the boundary to avoid shape drift.
  • Primitive returns (i64/bool/string) for simple policies.

Toggles (reserved; default OFF)

  • NYASH_VM_NY_KERNEL=0|1
  • NYASH_VM_NY_KERNEL_TIMEOUT_MS=200
  • NYASH_VM_NY_KERNEL_TRACE=0|1

Acceptance (v0)

  • With bridge OFF, behavior is unchanged on all smokes.
  • With bridge ON and a stub kernel, behavior is still unchanged; logging shows calls and zero decisions.
  • Bridge API documented and skeleton Ny box exists (not wired by default).

Notes

  • Router batching is critical to avoid percall overhead.
  • Keep JSON schemas tiny and versioned; include a toplevel "v" if necessary.