You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 15d0790
Browse filesBrowse the repository at this point in the historyBrowse files
In the above example, the heap objects contained only primitives (numbers and strings), which can be directly
388
+
encoded within those objects' representations in `heap`.
389
+
390
+
But heap objects can themselves point to other heap objects. Let's look at the following example:
391
+
392
+
```python
393
+
c = (1, (2, None))
394
+
d = (1, c)
395
+
```
396
+
397
+
<ahref="http://pythontutor.com/visualize.html#code=c+%3D+(1,+(2,+None))%0Ad+%3D+(1,+c)&mode=display&cumulative=false&py=2&curInstr=2">Jump to the end</a> of execution and notice that:
398
+
399
+
-`c` points to a tuple
400
+
- the second element of that tuple points to another tuple
401
+
-`d` points to a tuple whose second element points to what `c` points to
402
+
403
+
Let's look at the execution point object that corresponds to this visualization:
404
+
405
+
```javascript
406
+
{
407
+
"ordered_globals": [
408
+
"c",
409
+
"d"
410
+
],
411
+
"stdout":"",
412
+
"func_name":"<module>",
413
+
"stack_to_render": [],
414
+
"globals": {
415
+
"c": [
416
+
"REF",
417
+
1
418
+
],
419
+
"d": [
420
+
"REF",
421
+
3
422
+
]
423
+
},
424
+
"heap": {
425
+
"1": [
426
+
"TUPLE",
427
+
1,
428
+
[
429
+
"REF",
430
+
2
431
+
]
432
+
],
433
+
"2": [
434
+
"TUPLE",
435
+
2,
436
+
null
437
+
],
438
+
"3": [
439
+
"TUPLE",
440
+
1,
441
+
[
442
+
"REF",
443
+
1
444
+
]
445
+
]
446
+
},
447
+
"line":2,
448
+
"event":"return"
449
+
}
450
+
```
451
+
452
+
What's going on here? Let's start with `globals` again. `c` points to heap object 1 (`["REF", 1]`), and `d` points
453
+
to heap object 3 (`["REF", 3]`).
454
+
455
+
Let's now look at `heap`. Heap object 1 is:
456
+
457
+
```javascript
458
+
["TUPLE", 1, ["REF", 2]]
459
+
```
460
+
461
+
What does this mean? It means that it represents a tuple whose first element is the number `1` and whose
462
+
second element is a reference (pointer) to heap object 2.
463
+
464
+
Ok let's look at heap object 2:
465
+
466
+
```javascript
467
+
["TUPLE", 2, null]
468
+
```
469
+
470
+
which corresponds to the Python tuple object `(2, None)`.
471
+
472
+
Finally, heap object 3 (which `d` points to) is:
473
+
474
+
```javascript
475
+
["TUPLE", 1, ["REF", 1]]
476
+
```
477
+
478
+
which corresponds to the Python object `(1, c)`.
479
+
480
+
The ability to put "REF" objects inside of heap objects enables an arbitrary object graph to be
0 commit comments