Commit 7b2fd09e
7b2fd09e6224Merged
Ryan Seys <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
fix: replace silent UnknownNode_* fallback with hard compile error
Previously, any Prism node not handled by spinel_parse.c's flatten()
switch was emitted as UnknownNode_<numeric_type>, which compile_expr
silently turned into "0". Programs using unsupported syntax compiled
and ran but produced wrong output -- the worst possible failure mode.
Concrete example ($counter &&= 5 -- GlobalVariableAndWriteNode is
not on master's parser switch):
BEFORE AFTER
------ -----
CRuby: 5 spinel exits 1 with:
spinel: 1 "Spinel: cannot compile GlobalVariableAndWriteNode
^^^ at line 2 (unsupported Ruby syntax)"
wrong,
no error
This change emits an UnsupportedNode sentinel in the text AST,
carrying the Prism node-type name and the source line. compile_stmt
and compile_expr both refuse to compile that sentinel and exit(1)
with a precise message.
The error message uses the Ruby-vocabulary node name
(GlobalVariableAndWriteNode, FlipFlopNode, etc.) rather than the
C macro form (PM_GLOBAL_VARIABLE_AND_WRITE_NODE). The parser does
the prefix-strip + PascalCase conversion inline so the message reads
as Ruby docs the user can google.
Self-host audit shows spinel_codegen.rb itself uses only nodes the parser handles, so the bootstrap is unaffected.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 7b2fd09e6224
- Parent
- 59ff8d7a4f30
spinel_codegen.rbmodifiedView file
if field == "unescaped" @nd_unescaped[nid] = val end if field == "kind" # UnsupportedNode carries the Prism node-type name here so # codegen can surface a precise compile error. @nd_content[nid] = val end end def set_int_field(nid, field, val) if field == "start_line" @nd_value[nid] = val end if field == "source_line" # UnsupportedNode carries the source line so codegen can cite # location in the compile error. @nd_value[nid] = val end end def set_ref_field(nid, field, ref_id) return "0" end t = @nd_type[nid] if t == "UnsupportedNode" # The parser emitted this sentinel because it hit a Prism node # type it doesn't know how to serialize. Refusing to compile is # far better than the historical silent "0". $stderr.puts "Spinel: cannot compile " + @nd_content[nid] + " at line " + @nd_value[nid].to_s + " (unsupported Ruby syntax)" exit(1) end if t == "IntegerNode" return @nd_value[nid].to_s end return end t = @nd_type[nid] if t == "UnsupportedNode" # Same loud-error path as compile_expr's UnsupportedNode arm. $stderr.puts "Spinel: cannot compile " + @nd_content[nid] + " at line " + @nd_value[nid].to_s + " (unsupported Ruby syntax)" exit(1) end if t == "MultiWriteNode" compile_multi_write(nid) returnspinel_parse.cmodifiedView file
Loading diff…