phase: 20.49 COMPLETE; 20.50 Flow+String minimal reps; 20.51 selfhost v0/v1 minimal (Option A/B); hv1-inline binop/unop/copy; docs + run_all + CURRENT_TASK -> 21.0

This commit is contained in:
nyash-codex
2025-11-06 15:41:52 +09:00
parent 2dc370223d
commit 77d4fd72b3
1658 changed files with 6288 additions and 2612 deletions

View File

@ -0,0 +1,49 @@
// PatternBuilder — パターン条件ビルダー(コンパイル時メタ)
// 生成物は AST JSON v0 の条件式(文字列)。
static box PatternBuilder {
// eq(lhs, rhs) => lhs == rhs
eq(lhs_json, rhs_json) {
using "apps/lib/json_builder.hako" as JB
return JB.binary("==", lhs_json, rhs_json)
}
// or_([c1, c2, ...]) => c1 || c2 || ... (空は false
or_(conds) {
using "apps/lib/json_builder.hako" as JB
if conds.length() == 0 { return JB.literal_bool(false) }
if conds.length() == 1 { return conds.get(0) }
local i = 1
local acc = conds.get(0)
loop(i < conds.length()) {
acc = JB.binary("||", acc, conds.get(i))
i = i + 1
}
return acc
}
// and_([g1, g2, ...]) => g1 && g2 && ... (空は true
and_(conds) {
using "apps/lib/json_builder.hako" as JB
if conds.length() == 0 { return JB.literal_bool(true) }
if conds.length() == 1 { return conds.get(0) }
local i = 1
local acc = conds.get(0)
loop(i < conds.length()) {
acc = JB.binary("&&", acc, conds.get(i))
i = i + 1
}
return acc
}
// type_is(type_name, expr_json)
// Lowering 規約: MethodCall(object=expr, method="is", arguments=[Literal(String type_name)])
// → MIR::TypeOp(Check, value=expr, ty=map(type_name)) に降下されるsrc/mir/builder/exprs.rs
type_is(type_name, expr_json) {
local t = "{\"kind\":\"Literal\",\"value\":{\"type\":\"string\",\"value\":\"" + type_name + "\"}}"
return "{\"kind\":\"MethodCall\",\"object\":" + expr_json + ",\"method\":\"is\",\"arguments\":[" + t + "]}"
}
// default マーカー(条件式ではない)。
default() { return "__NY_PATTERN_DEFAULT" }
}