Commit af9d40dd
af9d40dd3174Merged
Ryan Seys <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
feat(parse,codegen): support SourceFileNode (FILE)
Adds parser case in spinel_parse.c that emits the toplevel script path (passed via argv) as the SourceFileNode's content. Codegen arm in compile_expr returns it as a c_string_literal, plus an infer_type arm so the type system knows FILE produces a string (without it, puts(FILE) emitted printf("%lld\n", ...) casting the pointer to long).
Limitation: spinel inlines require/require_relative at parse time, so FILE at every call site sees the toplevel script path. This matches CRuby for top-level uses but diverges inside required files. Documented in the test fixture.
Test: test/source_file.rb. Bootstrap: gen2.c == gen3.c.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- af9d40dd3174
- Parent
- 311d03089966
spinel_codegen.rbmodifiedView file
if t == "StringNode" return "string" end if t == "SourceFileNode" return "string" end if t == "SymbolNode" return "symbol" end if t == "SourceLineNode" return @nd_value[nid].to_s end if t == "SourceFileNode" # __FILE__ — parser populated @nd_content with the toplevel # script path. (Inlined-require call sites all see the same # path; documented limitation in test/source_file.rb.) return c_string_literal(@nd_content[nid]) end if t == "ArgumentsNode" arg_ids = parse_id_list(@nd_args[nid]) if arg_ids.length > 0spinel_parse.cmodifiedView file
Loading diff…
test/source_file.rbaddedView file
Loading diff…
test/source_file.rb.expectedaddedView file
Loading diff…