Skip to content

Commit 2133ac8

Browse files
committed
some subtle renamings
1 parent 95472de commit 2133ac8

2 files changed

Lines changed: 37 additions & 28 deletions

File tree

PyTutorGAE/js/edu-python-tutor.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,35 @@ function enterEditMode() {
3434
$.bbq.pushState({ mode: 'edit' }, 2 /* completely override other hash strings to keep URL clean */);
3535
}
3636

37-
function enterVisualizeMode(traceData, inputCode) {
37+
function preprocessBackendResult(traceData, inputCode) {
3838
// set gross globals, then let jQuery BBQ take care of the rest
3939
curTrace = traceData;
4040
curInputCode = inputCode;
4141

42-
precomputeCurTraceLayouts(); // bam!
43-
4442
renderPyCodeOutput(inputCode);
4543

44+
45+
// must postprocess traceData prior to running precomputeCurTraceLayouts() ...
46+
var lastEntry = curTrace[curTrace.length - 1];
47+
48+
// GLOBAL!
49+
instrLimitReached = (lastEntry.event == 'instruction_limit_reached');
50+
51+
if (instrLimitReached) {
52+
curTrace.pop() // kill last entry
53+
var warningMsg = lastEntry.exception_msg;
54+
$("#errorOutput").html(htmlspecialchars(warningMsg));
55+
$("#errorOutput").show();
56+
}
57+
// as imran suggests, for a (non-error) one-liner, SNIP off the
58+
// first instruction so that we start after the FIRST instruction
59+
// has been executed ...
60+
else if (curTrace.length == 2) {
61+
curTrace.shift();
62+
}
63+
64+
precomputeCurTraceLayouts(); // bam!
65+
4666
$.bbq.pushState({ mode: 'visualize' }, 2 /* completely override other hash strings to keep URL clean */);
4767
}
4868

@@ -113,7 +133,7 @@ $(document).ready(function() {
113133

114134
// do this AFTER making #pyOutputPane visible, or else
115135
// jsPlumb connectors won't render properly
116-
processTrace(false);
136+
enterVisualizeMode(false);
117137
}
118138
else {
119139
assert(false);
@@ -159,7 +179,7 @@ $(document).ready(function() {
159179
$('#executeBtn').attr('disabled', false);
160180
}
161181
else {
162-
enterVisualizeMode(traceData, pyInputCodeMirror.getValue());
182+
preprocessBackendResult(traceData, pyInputCodeMirror.getValue());
163183
}
164184
},
165185
"json");

PyTutorGAE/js/edu-python.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ function htmlspecialchars(str) {
108108
return str;
109109
}
110110

111-
function processTrace(jumpToEnd) {
111+
function enterVisualizeMode(jumpToEnd) {
112112
curInstr = 0;
113113

114114
// only do this at most ONCE, and then clear out preseededCurInstr
@@ -121,28 +121,9 @@ function processTrace(jumpToEnd) {
121121
$("#pyStdout").val('');
122122

123123
if (curTrace.length > 0) {
124-
var lastEntry = curTrace[curTrace.length - 1];
125-
126-
// GLOBAL!
127-
instrLimitReached = (lastEntry.event == 'instruction_limit_reached');
128-
129-
if (instrLimitReached) {
130-
curTrace.pop() // kill last entry
131-
var warningMsg = lastEntry.exception_msg;
132-
$("#errorOutput").html(htmlspecialchars(warningMsg));
133-
$("#errorOutput").show();
134-
}
135-
// as imran suggests, for a (non-error) one-liner, SNIP off the
136-
// first instruction so that we start after the FIRST instruction
137-
// has been executed ...
138-
else if (curTrace.length == 2) {
139-
curTrace.shift();
140-
}
141-
142-
143124
if (jumpToEnd) {
144125
// if there's an exception, then jump to the FIRST occurrence of
145-
// that exception. otherwise, jump to the very end of execution.
126+
// that exception. otherwise, jump to the very end of execution.
146127
curInstr = curTrace.length - 1;
147128

148129
for (var i = 0; i < curTrace.length; i++) {
@@ -165,8 +146,7 @@ function processTrace(jumpToEnd) {
165146
$('#executionSlider').slider({
166147
min: 0,
167148
max: curTrace.length - 1,
168-
step: 1
169-
149+
step: 1,
170150
});
171151

172152
//disable keyboard actions on the slider itself (to prevent double-firing of events)
@@ -889,6 +869,15 @@ function renderDataStructures(curEntry, vizDiv) {
889869
console.log('---');
890870
*/
891871

872+
// VERY VERY experimental!!!
873+
// when doing this for realz, convert to using d3 and use row ID tag
874+
// as unique object ID for object constancy.
875+
var curEntryLayout = curTraceLayouts[curInstr];
876+
toplevelHeapLayout = curEntryLayout.map(function(row)
877+
{return row.slice(1, row.length); // KRAZY!!! remove row ID tag for now
878+
});
879+
880+
892881

893882
// Heap object rendering phase:
894883

0 commit comments

Comments
 (0)