Skip to content

Commit 78d3a29

Browse files
committed
bah
1 parent 1769c28 commit 78d3a29

1 file changed

Lines changed: 46 additions & 51 deletions

File tree

‎v5-unity/js/pytutor.ts‎

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ export class ExecutionVisualizer {
7979
curInputCode: string;
8080
curTrace: any[];
8181

82+
// an array of objects with the following fields:
83+
// 'text' - the text of the line of code
84+
// 'lineNumber' - one-indexed (always the array index + 1)
85+
// 'executionPoints' - an ordered array of zero-indexed execution points where this line was executed
86+
// 'breakpointHere' - has a breakpoint been set here?
87+
codeOutputLines: {text: string, lineNumber: number, executionPoints: number[], breakpointHere: boolean}[] = [];
88+
8289
promptForUserInput: boolean;
8390
userInputPromptStr: string;
8491
promptForMouseInput: boolean;
@@ -221,6 +228,40 @@ export class ExecutionVisualizer {
221228
this.activateJavaFrontend(); // ohhhh yeah!
222229
}
223230

231+
var lines = this.curInputCode.split('\n');
232+
for (var i = 0; i < lines.length; i++) {
233+
var cod = lines[i];
234+
var n: {text: string, lineNumber: number, executionPoints: number[], breakpointHere: boolean} = {
235+
text: cod,
236+
lineNumber: i + 1,
237+
executionPoints: [],
238+
breakpointHere: false,
239+
};
240+
241+
$.each(this.curTrace, function(j, elt) {
242+
if (elt.line === n.lineNumber) {
243+
n.executionPoints.push(j);
244+
}
245+
});
246+
247+
// if there is a comment containing 'breakpoint' and this line was actually executed,
248+
// then set a breakpoint on this line
249+
var breakpointInComment = false;
250+
var toks = cod.split('#');
251+
for (var j = 1 /* start at index 1, not 0 */; j < toks.length; j++) {
252+
if (toks[j].indexOf('breakpoint') != -1) {
253+
breakpointInComment = true;
254+
}
255+
}
256+
257+
if (breakpointInComment && n.executionPoints.length > 0) {
258+
n.breakpointHere = true;
259+
this.addToBreakpoints(n.executionPoints);
260+
}
261+
262+
this.codeOutputLines.push(n);
263+
}
264+
224265
this.try_hook("end_constructor", {myViz:this});
225266
this.render(); // go for it!
226267
}
@@ -3075,14 +3116,6 @@ class CodeDisplay {
30753116

30763117
codToDisplay: string;
30773118

3078-
// initialize in renderPyCodeOutput()
3079-
// an array of objects with the following fields:
3080-
// 'text' - the text of the line of code
3081-
// 'lineNumber' - one-indexed (always the array index + 1)
3082-
// 'executionPoints' - an ordered array of zero-indexed execution points where this line was executed
3083-
// 'breakpointHere' - has a breakpoint been set here?
3084-
codeOutputLines: {text: string, lineNumber: number, executionPoints: number[], breakpointHere: boolean}[];
3085-
30863119
leftGutterSvgInitialized: boolean = false;
30873120
arrowOffsetY: number;
30883121
codeRowHeight: number;
@@ -3172,53 +3205,15 @@ class CodeDisplay {
31723205

31733206
renderPyCodeOutput() {
31743207
var myCodOutput = this; // capture
3175-
this.codeOutputLines = [];
3176-
3177-
var lines = this.codToDisplay.split('\n');
3178-
3179-
// TODO: maybe parse breakpoints in comments in ExecutionVisualizer
3180-
// instead of here in CodeDisplay?
3181-
for (var i = 0; i < lines.length; i++) {
3182-
var cod = lines[i];
3183-
var n: {text: string, lineNumber: number, executionPoints: number[], breakpointHere: boolean} = {
3184-
text: cod,
3185-
lineNumber: i + 1,
3186-
executionPoints: [],
3187-
breakpointHere: false,
3188-
};
3189-
3190-
$.each(this.owner.curTrace, function(j, elt) {
3191-
if (elt.line == n.lineNumber) {
3192-
n.executionPoints.push(j);
3193-
}
3194-
});
3195-
3196-
// if there is a comment containing 'breakpoint' and this line was actually executed,
3197-
// then set a breakpoint on this line
3198-
var breakpointInComment = false;
3199-
var toks = cod.split('#');
3200-
for (var j = 1 /* start at index 1, not 0 */; j < toks.length; j++) {
3201-
if (toks[j].indexOf('breakpoint') != -1) {
3202-
breakpointInComment = true;
3203-
}
3204-
}
3205-
3206-
if (breakpointInComment && n.executionPoints.length > 0) {
3207-
n.breakpointHere = true;
3208-
this.owner.addToBreakpoints(n.executionPoints);
3209-
}
3210-
3211-
this.codeOutputLines.push(n);
3212-
}
3213-
32143208
this.domRoot.find('#pyCodeOutputDiv').empty();
32153209

3216-
// maps this.codeOutputLines to both table columns
3210+
// maps codeOutputLines down both table columns
3211+
// TODO: get rid of pesky owner dependency
32173212
var codeOutputD3 = this.domRootD3.select('#pyCodeOutputDiv')
32183213
.append('table')
32193214
.attr('id', 'pyCodeOutput')
32203215
.selectAll('tr')
3221-
.data(this.codeOutputLines)
3216+
.data(this.owner.codeOutputLines)
32223217
.enter().append('tr')
32233218
.selectAll('td')
32243219
.data(function(d, i){return [d, d] /* map full data item down both columns */;})
@@ -3251,7 +3246,7 @@ class CodeDisplay {
32513246
// create a left-most gutter td that spans ALL rows ...
32523247
// (NB: valign="top" is CRUCIAL for this to work in IE)
32533248
this.domRoot.find('#pyCodeOutput tr:first')
3254-
.prepend('<td id="gutterTD" valign="top" rowspan="' + this.codeOutputLines.length + '"><svg id="leftCodeGutterSVG"/></td>');
3249+
.prepend('<td id="gutterTD" valign="top" rowspan="' + this.owner.codeOutputLines.length + '"><svg id="leftCodeGutterSVG"/></td>');
32553250

32563251
// create prevLineArrow and curLineArrow
32573252
this.domRootD3.select('svg#leftCodeGutterSVG')
@@ -3321,7 +3316,7 @@ class CodeDisplay {
33213316
// ... then handle the (much more common) multi-line case ...
33223317
// this weird contortion is necessary to get the accurate row height on Internet Explorer
33233318
// (simpler methods work on all other major browsers, erghhhhhh!!!)
3324-
if (this.codeOutputLines && this.codeOutputLines.length > 1) {
3319+
if (this.owner.codeOutputLines.length > 1) {
33253320
var secondRowOffsetY = this.domRoot.find('table#pyCodeOutput tr:nth-child(2)').offset().top;
33263321
this.codeRowHeight = secondRowOffsetY - firstRowOffsetY;
33273322
}

0 commit comments

Comments
 (0)