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,27 @@
// ExternsSSOTEmitter — dev-only SSOT generator (Phase20.29)
// Purpose: emit a minimal externs SSOT JSON for development.
// Notes: This is intentionally small; runtime merges with built-ins.
static box ExternsSSOTEmitter {
emit(){
return "[\n"
+ " {\"interface\":\"nyrt.array\",\"method\":\"size\",\"effects\":\"read\",\"params\":[\"Box:ArrayBox\"],\"returns\":\"Integer\"},\n"
+ " {\"interface\":\"nyrt.array\",\"method\":\"get\",\"effects\":\"read\",\"params\":[\"Box:ArrayBox\",\"Integer\"],\"returns\":\"Unknown\"},\n"
+ " {\"interface\":\"nyrt.array\",\"method\":\"set\",\"effects\":\"mut\",\"params\":[\"Box:ArrayBox\",\"Integer\",\"Unknown\"],\"returns\":\"Void\"},\n"
+ " {\"interface\":\"nyrt.array\",\"method\":\"pop\",\"effects\":\"mut\",\"params\":[\"Box:ArrayBox\"],\"returns\":\"Unknown\"},\n"
+ " {\"interface\":\"nyrt.string\",\"method\":\"length\",\"effects\":\"read\",\"params\":[\"String\"],\"returns\":\"Integer\"},\n"
+ " {\"interface\":\"nyrt.string\",\"method\":\"indexOf\",\"effects\":\"read\",\"params\":[\"String\",\"String\",\"Integer\"],\"returns\":\"Integer\"},\n"
+ " {\"interface\":\"nyrt.string\",\"method\":\"lastIndexOf\",\"effects\":\"read\",\"params\":[\"String\",\"String\",\"Integer\"],\"returns\":\"Integer\"},\n"
+ " {\"interface\":\"nyrt.string\",\"method\":\"substring\",\"effects\":\"read\",\"params\":[\"String\",\"Integer\",\"Integer\"],\"returns\":\"String\"},\n"
+ " {\"interface\":\"nyrt.string\",\"method\":\"charAt\",\"effects\":\"read\",\"params\":[\"String\",\"Integer\"],\"returns\":\"String\"},\n"
+ " {\"interface\":\"nyrt.string\",\"method\":\"replace\",\"effects\":\"read\",\"params\":[\"String\",\"String\",\"String\"],\"returns\":\"String\"},\n"
+ " {\"interface\":\"env.console\",\"method\":\"log\",\"effects\":\"io\",\"params\":[\"String\"],\"returns\":\"Void\"},\n"
+ " {\"interface\":\"env.console\",\"method\":\"warn\",\"effects\":\"io\",\"params\":[\"String\"],\"returns\":\"Void\"},\n"
+ " {\"interface\":\"env.console\",\"method\":\"error\",\"effects\":\"io\",\"params\":[\"String\"],\"returns\":\"Void\"},\n"
+ " {\"interface\":\"env.time\",\"method\":\"now_ms\",\"effects\":\"read\",\"params\":[],\"returns\":\"Integer\"},\n"
+ " {\"interface\":\"env.mem\",\"method\":\"name\",\"effects\":\"read\",\"params\":[],\"returns\":\"String\"},\n"
+ " {\"interface\":\"nyrt.ops\",\"method\":\"op_eq\",\"effects\":\"read\",\"params\":[\"Unknown\",\"Unknown\"],\"returns\":\"Bool\"}\n"
+ "]\n";
}
}

View File

