Commit ff9eca60

ff9eca606f09Merged

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

Description

fix: achieve 0 C errors for self-compilation

  • Rename 'last' variable in pop_scope to 'top_name' to avoid name collision with compile_body_return's 'last' (v1 uses global variable type map, collision caused wrong type inference)
  • Add explicit return statements to void methods to prevent v1 from inferring return types from last expression
  • Remove stmts parameter from emit_main (v1 typed it as mrb_int)

Self-compilation: ruby spinel.rb --source=spinel_codegen.rb produces C code that compiles with 0 errors. Self-hosted binary generates valid C headers but method bodies still need runtime debugging.

All 9 CRuby pipeline tests pass: fib, strings, case, control, inherit, attr, array2, hash, sort_reduce.

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

Details

Commit
ff9eca606f09
Parent
74c1890208a9

spinel_codegen.rbmodifiedView file

@@ -543,8 +543,8 @@
543543
544544 def pop_scope
545545 while @scope_names.length > 0
546- last = @scope_names[@scope_names.length - 1]
547- if last == "---"
546+ top_name = @scope_names[@scope_names.length - 1]
547+ if top_name == "---"
548548 @scope_names.pop
549549 @scope_types.pop
550550 return
@@ -1360,6 +1360,7 @@
13601360 ptypes_str = collect_ptypes_str(nid, ci)
13611361 defaults_str = collect_defaults_str(nid)
13621362 append_cls_meth(ci, mname, params_str, ptypes_str, "int", body_id, defaults_str)
1363+ return
13631364 end
13641365
13651366 def collect_params_str(nid)
@@ -2498,7 +2499,7 @@
24982499 emit_forward_decls
24992500 emit_class_methods
25002501 emit_toplevel_methods
2501- emit_main(stmts)
2502+ emit_main
25022503 end
25032504
25042505 def emit_header
@@ -3570,7 +3571,8 @@
35703571 end
35713572
35723573 # ---- Main emission ----
3573- def emit_main(stmts)
3574+ def emit_main
3575+ stmts = get_body_stmts(@root_id)
35743576 emit_raw("typedef struct{const char**data;mrb_int len;}sp_Argv;")
35753577 emit_raw("static sp_Argv sp_argv;")
35763578 emit_raw("")
@@ -4614,6 +4616,7 @@
46144616 if expr != "0"
46154617 emit(" " + expr + ";")
46164618 end
4619+ return
46174620 end
46184621
46194622 def compile_if_stmt(nid)
@@ -5419,6 +5422,7 @@
54195422 else
54205423 compile_stmt(last)
54215424 end
5425+ return
54225426 end
54235427
54245428 def compile_if_return(nid, rt)