Skip to content

Commit 7269250

Browse files
committed
more
1 parent 04ad668 commit 7269250

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

‎v4-cokapi/backends/ruby/pg_logger.rb‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# raise "error msg" unless <condition to assert>
1010

1111
# TODO
12+
# - put syntax error information into trace
1213
# - display constants defined INSIDE OF modules or classes
1314
# - display class and instance variables
1415
# - display the 'binding' within a proc/lambda object, which represents
@@ -19,7 +20,6 @@
1920
# - support gets() for user input using the restart hack mechanism
2021
# - user input stored in $_
2122
# - support 'include'-ing a module and bringing in variables into namespace
22-
# - get rid of fake 'nil' on final line and adjust line numbers
2323
#
2424
# Useful notes from http://phrogz.net/programmingruby/frameset.html:
2525
# - "First, every object has a unique object identifier (abbreviated as
@@ -47,7 +47,8 @@
4747
trace_output_fn = ARGV[1] || "../../../v3/test-trace.js"
4848

4949
cur_trace = []
50-
res = {'code' => cod, 'trace' => cur_trace}
50+
res = {'code' => cod.dup, # make a snapshot of the code NOW before it's modified
51+
'trace' => cur_trace}
5152

5253
# canonicalize to pretty-print
5354
cur_frame_id = 1
@@ -59,6 +60,8 @@
5960
#MAX_STEPS = 30
6061
MAX_STEPS = 300
6162

63+
n_lines_added = nil
64+
6265
class MaxStepsException < RuntimeError
6366
end
6467

@@ -247,11 +250,15 @@ def self.iseq_local_variables iseq
247250

248251
# super-hack: add an extra 'nil' line to execute at the end so that the
249252
# tracer can easily pick up on the final executed line in '(eval)'
250-
# - however, we need to patch up the line number and set event type to
251-
# 'return' for the final line's execution.
252253
# - this isn't a 'real' line number in the user's code since we've
253254
# inserted an extra line
254-
cod << "\nnil"
255+
if cod[-1] == "\n"
256+
cod << "nil"
257+
n_lines_added = 1
258+
else
259+
cod << "\nnil"
260+
n_lines_added = 2
261+
end
255262

256263
eval(cod) # the filename of the user's code is '(eval)'
257264
pg_tracer.disable
@@ -273,7 +280,7 @@ def self.iseq_local_variables iseq
273280
puts lineno
274281
puts exc_message
275282

276-
# TODO: put syntax error information on trace
283+
# TODO: put syntax error information into trace
277284
# "If the trace has exactly 1 entry and it's an uncaught_exception, then
278285
# the OPT frontend doesn't switch to the visualization at all ...
279286
# instead it displays a "syntax error"-like thingy in the code editor.
@@ -297,10 +304,19 @@ def self.iseq_local_variables iseq
297304
$stdout = STDOUT
298305
puts "other exception -- EEEEEEEE!!!"
299306
puts $!
300-
# ignore since we've already handled a :raise event by now
307+
# ignore since we've already handled a :raise event in the trace by now
301308
ensure
302309
$stdout = STDOUT
303310

311+
# super hack -- to account for the fact that we added an extra 'nil'
312+
# instruction at the very end of the user's code, we will set the
313+
# final instruction's line number to the last line of the file
314+
# (only do this if the trace isn't a single element, which likely
315+
# indicates some sort of uncaught_exception)
316+
if cur_trace.length > 1 && n_lines_added
317+
cur_trace[-1]['line'] -= n_lines_added
318+
end
319+
304320
# postprocessing into a trace
305321
trace_json = JSON.pretty_generate(res)
306322
File.open(trace_output_fn, 'w') do |f|

0 commit comments

Comments
 (0)