Commit e7b577b3

e7b577b37307Merged

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

Description

parse,codegen: Kernel#dir as compile-time literal

Returns the dirname of the source file, computed at parse time and baked into the generated C. The parser now emits a top-level SOURCE_FILE <escaped-path> line so the codegen can recover the path even when the source contains no __FILE__ reference.

Kernel#caller is intentionally not implemented -- it would require per-call frame tracking that slows the dispatch hot path. Out of scope for the AOT model.

Closes part of #878; caller portion deferred / declined.

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

Details

Commit
e7b577b37307
Parent
6d6d5954730f

compiler_helpers.rbmodifiedView file

@@ -571,6 +571,13 @@
571571 @root_id = root_id
572572 end
573573
574+ # Issue #878: parser emits SOURCE_FILE near the top so __dir__
575+ # (and similar compile-time helpers) can recover the path
576+ # without scanning for SourceFileNode entries.
577+ def set_source_file_path(path)
578+ @source_file_path = path
579+ end
580+
574581 def set_node_type(nid, node_type)
575582 @nd_type[nid] = node_type
576583 end