Skip to content

Commit c2cec43

Browse files
author
Philip Guo
committed
print return values AFTER local variables
1 parent c51f4dc commit c2cec43

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

edu-python.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ button.bigBtn {
256256
}
257257

258258
.retval {
259-
font-size: 10pt;
260-
font-style: italic;
259+
font-size: 9pt;
261260
}
262261

263262
table.listTbl {

edu-python.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ function renderDataStructuresVersion1(curEntry, vizDiv) {
337337

338338
// render all global variables IN THE ORDER they were created by the program,
339339
// in order to ensure continuity:
340+
//
341+
// TODO: in the future, the back-end can actually pre-compute this
342+
// list so that the front-end doesn't have to do any extra work!
343+
340344
var orderedGlobals = []
341345

342346
// iterating over ALL instructions (could be SLOW if not for our optimization below)
@@ -507,9 +511,8 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
507511
var val = curEntry.globals[varname];
508512
// (use '!==' to do an EXACT match against undefined)
509513
if (val !== undefined) { // might not be defined at this line, which is OKAY!
510-
tbl.append('<tr><td class="stackFrameVar"></td><td class="stackFrameValue"></td></tr>');
514+
tbl.append('<tr><td class="stackFrameVar">' + varname + '</td><td class="stackFrameValue"></td></tr>');
511515
var curTr = tbl.find('tr:last');
512-
curTr.find("td.stackFrameVar").html(varname);
513516

514517
// render primitives inline
515518
if (isPrimitiveType(val)) {
@@ -548,6 +551,8 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
548551

549552
// render locals in alphabetical order for tidiness:
550553
// TODO: later on, render locals in order of first appearance, for consistency!!!
554+
// (the back-end can actually pre-compute this list so that the
555+
// front-end doesn't have to do any extra work!)
551556
var orderedVarnames = [];
552557

553558
// use plain ole' iteration rather than jQuery $.each() since
@@ -562,17 +567,28 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
562567
$(vizDiv + " #stack #" + divID).append('<table class="stackFrameVarTable" id="' + tableID + '"></table>');
563568

564569
var tbl = $(vizDiv + " #" + tableID);
570+
571+
// put return value at the VERY END (if it exists)
572+
var retvalIdx = orderedVarnames.indexOf('__return__');
573+
if (retvalIdx >= 0) {
574+
orderedVarnames.splice(retvalIdx, 1);
575+
orderedVarnames.push('__return__');
576+
}
577+
565578
$.each(orderedVarnames, function(i, varname) {
566579
var val = localVars[varname];
567-
tbl.append('<tr><td class="stackFrameVar"></td><td class="stackFrameValue"></td></tr>');
568-
var curTr = tbl.find('tr:last');
580+
581+
// special treatment for displaying return value and indicating
582+
// that the function is about to return to its caller
569583
if (varname == '__return__') {
570-
curTr.find("td.stackFrameVar").html('<span class="retval">return value</span>');
584+
tbl.append('<tr><td class="stackFrameVar"><span class="retval">Return value:</span></td><td class="stackFrameValue"></td></tr>');
571585
}
572586
else {
573-
curTr.find("td.stackFrameVar").html(varname);
587+
tbl.append('<tr><td class="stackFrameVar">' + varname + '</td><td class="stackFrameValue"></td></tr>');
574588
}
575589

590+
var curTr = tbl.find('tr:last');
591+
576592
// render primitives inline and compound types on the heap
577593
if (isPrimitiveType(val)) {
578594
renderData(val, curTr.find("td.stackFrameValue"));
@@ -592,6 +608,7 @@ function renderDataStructuresVersion2(curEntry, vizDiv) {
592608
connectionEndpointIDs[varDivID] = heapObjID;
593609
}
594610
});
611+
595612
}
596613

597614
}

0 commit comments

Comments
 (0)