phase-20.45: v0 shape sweep (string JSON) for internal lowers

- lower_if_compare_box.hako: switch to functions[]/name="main"/blocks.id
- MirBuilderBox string fallbacks (if/binop/ret-int): same v0 shape update
- All quick canaries (phase2043/2044) remain green
This commit is contained in:
nyash-codex
2025-11-05 21:16:47 +09:00
parent 57ad6a13b4
commit 261b03b8a4
2 changed files with 12 additions and 11 deletions

View File

@ -234,13 +234,13 @@ static box MirBuilderBox {
} }
if lhs_val2 != null && rhs_val2 != null && then_val != null && else_val != null { if lhs_val2 != null && rhs_val2 != null && then_val != null && else_val != null {
// MIR: bb0(const lhs, const rhs, compare op -> v3, branch v3 then bb1 else bb2), bb1(const then, ret), bb2(const else, ret) // MIR: bb0(const lhs, const rhs, compare op -> v3, branch v3 then bb1 else bb2), bb1(const then, ret), bb2(const else, ret)
local mir_if = "{\"functions\":{\"Main.main\":{\"params\":[],\"locals\":[],\"blocks\":[" + local mir_if = "{\"functions\":[{\"name\":\"main\",\"params\":[],\"locals\":[],\"blocks\":[" +
"{\"label\":\"bb0\",\"instructions\":[{\"op\":\"const\",\"dst\":1,\"value\":{\"type\":\"i64\",\"value\":" + lhs_val2 + "}}," + "{\"id\":0,\"instructions\":[{\"op\":\"const\",\"dst\":1,\"value\":{\"type\":\"i64\",\"value\":" + lhs_val2 + "}}," +
"{\"op\":\"const\",\"dst\":2,\"value\":{\"type\":\"i64\",\"value\":" + rhs_val2 + "}}," + "{\"op\":\"const\",\"dst\":2,\"value\":{\"type\":\"i64\",\"value\":" + rhs_val2 + "}}," +
"{\"op\":\"compare\",\"operation\":\"" + op2 + "\",\"lhs\":1,\"rhs\":2,\"dst\":3}," + "{\"op\":\"compare\",\"operation\":\"" + op2 + "\",\"lhs\":1,\"rhs\":2,\"dst\":3}," +
"{\"op\":\"branch\",\"cond\":3,\"then\":1,\"else\":2}]}," + "{\"op\":\"branch\",\"cond\":3,\"then\":1,\"else\":2}]}," +
"{\"label\":\"bb1\",\"instructions\":[{\"op\":\"const\",\"dst\":4,\"value\":{\"type\":\"i64\",\"value\":" + then_val + "}},{\"op\":\"ret\",\"value\":4}]}," + "{\"id\":1,\"instructions\":[{\"op\":\"const\",\"dst\":4,\"value\":{\"type\":\"i64\",\"value\":" + then_val + "}},{\"op\":\"ret\",\"value\":4}]}," +
"{\"label\":\"bb2\",\"instructions\":[{\"op\":\"const\",\"dst\":5,\"value\":{\"type\":\"i64\",\"value\":" + else_val + "}},{\"op\":\"ret\",\"value\":5}]}] }},\"blocks\":3}" "{\"id\":2,\"instructions\":[{\"op\":\"const\",\"dst\":5,\"value\":{\"type\":\"i64\",\"value\":" + else_val + "}},{\"op\":\"ret\",\"value\":5}]}]}]}"
return mir_if return mir_if
} }
} }
@ -305,11 +305,11 @@ static box MirBuilderBox {
} }
} }
if lhs_val != null && rhs_val != null { if lhs_val != null && rhs_val != null {
local mir_bin = "{\"functions\":{\"Main.main\":{\"params\":[],\"locals\":[],\"blocks\":[{\"label\":\"bb0\",\"instructions\":[" + local mir_bin = "{\"functions\":[{\"name\":\"main\",\"params\":[],\"locals\":[],\"blocks\":[{\"id\":0,\"instructions\":[" +
"{\"op\":\"const\",\"dst\":1,\"value\":{\"type\":\"i64\",\"value\":" + lhs_val + "}}," + "{\"op\":\"const\",\"dst\":1,\"value\":{\"type\":\"i64\",\"value\":" + lhs_val + "}}," +
"{\"op\":\"const\",\"dst\":2,\"value\":{\"type\":\"i64\",\"value\":" + rhs_val + "}}," + "{\"op\":\"const\",\"dst\":2,\"value\":{\"type\":\"i64\",\"value\":" + rhs_val + "}}," +
"{\"op\":\"binop\",\"operation\":\"" + op + "\",\"lhs\":1,\"rhs\":2,\"dst\":3}," + "{\"op\":\"binop\",\"operation\":\"" + op + "\",\"lhs\":1,\"rhs\":2,\"dst\":3}," +
"{\"op\":\"ret\",\"value\":3}]}] }},\"blocks\":1}" "{\"op\":\"ret\",\"value\":3}]}]}]}"
return mir_bin return mir_bin
} }
} }
@ -328,7 +328,7 @@ static box MirBuilderBox {
loop(j < n) { local ch = s.substring(j,j+1); if ch >= "0" && ch <= "9" { had = 1 j = j + 1 } else { break } } loop(j < n) { local ch = s.substring(j,j+1); if ch >= "0" && ch <= "9" { had = 1 j = j + 1 } else { break } }
if had == 1 { if had == 1 {
local num = s.substring(i, j) local num = s.substring(i, j)
local mir = "{\"functions\":{\"Main.main\":{\"params\":[],\"locals\":[],\"blocks\":[{\"label\":\"bb0\",\"instructions\":[{\"op\":\"const\",\"dst\":1,\"value\":{\"type\":\"i64\",\"value\":" + num + "}},{\"op\":\"ret\",\"value\":1}] }] }},\"blocks\":1}" local mir = "{\"functions\":[{\"name\":\"main\",\"params\":[],\"locals\":[],\"blocks\":[{\"id\":0,\"instructions\":[{\"op\":\"const\",\"dst\":1,\"value\":{\"type\":\"i64\",\"value\":" + num + "}},{\"op\":\"ret\",\"value\":1}]}]}]}"
return mir return mir
} }
} }

