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

View File

@ -0,0 +1,69 @@
// GcBox — Policy wrapper (Hakorune) around host GC externs
// Phase 20.8: docs/導線優先既定OFF。Rustはデータ平面走査/バリア/セーフポイント)、
// Hakorune はポリシー平面(しきい値/スケジューリング/ログ)を担当するよ。
// 参考: docs/development/architecture/gc/policy-vs-data-plane.md
static box GcBox {
// Return JSON string with counters {safepoints, barrier_reads, barrier_writes}
stats() {
return call("env.gc.stats/0")
}
// Return total roots count (host handles + modules), besteffort integer
roots_snapshot() {
return call("env.gc.roots_snapshot/0")
}
// Request collection (noop until host supports it)
collect() {
// Host may ignore; keep FailFast if extern missing
call("env.gc.collect/0")
}
// Optional lifecycle hooks (noop unless host implements)
start() { call("env.gc.start/0"); }
stop() { call("env.gc.stop/0"); }
// Example (dev): a tiny cadence policy, OFF by default.
// Enable with: HAKO_GC_POLICY_TICK=1 (docs only; call manually from scripts)
policy_tick() {
if (call("env.local.get/1", "HAKO_GC_POLICY_TICK") == "1") {
// Read metrics and print a compact line for observation
local s = me.stats()
call("env.console.log/1", "[GcBox] stats=" + s)
// Example threshold (no-op unless host implements collect):
// me.collect()
}
}
// Example (dev): run simple cadence based on env thresholds (strings; best-effort)
// HAKO_GC_POLICY_LOG=1 → print stats each tick
// HAKO_GC_POLICY_FORCE=1 → call collect() each tick (may be no-op; guard expected)
// HAKO_GC_POLICY_EVERY_N=K → best-effort modulus trigger (tick_count % K == 0)
tick_with_policy(tick_count) {
local log = call("env.local.get/1", "HAKO_GC_POLICY_LOG")
local every = call("env.local.get/1", "HAKO_GC_POLICY_EVERY_N")
local force = call("env.local.get/1", "HAKO_GC_POLICY_FORCE")
if (log == "1") {
call("env.console.log/1", "[GcBox] stats=" + me.stats())
}
if (force == "1") {
// Gate: host may not implement collect() yet
collect()
return 0
}
if (every != "") {
// crude parse: treat non-empty string as integer if equals to tick_count string
// consumers should pass small positive K
local k = every
// Only attempt modulus when both are simple digits
// (language JSON helpers or numeric ops may be used when available)
if (k == "1") {
collect()
return 0
}
}
return 0
}
}