restore(lang): full lang tree from ff3ef452 (306 files) — compiler, vm, shared, runner, c-abi, etc.\n\n- Restores lang/ directory (files≈306, dirs≈64) as per historical branch with selfhost sources\n- Keeps our recent parser index changes in compiler/* (merged clean by checkout)\n- Unblocks selfhost development and documentation references

This commit is contained in:
nyash-codex
2025-10-31 20:45:46 +09:00
parent dbc285f2b1
commit e5f697eb22
244 changed files with 16915 additions and 47 deletions

28
lang/src/runner/README.md Normal file
View File

@ -0,0 +1,28 @@
# Runner Facade (ScriptFirst) — Phase 20.10
Responsibility
- Provide a thin, optin runner facade in Hakorune (script) to orchestrate entry selection and pre/post hooks.
- Delegates actual execution to existing backends (Rust VM / LLVM). No behavior change by default.
Gate
- Enable with `HAKO_SCRIPT_RUNNER=1` (default OFF). In 20.10 this runner is not wired by default; wiring will be added behind the gate.
Contracts (draft)
- Entry: `Runner.run(entry: string, args: array<string>) -> i64`
- Prehooks: validate entry, shape args, emit diagnostics (short tokens) on failure.
- Posthooks: normalize result (e.g., quiet result mode), optional metrics/logging.
Notes
- Keep this layer pure and free of platform I/O. Defer I/O to CABI utilities (`hako_*`).
- FailFast: invalid entry/args → emit short diagnostics and return nonzero.
- BoxFirst: add adapters for boundary objects (args, env) instead of sprinkling conditions.
Short Diagnostics & Observability
- Preinvoke emits stable oneliners for smokes:
- Success: `[script-runner] invoke` (stdout)
- Failure (dev injection or panic): `[script-runner] invoke: FAIL` (stdout)
- The runner wiring prints a gate trace to stderr: `[script-runner] gate=on (facade)`.
Devonly toggle (TTL: Phase 20.10 bringup)
- `HAKO_SCRIPT_RUNNER_FORCE_FAIL=1` forces the preinvoke to emit `[script-runner] invoke: FAIL` without executing the facade program.
- Scope: tests/smokes only. Remove after runner wiring stabilizes (documented here as a temporary aid).

View File

@ -0,0 +1,13 @@
# Runner Core (Plan Builder)
Scope
- Decision-only layer to build a `RunnerPlan` from CLI/ENV inputs.
- No I/O or process execution here. Rust (Floor) applies the plan.
Status
- Phase 20.26C scaffold. Optin via `HAKO_RUNNER_PLAN=1` once wired.
Contract (MVP)
- Provide `RunnerPlanBuilder.build(args)` that returns a small JSON object with a minimal set of fields:
- `{"action":"ExecuteCore|ExecuteVM|ExecuteNyLlvmc|Skip|Error", "gate_c":bool, "engine":"core|vm|llvm", "plugins":bool, "quiet":bool}`
- FailFast on ambiguity; no silent fallbacks.

View File

@ -0,0 +1,34 @@
// RunnerPlanBuilder (JSON Plan) — Phase 20.26C
// Responsibility: Build a minimal RunnerPlan JSON from a tiny JSON payload.
// Contract: build/1 accepts a JSON-like string and returns a JSON object string:
// {"action":"ExecuteCore|ExecuteVM|ExecuteNyLlvmc|Skip|Error","gate_c":bool,
// "engine":"core|vm|llvm", "plugins":bool, "quiet":bool }
static box RunnerPlanBuilder {
build(j) {
// MVP: naive scan (no JSON parser dependency).
// Priority: explicit backend → ExecuteVM/ExecuteNyLlvmc;
// boxes directive → ExecuteBoxes;
// else if gate_c → ExecuteCore; else Skip.
local gate = j.indexOf("\"gate_c\":true") >= 0
local act = "Skip"
if (j.indexOf("\"backend\":\"vm\"") >= 0) { act = "ExecuteVM" }
else if (j.indexOf("\"backend\":\"llvm\"") >= 0) { act = "ExecuteNyLlvmc" }
// boxes toggle (optional). If present and no stronger action decided, produce ExecuteBoxes
local boxes_val = ""
if (j.indexOf("\"boxes\":\"hako\"") >= 0) { boxes_val = "hako" }
else if (j.indexOf("\"boxes\":\"rust\"") >= 0) { boxes_val = "rust" }
if (act == "Skip" && boxes_val != "") { act = "ExecuteBoxes" }
else if (act == "Skip" && gate) { act = "ExecuteCore" }
// Compose a compact JSON string (keys kept minimal and stable)
local plan = "{\"action\":\"" + act + "\"," +
"\"gate_c\":" + (gate ? "true" : "false") + "," +
"\"engine\":\"core\"," +
"\"plugins\":false," +
"\"quiet\":true" +
(boxes_val != "" ? ",\"boxes\":\"" + boxes_val + "\"" : "") +
"}"
return plan
}
}

View File

@ -0,0 +1,15 @@
// GateC Controller (Phase 20.26)
// Responsibility: Provide a thin, stable entry to route MIR(JSON v0)
// through the Ny/Core dispatcher when a wrapper route is needed.
include "lang/src/vm/core/dispatcher.hako"
static box GateCController {
// route_json/1: String(JSON v0) -> String(last line)
// Contract: returns a printable string (numeric or tag). No side effects.
route_json(j) {
// Delegate to the Core dispatcher runner
return call("NyVmDispatcher.run/1", j)
}
}

View File

@ -0,0 +1,7 @@
[module]
name = "selfhost.runner"
version = "1.0.0"
[exports]
Runner = "runner_facade.hako"

View File

@ -0,0 +1,9 @@
// launcher.hako — Minimal selfhost launcher (AOT target)
// Goal: produce lang/bin/hakorune via tools/build_llvm.sh
static box Main {
// No-args main() to avoid runtime Array allocation in AOT
main(){
return 0;
}
}

View File

@ -0,0 +1,23 @@
// runner_facade.hako — Phase 20.10 Script Runner (facade, draft)
// Gate: HAKO_SCRIPT_RUNNER=1 (not wired by default in 20.10)
static box Runner {
// Run facade. Returns process exit code (i64).
run(entry, args){
// Validate entry (simple dotted form expected)
if (entry == null || entry == "") {
call("env.console.warn/1", "VALIDATION");
return 2;
}
// Trace invocation (stable short line for smokes) — opt-in
// HAKO_SCRIPT_RUNNER_TRACE=1 で出力(既定は静穏)
local tr = call("env.local.get/1", "HAKO_SCRIPT_RUNNER_TRACE");
if tr && tr != "0" && tr != "false" {
print("[script-runner] invoke");
}
// Future: pre-hooks (env snapshot / quiet-result policy)
// Delegate to backend via existing CLI (placeholder; not wired in 20.10)
// This facade is documented first; wiring is added from Rust side behind a gate.
return 0;
}
}