Skip to content

Commit a84fc5e

Browse files
author
Philip Guo
committed
experimental CRAZY MODE (selected as "Py 2.crazy"
in the Python version selector) where OPT turns into an almost bytecode-level stepper instead of a single-line stepper
1 parent e96bf36 commit a84fc5e

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

‎v3/css/pytutor.css‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,3 +719,8 @@ div.ExecutionVisualizer .highlight-legend {
719719
.ui-resizable-e:hover {
720720
border-color: #cccccc;
721721
}
722+
723+
/* for pyCrazyMode */
724+
span.crazyHighlightedChar {
725+
background-color: #FFFF66;
726+
}

‎v3/js/opt-frontend.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,26 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3434
// make two copies of ../web_exec.py and give them the following names,
3535
// then change the first line (starting with #!) to the proper version
3636
// of the Python interpreter (i.e., Python 2 or Python 3).
37+
// Note that your hosting provider might have stringent rules for what
38+
// kind of scripts are allowed to execute. For instance, my provider
39+
// (Webfaction) seems to let scripts execute only if permissions are
40+
// something like:
41+
// -rwxr-xr-x 1 pgbovine pgbovine 2.5K Jul 5 22:46 web_exec_py2.py*
42+
// (most notably, only the owner of the file should have write
43+
// permissions)
3744
//var python2_backend_script = 'web_exec_py2.py';
3845
//var python3_backend_script = 'web_exec_py3.py';
3946

4047
// uncomment below if you're running on Google App Engine using the built-in app.yaml
4148
var python2_backend_script = 'exec';
4249
var python3_backend_script = null;
4350

51+
// KRAZY experimental KODE!!! Use a custom hacked CPython interpreter
52+
var python2crazy_backend_script = 'web_exec_py2-crazy.py';
53+
// On Google App Engine, simply run dev_appserver.py with the
54+
// crazy custom CPython interpreter to get 2crazy
55+
//var python2crazy_backend_script = 'exec';
56+
4457
var appMode = 'edit'; // 'edit', 'display', or 'display_no_frills'
4558

4659
var preseededCode = null; // if you passed in a 'code=<code string>' in the URL, then set this var
@@ -143,6 +156,10 @@ $(document).ready(function() {
143156
else if ($('#pythonVersionSelector').val() == '3') {
144157
backend_script = python3_backend_script;
145158
}
159+
// experimental KRAZY MODE!!!
160+
else if ($('#pythonVersionSelector').val() == '2crazy') {
161+
backend_script = python2crazy_backend_script;
162+
}
146163

147164
if (!backend_script) {
148165
alert('Error: This server is not configured to run Python ' + $('#pythonVersionSelector').val());
@@ -222,6 +239,9 @@ $(document).ready(function() {
222239
textualMemoryLabels: ($('#textualMemoryLabelsSelector').val() == 'true'),
223240
showOnlyOutputs: ($('#showOnlyOutputsSelector').val() == 'true'),
224241
executeCodeWithRawInputFunc: executeCodeWithRawInput,
242+
243+
// undocumented experimental modes:
244+
pyCrazyMode: ($('#pythonVersionSelector').val() == '2crazy'),
225245
//allowEditAnnotations: true,
226246
});
227247

‎v3/js/pytutor.js‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,13 @@ ExecutionVisualizer.prototype.render = function() {
388388
this.allowEditAnnotations = false;
389389
}
390390

391+
if (this.params.pyCrazyMode !== undefined) {
392+
this.pyCrazyMode = this.params.pyCrazyMode;
393+
}
394+
else {
395+
this.pyCrazyMode = false;
396+
}
397+
391398
this.domRoot.find('#stepAnnotationEditor').hide();
392399

393400
if (this.params.embeddedMode) {
@@ -1317,17 +1324,63 @@ ExecutionVisualizer.prototype.updateOutput = function(smoothTransition) {
13171324
var curLineNumber = null;
13181325
var prevLineNumber = null;
13191326

1327+
// only relevant if in myViz.pyCrazyMode
1328+
var curColumnNumber = null;
1329+
var prevColumnNumber = null;
1330+
13201331
var curIsReturn = (curEntry.event == 'return');
13211332
var prevIsReturn = false;
13221333

13231334

13241335
if (myViz.curInstr > 0) {
13251336
prevLineNumber = myViz.curTrace[myViz.curInstr - 1].line;
13261337
prevIsReturn = (myViz.curTrace[myViz.curInstr - 1].event == 'return');
1338+
1339+
if (myViz.pyCrazyMode) {
1340+
prevColumnNumber = myViz.curTrace[myViz.curInstr - 1].column;
1341+
}
13271342
}
13281343

13291344
curLineNumber = curEntry.line;
13301345

1346+
if (myViz.pyCrazyMode) {
1347+
curColumnNumber = curEntry.column;
1348+
}
1349+
1350+
if (myViz.pyCrazyMode) {
1351+
var lineInfo = myViz.codeOutputLines[curLineNumber - 1];
1352+
assert(lineInfo.lineNumber == curLineNumber);
1353+
var codeAtLine = lineInfo.text;
1354+
//console.log("Line=", curLineNumber, ", Col=", curColumnNumber, codeAtLine);
1355+
1356+
// super hack to create three different substrings from codeAtLine
1357+
// and then encode each one separately as HTML
1358+
var prefix = '';
1359+
if (curColumnNumber > 0) {
1360+
prefix = codeAtLine.slice(0, curColumnNumber);
1361+
}
1362+
1363+
var highlightedChar = codeAtLine.slice(curColumnNumber, curColumnNumber + 1);
1364+
1365+
var suffix = '';
1366+
if (curColumnNumber < codeAtLine.length - 1) {
1367+
suffix = codeAtLine.slice(curColumnNumber + 1, codeAtLine.length);
1368+
}
1369+
1370+
// shotgun approach: reset ALL lines to their natural (unbolded) state
1371+
$.each(myViz.codeOutputLines, function(i, e) {
1372+
var d = myViz.generateID('cod' + e.lineNumber);
1373+
myViz.domRoot.find('#' + d).html(htmlspecialchars(e.text));
1374+
});
1375+
1376+
// ... then set the current line to lineHTML
1377+
var lineHTML = htmlspecialchars(prefix) +
1378+
'<span class="crazyHighlightedChar">' + htmlspecialchars(highlightedChar) + '</span>' +
1379+
htmlspecialchars(suffix);
1380+
var curCodeLineDiv = myViz.generateID('cod' + curLineNumber);
1381+
myViz.domRoot.find('#' + curCodeLineDiv).html(lineHTML);
1382+
}
1383+
13311384
// on 'return' events, give a bit more of a vertical nudge to show that
13321385
// the arrow is aligned with the 'bottom' of the line ...
13331386
var prevVerticalNudge = prevIsReturn ? Math.floor(myViz.codeRowHeight / 2) : 0;

‎v3/visualize.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<select id="pythonVersionSelector">
7878
<option value="2">Python 2.7</option>
7979
<option value="3">Python 3.3</option>
80+
<option value="2crazy">Py 2.crazy</option>
8081
</select>,
8182
<select id="cumulativeModeSelector">
8283
<option value="false">hide frames of exited functions</option>

0 commit comments

Comments
 (0)