Commit 3f2e6f28

3f2e6f288a05Merged

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

Description

codegen,analyze: punctuation global variables compile to safe identifiers

Any program referencing `$!` / `$;` / `$,` / `$/` / `$:` etc. hit a C compile error because spinel emitted `gv_!` / `gv_;` / ... which aren't valid C identifiers. Map each non-alphanumeric char to a stable word (`!` → `bang`, `;` → `semi`, ...) so the suffix becomes a valid identifier and the same Ruby global maps to one C name everywhere it appears.

`$!` reads as the rescued exception message string (NULL outside rescue → inspects as "nil"); `$/` reads as `"\n"` (its only meaningful default); other punct globals read as nil.

Fixes #831

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

Details

Commit
3f2e6f288a05
Parent
cf0d43265ab5

spinel_analyze.rbmodifiedView file

@@ -2206,6 +2206,11 @@
22062206 if gname == "$~" || gname == "$&" || gname == "$`" || gname == "$'"
22072207 return "string"
22082208 end
2209+ # Issue #831: $! is the currently-rescued exception. Read as
2210+ # the rescue message string (NULL outside rescue → .inspect = "nil").
2211+ if gname == "$!" || gname == "$;" || gname == "$," || gname == "$/"
2212+ return "string"
2213+ end
22092214 gi = 0
22102215 while gi < @gvar_names.length
22112216 if @gvar_names[gi] == gname