Skip to content

Commit a7a05f6

Browse files
committed
Merge branch 'master' of github.com:pgbovine/OnlinePythonTutor
2 parents 4f0094d + 8dbbb67 commit a7a05f6

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

‎v3/docs/opt-trace-format.md‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,35 @@ However, you'll see in the "Closures and Zombie Frames" section why `unique_hash
741741
Finally, ignore `is_parent`, `is_zombie`, and `parent_frame_id_list` for now. We'll cover those in the more advanced
742742
"Closures and Zombie Frames" section below.
743743

744+
## Event types
745+
746+
The `event` field can either be:
747+
748+
- `step_line` - ordinary single step. most trace entries will be of this type.
749+
- `call` - first line during an executed function call; very important to match with corresponding `return` for visualization to work properly ... every frame should have matching `call` and `return` entries.
750+
- `return` - about to return from a function, usually the `__return__` value is set at this point in the proper stack frame entry.
751+
- `exception` and `uncaught_exception` - when an exception happens - the `exception_msg` field should be set to a reasonable error message. use `uncaught_exception` at the top-level of the tracer to indicate what happens when the user's program itself didn't catch the exception, and a regular `exception` when the user's program throws an exception (which might be caught in another part of their program). If the trace has exactly 1 entry and it's an `uncaught_exception`, then the OPT frontend doesn't switch to the visualization at all ... instead it displays a "syntax error"-like thingy in the code editor. It will highlight the faulting line, indicated by the `line` field and display `exception_msg` there. So if you want to indicate a syntax error, then create a trace with exactly ONE entry that's an `uncaught_exception`. (If there's more than one trace entry and the last one happens to be `uncaught_exception`, then OPT will display the visualization as usual and then show the error when the user navigates to the final execution point.)
752+
- `instruction_limit_reached` - if you want to cap execution at a certain limit (e.g., 300 executed steps), issue this special event at the end. fill in the `exception_msg` field to say something like "(stopped after N steps to prevent possible infinite loop)"
753+
744754

745755
## Closures and Zombie Frames (advanced)
746756

747-
(TODO: WRITE ME!)
757+
As soon as a function becomes the parent of another function (i.e., a nested function is defined inside of it), set the `is_parent` field of its stack entry to `true`. Also change its `unique_hash` by appending `_p` to it. The reason why we want to change `unique_hash` is that we want the frontend to *refresh* its display, and d3 might not refresh if it sees that the hash is identical to the prior frame. Conceptually, we want `unique_hash` to be different for a function before and after it turns into the parent of another function since we want to display it differently.
758+
759+
For example, when function `foo` is executing, its frame will have `is_parent=false` and `unique_hash = foo_f1` (or something similar) when its first two lines are running to define `x` and `y`, respectively. Then when its third line executes, that defines `bar` as a nested function within itself, so at that step, `foo` should have `is_parent=true` and `unique_hash = foo_f1_p` (or something similar).
760+
761+
```python
762+
def foo(y):
763+
x = 10
764+
y = 20
765+
def bar(x):
766+
return x + y
767+
768+
foo(1)
769+
```
770+
771+
[TODO: talk about `parent_frame_id_list`]
772+
773+
[TODO: talk about appending `_z` onto `unique_hash` when the frame becomes a zombie.]
748774

749-
(TODO: talk about needing to append `_p` and `_z` onto `unique_hash` when a frame becomes a parent or zombie,
750-
respectively, since the frontend needs to know when to refresh the display.)
775+
[TODO: IMPROVE ME!]

0 commit comments

Comments
 (0)