View File

@ -54,13 +54,14 @@ static box LowerIfCompareBox {
local else_val = JsonFragBox.read_int_after(s, kv_else + 8) local else_val = JsonFragBox.read_int_after(s, kv_else + 8)
if else_val == null { return null } if else_val == null { return null }
local mir = "{\"functions\":{\"Main.main\":{\"params\":[],\"locals\":[],\"blocks\":[" + // Emit MIR v0 JSON as string (functions[]/name="main"/blocks.id)
"{\"label\":\"bb0\",\"instructions\":[{\"op\":\"const\",\"dst\":1,\"value\":{\"type\":\"i64\",\"value\":" + lhs_val + "}}," + local mir = "{\"functions\":[{\"name\":\"main\",\"params\":[],\"locals\":[],\"blocks\":[" +
"{\"id\":0,\"instructions\":[{\"op\":\"const\",\"dst\":1,\"value\":{\"type\":\"i64\",\"value\":" + lhs_val + "}}," +
"{\"op\":\"const\",\"dst\":2,\"value\":{\"type\":\"i64\",\"value\":" + rhs_val + "}}," + "{\"op\":\"const\",\"dst\":2,\"value\":{\"type\":\"i64\",\"value\":" + rhs_val + "}}," +
"{\"op\":\"compare\",\"operation\":\"" + op + "\",\"lhs\":1,\"rhs\":2,\"dst\":3}," + "{\"op\":\"compare\",\"operation\":\"" + op + "\",\"lhs\":1,\"rhs\":2,\"dst\":3}," +
"{\"op\":\"branch\",\"cond\":3,\"then\":1,\"else\":2}]}," + "{\"op\":\"branch\",\"cond\":3,\"then\":1,\"else\":2}]}," +
"{\"label\":\"bb1\",\"instructions\":[{\"op\":\"const\",\"dst\":4,\"value\":{\"type\":\"i64\",\"value\":" + then_val + "}},{\"op\":\"ret\",\"value\":4}]}," + "{\"id\":1,\"instructions\":[{\"op\":\"const\",\"dst\":4,\"value\":{\"type\":\"i64\",\"value\":" + then_val + "}},{\"op\":\"ret\",\"value\":4}]}," +
"{\"label\":\"bb2\",\"instructions\":[{\"op\":\"const\",\"dst\":5,\"value\":{\"type\":\"i64\",\"value\":" + else_val + "}},{\"op\":\"ret\",\"value\":5}]}] }},\"blocks\":3}" "{\"id\":2,\"instructions\":[{\"op\":\"const\",\"dst\":5,\"value\":{\"type\":\"i64\",\"value\":" + else_val + "}},{\"op\":\"ret\",\"value\":5}]}]}]}"
return mir return mir
} }
} }