Commit bf5a7eea

bf5a7eea452eMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified

Description

fix: restore self-hosting by fixing v1 compiler compatibility issues

Fix StrArray type mismatch: change lnames/ltypes from [] to "".split(",") so the v1 compiler correctly infers StrArray type instead of IntArray.

Refactor scan_return_type_list to scan_return_type_nid taking an int node ID parameter, avoiding passing IntArray as a function parameter which the v1 compiler miscompiles as const char*.

These changes, combined with v1 compiler fixes (StrArray indexed assignment support and GC cleanup attribute), restore self-hosted fib(34) = 5702887.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
bf5a7eea452e
Parent
48967805b2c3

spinel_codegen.rbmodifiedView file

@@ -3823,8 +3823,8 @@
38233823 end
38243824 # Also declare locals for better return type inference
38253825 if @meth_body_ids[i] >= 0
3826- lnames = []
3827- ltypes = []
3826+ lnames = "".split(",")
3827+ ltypes = "".split(",")
38283828 scan_locals(@meth_body_ids[i], lnames, ltypes, pnames)
38293829 lk = 0
38303830 while lk < lnames.length
@@ -4034,7 +4034,7 @@
40344034 return "void"
40354035 end
40364036 # Check for explicit returns
4037- rt = scan_return_type_list(stmts)
4037+ rt = scan_return_type_nid(body_id)
40384038 if rt != ""
40394039 return rt
40404040 end
@@ -4042,7 +4042,8 @@
40424042 infer_type(stmts[stmts.length - 1])
40434043 end
40444044
4045- def scan_return_type_list(stmts)
4045+ def scan_return_type_nid(nid)
4046+ stmts = get_stmts(nid)
40464047 i = 0
40474048 while i < stmts.length
40484049 rt = scan_return_type(stmts[i])
@@ -4072,8 +4073,7 @@
40724073 r1 = ""
40734074 body = @nd_body[nid]
40744075 if body >= 0
4075- stmts = get_stmts(body)
4076- r1 = scan_return_type_list(stmts)
4076+ r1 = scan_return_type_nid(body)
40774077 end
40784078 sub = @nd_subsequent[nid]
40794079 if sub >= 0
@@ -4087,15 +4087,13 @@
40874087 if @nd_type[nid] == "ElseNode"
40884088 body = @nd_body[nid]
40894089 if body >= 0
4090- stmts = get_stmts(body)
4091- return scan_return_type_list(stmts)
4090+ return scan_return_type_nid(body)
40924091 end
40934092 end
40944093 if @nd_type[nid] == "WhileNode"
40954094 body = @nd_body[nid]
40964095 if body >= 0
4097- stmts = get_stmts(body)
4098- return scan_return_type_list(stmts)
4096+ return scan_return_type_nid(body)
40994097 end
41004098 end
41014099 if @nd_type[nid] == "CaseMatchNode"
@@ -4105,8 +4103,7 @@
41054103 if @nd_type[inid] == "InNode"
41064104 ibody = @nd_body[inid]
41074105 if ibody >= 0
4108- is = get_stmts(ibody)
4109- rt = scan_return_type_list(is)
4106+ rt = scan_return_type_nid(ibody)
41104107 if rt != ""
41114108 return rt
41124109 end