Commit c41310f8

c41310f8b23fMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

fix(codegen): puts on a value-type sp_Class renders the class name

puts c.class (with c a user instance) fell through to the default printf("%lld", (long long)val) arm in both compile_puts and compile_puts_single. The value is an sp_Class struct, so the emitted C errored with "aggregate value used where an integer was expected".

Add a "class"-typed arm that emits puts(sp_class_to_s(val)), mirroring the existing "#{cls}" interpolation path.

Closes #681

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
c41310f8b23f
Parent
8123a5af9ad1

spinel_codegen.rbmodifiedView file

@@ -33876,6 +33876,12 @@
3387633876 emit(" { const char *_ps = sp_exc_message(" + val + "); if (_ps) { fputs(_ps, stdout); if (!*_ps || _ps[strlen(_ps)-1] != '" + bsl_n + "') putchar('" + bsl_n + "'); } else putchar('" + bsl_n + "'); }")
3387733877 return
3387833878 end
33879+ # `puts <cls>` on a value-type sp_Class -- render the name.
33880+ if at == "class"
33881+ @needs_class_table = 1
33882+ emit(" puts(sp_class_to_s(" + val + "));")
33883+ return
33884+ end
3387933885 if at == "time"
3388033886 emit(" { const char *_ts = sp_time_inspect_v(" + val + "); fputs(_ts, stdout); putchar('" + bsl_n + "'); }")
3388133887 return
@@ -33979,6 +33985,14 @@
3397933985 k = k + 1
3398033986 next
3398133987 end
33988+ # `puts <cls>` on a value-type sp_Class -- render the name via
33989+ # the sp_class_names[] table (mirrors `"#{cls}"` interpolation).
33990+ if at == "class"
33991+ @needs_class_table = 1
33992+ emit(" puts(sp_class_to_s(" + val + "));")
33993+ k = k + 1
33994+ next
33995+ end
3398233996 # `puts <exc>` -- print the message (CRuby calls to_s).
3398333997 if at == "exception"
3398433998 emit(" { const char *_ps = sp_exc_message(" + val + "); if (_ps) { fputs(_ps, stdout); if (!*_ps || _ps[strlen(_ps)-1] != '" + bsl_n + "') putchar('" + bsl_n + "'); } else putchar('" + bsl_n + "'); }")