Skip to content

Commit 7d1c151

Browse files
committed
got memory labels rendered
1 parent 4086012 commit 7d1c151

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

v3/css/pytutor.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ div.ExecutionVisualizer .vizFrame {
218218
/* Rendering of primitive types */
219219

220220
div.ExecutionVisualizer .nullObj {
221-
font-size: 8pt;
221+
// font-size: 8pt;
222222
}
223223

224224
div.ExecutionVisualizer .stringObj,
@@ -383,8 +383,8 @@ div.ExecutionVisualizer .objectIdLabel {
383383

384384
div.ExecutionVisualizer .typeLabel {
385385
font-size: 8pt;
386-
color: #222222;
387-
margin-bottom: 1px;
386+
color: #555;
387+
margin-bottom: 2px;
388388
}
389389

390390
div.ExecutionVisualizer div#stack,

v3/js/pytutor.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,10 +1947,6 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
19471947
d3DomElement.append('<div class="heapObject" id="' + heapObjID + '"></div>');
19481948
d3DomElement = myViz.domRoot.find('#' + heapObjID);
19491949

1950-
if (myViz.textualMemoryLabels) {
1951-
d3DomElement.append('<div class="objectIdLabel">id' + objID + '</div>');
1952-
}
1953-
19541950
renderedObjectIDs.set(objID, 1);
19551951

19561952
var obj = curEntry.heap[objID];
@@ -2088,19 +2084,24 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
20882084
var funcName = htmlspecialchars(obj[1]).replace('&lt;lambda&gt;', '\u03bb');
20892085
var parentFrameID = obj[2]; // optional
20902086

2087+
d3DomElement.append('<div class="typeLabel">function</div>');
2088+
20912089
if (parentFrameID) {
2092-
d3DomElement.append('<div class="funcObj">function ' + funcName + ' [parent=f'+ parentFrameID + ']</div>');
2090+
d3DomElement.append('<div class="funcObj">' + funcName + ' [parent=f'+ parentFrameID + ']</div>');
20932091
}
20942092
else {
2095-
d3DomElement.append('<div class="funcObj">function ' + funcName + '</div>');
2093+
d3DomElement.append('<div class="funcObj">' + funcName + '</div>');
20962094
}
20972095
}
20982096
else if (obj[0] == 'HEAP_PRIMITIVE') {
2099-
assert(obj.length == 2);
2097+
assert(obj.length == 3);
2098+
2099+
var typeName = obj[1];
2100+
var primitiveVal = obj[2];
21002101

2101-
var primitiveVal = obj[1];
21022102
// add a bit of padding to heap primitives, for aesthetics
21032103
d3DomElement.append('<div class="heapPrimitive"></div>');
2104+
d3DomElement.find('div.heapPrimitive').append('<div class="typeLabel">' + typeName + '</div>');
21042105
renderPrimitiveObject(primitiveVal, d3DomElement.find('div.heapPrimitive'));
21052106
}
21062107
else {
@@ -2115,6 +2116,15 @@ ExecutionVisualizer.prototype.renderDataStructures = function() {
21152116
d3DomElement.append('<div class="typeLabel">' + typeName + '</div>');
21162117
d3DomElement.append('<table class="customObjTbl"><tr><td class="customObjElt">' + strRepr + '</td></tr></table>');
21172118
}
2119+
2120+
// prepend the type label with a memory address label
2121+
if (myViz.textualMemoryLabels) {
2122+
var typeLabelPrefix = 'id' + objID + ':';
2123+
2124+
var labelD3 = d3DomElement.find('div.typeLabel');
2125+
assert(labelD3.length == 1); // everything should have exactly ONE type label
2126+
labelD3.html(typeLabelPrefix + labelD3.html());
2127+
}
21182128
}
21192129

21202130

v3/pg_encoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
# (json.dumps encodes these fine verbatim)
3939
#
4040
# If render_heap_primitives is True, then primitive values are rendered
41-
# on the heap as ['HEAP_PRIMITIVE', <value>]
41+
# on the heap as ['HEAP_PRIMITIVE', <type name>, <value>]
4242
#
4343
# Compound objects:
4444
# * list - ['LIST', elt1, elt2, elt3, ..., eltN]
@@ -219,7 +219,7 @@ def encode(self, dat, get_parent):
219219
new_obj.extend(['module', dat.__name__])
220220
elif typ in PRIMITIVE_TYPES:
221221
assert self.render_heap_primitives
222-
new_obj.extend(['HEAP_PRIMITIVE', dat])
222+
new_obj.extend(['HEAP_PRIMITIVE', type(dat).__name__, dat])
223223
else:
224224
typeStr = str(typ)
225225
m = typeRE.match(typeStr)

0 commit comments

Comments
 (0)