Commit e59d250a

e59d250ab7afMerged

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

Description

Merge PR #1292: spinel --debug / -g line-mapped builds

Adds --debug / -g modes that emit #line directives (with a multi-file source map across require/require_relative) and keep methods non-inlined, so a native debugger can step through the original Ruby.

Maintainer follow-ups applied during merge:

  • Drop the @file_table ||= [] guard in compiler_helpers.rb#set_file_entry. The bare empty-array literal lowered to an IntArray default and collided with the StrArray/PolyArray-typed slot, breaking the windows-mingw self-host build. Both consumers already initialize the slot, so the helper can assume it exists.
  • Resolve the spinel_parse.c require-inlining conflict so the trailing same-line modifier handling (require 'x' rescue nil, CRLF-safe) runs before sp_wrap_included marker-wraps the inlined content.

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

Details

Commit
e59d250ab7af
Parent
8ce5456abae4
Merge parent
da8b3bca7078

compiler_helpers.rbmodifiedView file

@@ -466,6 +466,8 @@
466466 @nd_type.push("")
467467 @nd_name.push("")
468468 @nd_value.push(0)
469+ @nd_line.push(0) # keep the source-map arrays parallel with the rest, so a
470+ @nd_file.push(0) # dynamically-allocated node can't drift them out of sync
469471 @nd_content.push("")
470472 @nd_flags.push(0)
471473 @nd_operator.push("")
@@ -528,6 +530,8 @@
528530 @nd_type = Array.new(n, "")
529531 @nd_name = Array.new(n, "")
530532 @nd_value = Array.new(n, 0)
533+ @nd_line = Array.new(n, 0)
534+ @nd_file = Array.new(n, 0)
531535 @nd_content = Array.new(n, "")
532536 @nd_flags = Array.new(n, 0)
533537 @nd_operator = Array.new(n, "")
@@ -665,6 +669,30 @@
665669 # location in the compile error.
666670 @nd_value[nid] = val
667671 end
672+ # Debug builds only (SPINEL_DEBUG=1): the parser stamps every node
673+ # with its 1-based source line in a dedicated slot so codegen can
674+ # emit `#line` directives. Kept separate from @nd_value, which is
675+ # overloaded for integer/float literal values, numbered-param max, etc.
676+ if field == "node_line"
677+ @nd_line[nid] = val
678+ end
679+ # Debug multi-file map: id into the FILE table (0 = toplevel source).
680+ if field == "node_file"
681+ @nd_file[nid] = val
682+ end
683+ end
684+
685+ # Debug multi-file map: record a FILE <id> <path> table entry emitted by
686+ # the parser. Grown on demand so ids can arrive in any order.
687+ def set_file_entry(id, path)
688+ # The analyze/codegen consumers initialize @file_table = []; this shared
689+ # helper assumes the slot exists. A bare `@file_table ||= []` fallback is
690+ # unsafe under self-host inference: the empty literal lowers to IntArray
691+ # and collides with the PolyArray-typed slot, breaking the build.
692+ while @file_table.length <= id
693+ @file_table.push("")
694+ end
695+ @file_table[id] = path
668696 end
669697
670698 def set_ref_field(nid, field, ref_id)