Skip to content

Commit eec35c3

Browse files
author
Philip Guo
committed
sync'ed display with frontend
1 parent bc4e8ae commit eec35c3

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

PyTutorGAE/js/pytutor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,9 +1660,9 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
16601660
var funcName = htmlspecialchars(frame.func_name); // might contain '<' or '>' for weird names like <genexpr>
16611661
var headerLabel = funcName + '()';
16621662

1663-
var frameID = frame.frame_id; // optional (btw, this isn't a CSS id)
1664-
if (frameID) {
1665-
headerLabel = 'f' + frameID + ': ' + headerLabel;
1663+
// only display if you're someone's parent
1664+
if (frame.is_parent) {
1665+
headerLabel = 'f' + frame.frame_id + ': ' + headerLabel;
16661666
}
16671667

16681668
// optional (btw, this isn't a CSS id)

PyTutorGAE/pg_logger.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def __init__(self, finalizer_func, cumulative_display=False):
9191
# rather than only those currently on the stack (and their
9292
# lexical parents)
9393
self.cumulative_display = cumulative_display
94-
self.cumulative_display = True
9594

9695
# each entry contains a dict with the information for a single
9796
# executed line
@@ -104,7 +103,7 @@ def __init__(self, finalizer_func, cumulative_display=False):
104103
# Value: parent frame
105104
self.closures = {}
106105

107-
# Key: id() of frame object
106+
# Key: frame object
108107
# Value: monotonically increasing small ID, based on call order
109108
self.frame_ordered_ids = {}
110109
self.cur_frame_id = 1
@@ -115,6 +114,10 @@ def __init__(self, finalizer_func, cumulative_display=False):
115114
# nested functions were defined within them.
116115
self.zombie_frames = []
117116

117+
# set of elements within zombie_frames that are also
118+
# LEXICAL PARENTS of other frames
119+
self.parent_frames_set = set()
120+
118121
# all globals that ever appeared in the program, in the order in
119122
# which they appeared. note that this might be a superset of all
120123
# the globals that exist at any particular execution point,
@@ -129,7 +132,7 @@ def __init__(self, finalizer_func, cumulative_display=False):
129132

130133

131134
def get_frame_id(self, cur_frame):
132-
return self.frame_ordered_ids[id(cur_frame)]
135+
return self.frame_ordered_ids[cur_frame]
133136

134137

135138
# Returns the (lexical) parent frame of the function that was called
@@ -237,9 +240,8 @@ def interaction(self, frame, traceback, event_type):
237240
# or else we won't properly capture heap object mutations in the trace!
238241

239242
if event_type == 'call':
240-
tfid = id(top_frame)
241-
assert tfid not in self.frame_ordered_ids
242-
self.frame_ordered_ids[tfid] = self.cur_frame_id
243+
assert top_frame not in self.frame_ordered_ids
244+
self.frame_ordered_ids[top_frame] = self.cur_frame_id
243245
self.cur_frame_id += 1
244246

245247
if self.cumulative_display:
@@ -356,8 +358,8 @@ def create_encoded_stack_entry(cur_frame):
356358
assert e in encoded_locals
357359

358360
return dict(func_name=cur_name,
361+
is_parent=(cur_frame in self.parent_frames_set),
359362
frame_id=self.get_frame_id(cur_frame),
360-
# TODO: fixme
361363
parent_frame_id_list=parent_frame_id_list,
362364
encoded_locals=encoded_locals,
363365
ordered_varnames=ordered_varnames)
@@ -372,6 +374,7 @@ def create_encoded_stack_entry(cur_frame):
372374
if (type(v) in (types.FunctionType, types.MethodType) and \
373375
v not in self.closures):
374376
self.closures[v] = top_frame
377+
self.parent_frames_set.add(top_frame) # unequivocally add to this set!!!
375378
if not top_frame in self.zombie_frames:
376379
self.zombie_frames.append(top_frame)
377380

@@ -456,16 +459,17 @@ def create_encoded_stack_entry(cur_frame):
456459
# frontend can uniquely identify it when doing incremental
457460
# rendering. the strategy is to use a frankenstein-like mix of the
458461
# relevant fields to properly disambiguate closures and recursive
459-
# calls to the same function (stack_index is key for
460-
# disambiguating recursion!)
461-
for (stack_index, e) in enumerate(stack_to_render):
462+
# calls to the same function
463+
for e in stack_to_render:
462464
hash_str = e['func_name']
465+
# frame_id is UNIQUE, so it can disambiguate recursive calls
463466
hash_str += '_f' + str(e['frame_id'])
464-
if e['parent_frame_id_list']:
465-
hash_str += '_p' + '_'.join([str(i) for i in e['parent_frame_id_list']])
467+
468+
# TODO: this is no longer needed, right? (since frame_id is unique)
469+
#if e['parent_frame_id_list']:
470+
# hash_str += '_p' + '_'.join([str(i) for i in e['parent_frame_id_list']])
466471
if e['is_zombie']:
467472
hash_str += '_z'
468-
hash_str += '_i' + str(stack_index)
469473

470474
e['unique_hash'] = hash_str
471475

@@ -475,8 +479,6 @@ def create_encoded_stack_entry(cur_frame):
475479
func_name=tos[0].f_code.co_name,
476480
globals=encoded_globals,
477481
ordered_globals=ordered_globals,
478-
#stack_locals=encoded_stack_locals, # DEPRECATED in favor of stack_to_render
479-
#zombie_stack_locals=zombie_encoded_stack_locals, # DEPRECATED in favor of stack_to_render
480482
stack_to_render=stack_to_render,
481483
heap=self.encoder.get_heap(),
482484
stdout=get_user_stdout(tos[0]))

0 commit comments

Comments
 (0)