macro(if/match normalize): implement If-expression normalization for common statement contexts (Assignment/Return/Print); add golden (if-assign) and JSON builder helpers (print, return)

This commit is contained in:
Selfhosting Dev
2025-09-20 01:22:55 +09:00
parent 7d22a931be
commit b7975c80db
5 changed files with 357 additions and 3 deletions

View File

@ -60,6 +60,16 @@ static box JsonBuilder {
return "{\"kind\":\"Assignment\",\"target\":" + target_json + ",\"value\":" + value_json + "}"
}
print_(expr_json) {
return "{\"kind\":\"Print\",\"expression\":" + expr_json + "}"
}
return_(value_json) {
local v = "null"
if value_json != null { v = value_json }
return "{\"kind\":\"Return\",\"value\":" + v + "}"
}
local(vars, inits) {
// vars: array[string], inits: array[string|null]
local vs = []
@ -110,4 +120,3 @@ static box JsonBuilder {
return "{\"kind\":\"Program\",\"statements\":[" + this.join(stmts_json, ",") + "]}"
}
}