@ -0,0 +1,114 @@
// min_emitter.hako — Minimal MIR(JSON v0) emitter (const/ret/binop)
// Dev/optin helper for P1: Hakoside JSON generation without touching Rust semantics.
static box MinMirEmitter {
_header() { return "{\n \"kind\": \"MIR\",\n \"schema_version\": \"1.0\",\n \"functions\": [\n {\n \"name\": \"Main.main\", \"entry\": 1,\n \"blocks\": [\n { \"id\": 1, \"instructions\": [\n" }
_footer() { return " ] }\n ]\n }\n ]\n}\n" }
_const(dst, val) { return " {\"op\":\"const\",\"dst\":" + (""+dst) + ",\"value\":{\"type\":\"i64\",\"value\":" + (""+val) + "}},\n" }
_ret(val) { return " {\"op\":\"ret\",\"value\":" + (""+val) + "}\n" }
_binop(dst, op, lhs, rhs) {
return " {\"op\":\"binop\",\"dst\":" + (""+dst) + ",\"lhs\":" + (""+lhs) + ",\"rhs\":" + (""+rhs) + ",\"operation\":\"" + op + "\"},\n"
}
emit_ret_i64(n) {
return me._header() + me._const(1, n) + me._ret(1) + me._footer()
}
emit_add_i64(a, b) {
// v1 = a; v2 = b; v3 = v1 + v2; ret v3
return me._header() + me._const(1, a) + me._const(2, b) + me._binop(3, "Add", 1, 2) + me._ret(3) + me._footer()
}
// Emit: if (a > b) return 1 else return 0 (multi-block)
emit_if_gt_i64(a, b) {
local h = "{\n \"kind\": \"MIR\",\n \"schema_version\": \"1.0\",\n \"functions\": [\n { \"name\": \"Main.main\", \"entry\": 1,\n \"blocks\": [\n"
local b1 = " {\"id\":1, \"instructions\": [\n"
+ me._const(1, a)
+ me._const(2, b)
+ " {\"op\":\"compare\",\"dst\":3,\"lhs\":1,\"rhs\":2,\"operation\":\"Gt\"},\n"
+ " {\"op\":\"branch\",\"cond\":3,\"then\":2,\"else\":3}\n"
+ " ] }\n"
local b2 = " , {\"id\":2, \"instructions\": [\n"
+ me._const(4, 1)
+ me._ret(4)
+ " ] }\n"
local b3 = " , {\"id\":3, \"instructions\": [\n"
+ me._const(5, 0)
+ me._ret(5)
+ " ] }\n"
local f = " ]\n }\n ]\n}\n"
return h + b1 + b2 + b3 + f
}
// Emit: if (a == b) return 1 else return 0
emit_if_eq_i64(a, b) {
local h = "{\n \"kind\": \"MIR\",\n \"schema_version\": \"1.0\",\n \"functions\": [\n { \"name\": \"Main.main\", \"entry\": 1,\n \"blocks\": [\n"
local b1 = " {\"id\":1, \"instructions\": [\n"
+ me._const(1, a)
+ me._const(2, b)
+ " {\"op\":\"compare\",\"dst\":3,\"lhs\":1,\"rhs\":2,\"operation\":\"Eq\"},\n"
+ " {\"op\":\"branch\",\"cond\":3,\"then\":2,\"else\":3}\n"
+ " ] }\n"
local b2 = " , {\"id\":2, \"instructions\": [\n"
+ me._const(4, 1)
+ me._ret(4)
+ " ] }\n"
local b3 = " , {\"id\":3, \"instructions\": [\n"
+ me._const(5, 0)
+ me._ret(5)
+ " ] }\n"
local f = " ]\n }\n ]\n}\n"
return h + b1 + b2 + b3 + f
}
// Emit: if (a != b) return 1 else return 0
emit_if_ne_i64(a, b) {
local h = "{\n \"kind\": \"MIR\",\n \"schema_version\": \"1.0\",\n \"functions\": [\n { \"name\": \"Main.main\", \"entry\": 1,\n \"blocks\": [\n"
local b1 = " {\"id\":1, \"instructions\": [\n"
+ me._const(1, a)
+ me._const(2, b)
+ " {\"op\":\"compare\",\"dst\":3,\"lhs\":1,\"rhs\":2,\"operation\":\"Ne\"},\n"
+ " {\"op\":\"branch\",\"cond\":3,\"then\":2,\"else\":3}\n"
+ " ] }\n"
local b2 = " , {\"id\":2, \"instructions\": [\n"
+ me._const(4, 1)
+ me._ret(4)
+ " ] }\n"
local b3 = " , {\"id\":3, \"instructions\": [\n"
+ me._const(5, 0)
+ me._ret(5)
+ " ] }\n"
local f = " ]\n }\n ]\n}\n"
return h + b1 + b2 + b3 + f
}
// Emit diamond with PHI:
// if (a > b) then v=tv else v=ev; return v
emit_diamond_phi_gt_i64(a, b, tv, ev) {
local h = "{\n \"kind\": \"MIR\",\n \"schema_version\": \"1.0\",\n \"functions\": [\n { \"name\": \"Main.main\", \"entry\": 1,\n \"blocks\": [\n"
// bb1: compare + branch to bb2/bb3
local b1 = " {\"id\":1, \"instructions\": [\n"
+ me._const(1, a)
+ me._const(2, b)
+ " {\"op\":\"compare\",\"dst\":3,\"lhs\":1,\"rhs\":2,\"operation\":\"Gt\"},\n"
+ " {\"op\":\"branch\",\"cond\":3,\"then\":2,\"else\":3}\n"
+ " ] }\n"
// bb2: then path → const tv; jump merge
local b2 = " , {\"id\":2, \"instructions\": [\n"
+ me._const(4, tv)
+ " {\"op\":\"jump\",\"target\":4}\n"
+ " ] }\n"
// bb3: else path → const ev; jump merge
local b3 = " , {\"id\":3, \"instructions\": [\n"
+ me._const(5, ev)
+ " {\"op\":\"jump\",\"target\":4}\n"
+ " ] }\n"
// bb4: phi merge; ret v6
local b4 = " , {\"id\":4, \"instructions\": [\n"
+ " {\"op\":\"phi\",\"dst\":6,\"values\":[{\"block\":2,\"value\":4},{\"block\":3,\"value\":5}]},\n"
+ me._ret(6)
+ " ] }\n"
local f = " ]\n }\n ]\n}\n"
return h + b1 + b2 + b3 + b4 + f
}
}
static box MinMirEmitterMain { main(args){ return 0 } }