Skip to content

Commit f64fd7e

Browse files
committed
move stack_to_render computation to BACKEND
1 parent 94bb372 commit f64fd7e

File tree

3 files changed

+57
-56
lines changed

3 files changed

+57
-56
lines changed

PyTutorGAE/backend_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pg_logger, pprint
2+
3+
pp = pprint.PrettyPrinter()
4+
5+
def pprint_finalizer(trace):
6+
for e in trace:
7+
pp.pprint(e)
8+
9+
pg_logger.exec_script_str(open('example-code/closures/closure3.txt').read(), pprint_finalizer)

PyTutorGAE/js/edu-python.js

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -626,47 +626,6 @@ function renderDataStructures(curEntry, vizDiv) {
626626
$(vizDiv + " #stack").append('<div id="stackHeader">Frames</div>');
627627

628628

629-
// merge zombie_stack_locals and stack_locals into one master
630-
// ordered list using some simple rules for aesthetics
631-
var stack_to_render = [];
632-
633-
// first push all regular stack entries backwards
634-
if (curEntry.stack_locals) {
635-
for (var i = curEntry.stack_locals.length - 1; i >= 0; i--) {
636-
var entry = curEntry.stack_locals[i];
637-
entry.is_zombie = false;
638-
entry.is_highlighted = (i == 0);
639-
stack_to_render.push(entry);
640-
}
641-
}
642-
643-
// zombie stack consists of exited functions that have returned nested functions
644-
// push zombie stack entries at the BEGINNING of stack_to_render,
645-
// EXCEPT put zombie entries BEHIND regular entries that are their parents
646-
if (curEntry.zombie_stack_locals) {
647-
648-
for (var i = curEntry.zombie_stack_locals.length - 1; i >= 0; i--) {
649-
var entry = curEntry.zombie_stack_locals[i];
650-
entry.is_zombie = true;
651-
entry.is_highlighted = false; // never highlight zombie entries
652-
653-
// j should be 0 most of the time, so we're always inserting new
654-
// elements to the front of stack_to_render (which is why we are
655-
// iterating backwards over zombie_stack_locals).
656-
var j = 0;
657-
for (j = 0; j < stack_to_render.length; j++) {
658-
if ($.inArray(stack_to_render[j].frame_id, entry.parent_frame_id_list) >= 0) {
659-
continue;
660-
}
661-
break;
662-
}
663-
664-
stack_to_render.splice(j, 0, entry);
665-
}
666-
667-
}
668-
669-
670629
// first build up a list of lists representing the locations of TOP-LEVEL heap objects to be rendered.
671630
// doing so decouples the data format of curEntry from the nitty-gritty HTML rendering code,
672631
// which gives us more flexibility in experimenting with layout strategies.
@@ -813,16 +772,11 @@ function renderDataStructures(curEntry, vizDiv) {
813772
}
814773
});
815774

816-
$.each(stack_to_render, function(i, frame) {
775+
$.each(curEntry.stack_to_render, function(i, frame) {
817776
if (frame.ordered_varnames.length > 0) {
818777
$.each(frame.ordered_varnames, function(xxx, varname) {
819778
var val = frame.encoded_locals[varname];
820779

821-
// ignore return values for zombie frames
822-
if (frame.is_zombie && varname == '__return__') {
823-
return;
824-
}
825-
826780
if (!isPrimitiveType(val)) {
827781
layoutHeapObject(val);
828782
//console.log(frame.func_name + ':', varname, getRefID(val));
@@ -1148,7 +1102,7 @@ function renderDataStructures(curEntry, vizDiv) {
11481102
}
11491103

11501104

1151-
$.each(stack_to_render, function(i, e) {
1105+
$.each(curEntry.stack_to_render, function(i, e) {
11521106
renderStackFrame(e, i, e.is_zombie);
11531107
});
11541108

@@ -1199,11 +1153,6 @@ function renderDataStructures(curEntry, vizDiv) {
11991153
$.each(frame.ordered_varnames, function(xxx, varname) {
12001154
var val = localVars[varname];
12011155

1202-
// don't render return values for zombie frames
1203-
if (is_zombie && varname == '__return__') {
1204-
return;
1205-
}
1206-
12071156
// special treatment for displaying return value and indicating
12081157
// that the function is about to return to its caller
12091158
//
@@ -1296,7 +1245,7 @@ function renderDataStructures(curEntry, vizDiv) {
12961245

12971246
// highlight the top-most non-zombie stack frame or, if not available, globals
12981247
var frame_already_highlighted = false;
1299-
$.each(stack_to_render, function(i, e) {
1248+
$.each(curEntry.stack_to_render, function(i, e) {
13001249
if (e.is_highlighted) {
13011250
highlight_frame('stack' + i);
13021251
frame_already_highlighted = true;

PyTutorGAE/pg_logger.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,56 @@ def create_encoded_stack_entry(cur_frame):
383383
ordered_globals = [e for e in self.all_globals_in_order if e in encoded_globals]
384384
assert len(ordered_globals) == len(encoded_globals)
385385

386+
387+
# merge zombie_encoded_stack_locals and encoded_stack_locals
388+
# into one master ordered list using some simple rules for
389+
# making it look aesthetically pretty
390+
stack_to_render = [];
391+
392+
# first push all regular stack entries BACKWARDS
393+
if encoded_stack_locals:
394+
stack_to_render = encoded_stack_locals[::-1]
395+
for e in stack_to_render:
396+
e['is_zombie'] = False
397+
e['is_highlighted'] = False
398+
399+
stack_to_render[-1]['is_highlighted'] = True
400+
401+
402+
# zombie_encoded_stack_locals consists of exited functions that have returned
403+
# nested functions. Push zombie stack entries at the BEGINNING of stack_to_render,
404+
# EXCEPT put zombie entries BEHIND regular entries that are their parents
405+
for e in zombie_encoded_stack_locals[::-1]:
406+
# don't display return value for zombie frames
407+
try:
408+
e['ordered_varnames'].remove('__return__')
409+
except ValueError:
410+
pass
411+
412+
e['is_zombie'] = True
413+
e['is_highlighted'] = False # never highlight zombie entries
414+
415+
# j should be 0 most of the time, so we're always inserting new
416+
# elements to the front of stack_to_render (which is why we are
417+
# iterating backwards over zombie_stack_locals).
418+
j = 0
419+
while j < len(stack_to_render):
420+
if stack_to_render[j]['frame_id'] in e['parent_frame_id_list']:
421+
j += 1
422+
continue
423+
break
424+
425+
stack_to_render.insert(j, e)
426+
427+
386428
trace_entry = dict(line=lineno,
387429
event=event_type,
388430
func_name=tos[0].f_code.co_name,
389431
globals=encoded_globals,
390432
ordered_globals=ordered_globals,
391-
stack_locals=encoded_stack_locals,
392-
zombie_stack_locals=zombie_encoded_stack_locals,
433+
#stack_locals=encoded_stack_locals, # DEPRECATED in favor of stack_to_render
434+
#zombie_stack_locals=zombie_encoded_stack_locals, # DEPRECATED in favor of stack_to_render
435+
stack_to_render=stack_to_render,
393436
heap=self.encoder.get_heap(),
394437
stdout=get_user_stdout(tos[0]))
395438

0 commit comments

Comments
 (0)