1313# - display class and instance variables
1414# - display the 'binding' within a proc/lambda object, which represents
1515# its closure
16- # - for simplicity, maybe consolidate the '<main>' frame into the global
17- # frame, so that 'locals' defined in main and methods appear together
1816# - support gets() for user input using the restart hack mechanism
1917# - user input stored in $_
2018# - support 'include'-ing a module and bringing in variables into namespace
@@ -203,6 +201,8 @@ def self.iseq_local_variables iseq
203201 stack_entry = { }
204202 stack_entry [ 'is_highlighted' ] = false # set the last entry to true later
205203
204+ is_main = false
205+
206206 iseq = dc . frame_iseq ( i )
207207 if !iseq
208208 # if you're, say, in a built-in operator like :/ (division)
@@ -225,7 +225,12 @@ def self.iseq_local_variables iseq
225225 STDERR . print 'frame_description: '
226226 STDERR . puts boc . frame_description
227227 STDERR . print 'frame_type: '
228- STDERR . puts boc . frame_type # 'eval', 'method', 'block'
228+ STDERR . puts boc . frame_type # :eval, :method, :block
229+
230+ # special-case handling for the toplevel '<main>' frame
231+ if boc . frame_description == '<main>' && boc . frame_type == :eval
232+ is_main = true
233+ end
229234
230235 stack_entry [ 'func_name' ] = boc . frame_description # TODO: integrate 'frame_type' too?
231236
@@ -252,13 +257,26 @@ def self.iseq_local_variables iseq
252257
253258 stack_entry [ 'ordered_varnames' ] = lvs . map { |e | e . to_s }
254259 stack_entry [ 'encoded_locals' ] = lvs_val
255- end
256260
257- stack << stack_entry # only append on success
261+ # just fold everything into globals rather than creating a
262+ # separate (redundant) frame for '<main>'
263+ if is_main
264+ entry [ 'ordered_globals' ] += stack_entry [ 'ordered_varnames' ]
265+ entry [ 'globals' ] . update ( stack_entry [ 'encoded_locals' ] )
266+ end
267+ end
258268
269+ STDERR . puts '--- is_main: %s' % is_main
259270 STDERR . print '>>> ' , loc , ' ' , lvs , lvs_val
260271 STDERR . puts
261272 STDERR . puts
273+
274+ # no separate frame for main since its local variables were folded
275+ # into globals
276+ if !is_main
277+ stack << stack_entry
278+ end
279+
262280 end
263281 end
264282
0 commit comments