Commit 946de69f
946de69fcef7Merged
Ryan Seys <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
feat(parse,codegen): support SourceEncodingNode (ENCODING)
Adds parser case (no fields beyond base) and codegen arm in compile_expr returning c_string_literal("UTF-8"). infer_type arm classifies it as a string for the type system.
Limitation: CRuby returns an Encoding object; Spinel has no Encoding runtime so we return the canonical name as a string. Test calls .to_s for parity with both implementations.
Test: test/source_encoding.rb. Bootstrap: gen2.c == gen3.c.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 946de69fcef7
- Parent
- fea5369dddb0
spinel_codegen.rbmodifiedView file
@@ -1713,6 +1713,9 @@
17131713
if t == "SourceFileNode"17141714
return "string"17151715
end1716+
if t == "SourceEncodingNode"1717+
return "string"1718+
end17161719
if t == "SymbolNode"17171720
return "symbol"17181721
end@@ -17392,6 +17395,11 @@
1739217395
# path; documented limitation in test/source_file.rb.)1739317396
return c_string_literal(@nd_content[nid])1739417397
end17398+
if t == "SourceEncodingNode"17399+
# __ENCODING__ — Spinel has no Encoding runtime; we return17400+
# the canonical "UTF-8" string. Documented in test/source_encoding.rb.17401+
return c_string_literal("UTF-8")17402+
end1739517403
if t == "ArgumentsNode"1739617404
arg_ids = parse_id_list(@nd_args[nid])1739717405
if arg_ids.length > 0spinel_parse.cmodifiedView file
Loading diff…
test/source_encoding.rbaddedView file
Loading diff…
test/source_encoding.rb.expectedaddedView file
Loading diff…