runner: add NyVM wrapper core_bridge (canonicalize/dump) + opt-in wrapper canary; export module in common_util

This commit is contained in:
nyash-codex
2025-11-01 02:51:49 +09:00
parent 5597b78f0d
commit 978bb4a5c6
25 changed files with 604 additions and 27 deletions

View File

@ -27,6 +27,7 @@ static box Main {
}
_collect_flags(args) {
// Stage-A flags: emit/source/return only
local flags = { emit: 0, ret: null, source: null }
if args == null { return flags }
@ -210,17 +211,17 @@ static box Main {
// expr like: {"a":1,"b":2} - StageA: minimal implementation for basic key/value pairs
local inner = me._trim(expr.substring(1, expr.length()-1))
if inner == "" { return me._emit_call("map.of", "") }
local out = ""
local i = 0
local n = inner.length()
loop(i <= n) {
// find next comma or end
local j = i
loop(j < n) {
local ch = inner.substring(j,j+1)
if ch == "," { break }
j = j + 1
loop(j < n) {
local ch = inner.substring(j,j+1)
if ch == "," { break }
j = j + 1
}
local jj = j
if jj >= n { jj = n }
@ -466,7 +467,7 @@ static box Main {
if flags.emit == 1 {
local json = me._compile_source_to_json_v0(flags.source)
print(json)
return
return 0
}
// Stage-A は --min-json 指定時のみ JSON を出力
if flags.source != null && flags.source != "" {

View File

@ -0,0 +1,74 @@
// Stage-B compiler entry — ParserBox → FlowEntry emit-only
using "lang/src/compiler/parser/parser_box.hako" as ParserBox
using "lang/src/compiler/pipeline_v2/flow_entry.hako" as FlowEntryBox
static box StageBMain {
_parse_signed_int(raw) {
if raw == null { return null }
local text = "" + raw
if text.length() == 0 { return null }
local sign = 1
local idx = 0
if text.length() > 0 && text.substring(0, 1) == "-" {
sign = -1
idx = 1
}
if idx >= text.length() { return null }
local acc = 0
loop(idx < text.length()) {
local ch = text.substring(idx, idx + 1)
if ch < "0" || ch > "9" { return null }
local digit = "0123456789".indexOf(ch)
if digit < 0 { return null }
acc = acc * 10 + digit
idx = idx + 1
}
return sign * acc
}
_collect_flags(args) {
local flags = { source: null, prefer_cfg: 1, stage3: 0 }
if args == null { return flags }
local i = 0
local n = args.length()
loop(i < n) {
local token = "" + args.get(i)
if token == "--source" && i + 1 < n {
flags.source = "" + args.get(i + 1)
i = i + 1
} else if token == "--prefer-cfg" && i + 1 < n {
local parsed = me._parse_signed_int(args.get(i + 1))
if parsed != null { flags.prefer_cfg = parsed }
i = i + 1
} else if token == "--stage3" {
flags.stage3 = 1
}
i = i + 1
}
return flags
}
main(args) {
local flags = me._collect_flags(args)
local src = flags.source
if src == null || src == "" {
print("{\"version\":0,\"kind\":\"Program\",\"body\":[{\"type\":\"Return\",\"expr\":{\"type\":\"Int\",\"value\":0}}]}")
return 0
}
local p = new ParserBox()
if flags.stage3 == 1 { p.stage3_enable(1) }
p.extract_usings(src)
local usings_json = p.get_usings_json()
p.extract_externs(src)
local externs_json = p.get_externs_json()
local ast_json = p.parse_program2(src)
local prefer = flags.prefer_cfg
local jv0 = FlowEntryBox.emit_v0_from_ast(ast_json, prefer)
// Attach usings metadata when availableStage-B pipeline consumes via resolver
if jv0 == null || jv0 == "" { jv0 = "{\"version\":0,\"kind\":\"Program\",\"body\":[{\"type\":\"Return\",\"expr\":{\"type\":\"Int\",\"value\":0}}]}" }
print(jv0)
return 0
}
}