Skip to content

Commit a738cd0

Browse files
committed
Docstring and istoplevel improvements
1 parent b888b2f commit a738cd0

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

docs/src/dev_reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ JuliaInterpreter.evaluate_call!
4343
JuliaInterpreter.evaluate_foreigncall
4444
JuliaInterpreter.maybe_evaluate_builtin
4545
JuliaInterpreter.maybe_next_call!
46+
JuliaInterpreter.next_line!
47+
JuliaInterpreter.maybe_step_through_wrapper!
4648
JuliaInterpreter.handle_err
4749
```
4850

src/commands.jl

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
2-
ret = finish!(recurse, frame, istoplevel=false)
3-
ret = finish!(frame, istoplevel=false)
2+
pc = finish!(recurse, frame, istoplevel=false)
3+
pc = finish!(frame, istoplevel=false)
44
5-
Run `frame` until execution terminates. `ret` is either `nothing` (if execution terminates
5+
Run `frame` until execution terminates. `pc` is either `nothing` (if execution terminates
66
when it hits a `return` statement) or a reference to a breakpoint.
77
In the latter case, `leaf(frame)` returns the frame in which it hit the breakpoint.
88
@@ -22,8 +22,8 @@ finish!(frame::Frame, istoplevel::Bool=false) = finish!(finish_and_return!, fram
2222
ret = finish_and_return!(recurse, frame, istoplevel::Bool=false)
2323
ret = finish_and_return!(frame, istoplevel::Bool=false)
2424
25-
Call [`JuliaInterpreter.finish!`](@ref) and pass back the return value. If execution
26-
pauses at a breakpoint, the reference to the breakpoint is returned.
25+
Call [`JuliaInterpreter.finish!`](@ref) and pass back the return value `ret`. If execution
26+
pauses at a breakpoint, `ret` is the reference to the breakpoint.
2727
"""
2828
function finish_and_return!(@nospecialize(recurse), frame::Frame, istoplevel::Bool=false)
2929
pc = finish!(recurse, frame, istoplevel)
@@ -33,26 +33,29 @@ end
3333
finish_and_return!(frame::Frame, istoplevel::Bool=false) = finish_and_return!(finish_and_return!, frame, istoplevel)
3434

3535
"""
36-
bpref = dummy_breakpoint(recurse, frame::Frame)
36+
bpref = dummy_breakpoint(recurse, frame::Frame, istoplevel)
3737
38-
Return a fake breakpoint. This can be useful as the `recurse` argument to `evaluate_call!`
39-
(or any of the higher-order commands) to ensure that you return immediately after stepping
40-
into a call.
38+
Return a fake breakpoint. `dummy_breakpoint` can be useful as the `recurse` argument to
39+
`evaluate_call!` (or any of the higher-order commands) to ensure that you return immediately
40+
after stepping into a call.
4141
"""
42-
dummy_breakpoint(@nospecialize(recurse), frame::Frame) = BreakpointRef(frame.framecode, 0)
42+
dummy_breakpoint(@nospecialize(recurse), frame::Frame, istoplevel) = BreakpointRef(frame.framecode, 0)
4343

4444
"""
45-
ret = finish_stack!(recurse, frame, istoplevel=false)
46-
ret = finish_stack!(frame, istoplevel=false)
45+
ret = finish_stack!(recurse, frame, rootistoplevel=false)
46+
ret = finish_stack!(frame, rootistoplevel=false)
4747
4848
Unwind the callees of `frame`, finishing each before returning to the caller.
49-
`frame` itself is also finished
50-
If execution hits a breakpoint, `ret` will be a reference to the breakpoint.
49+
`frame` itself is also finished. `rootistoplevel` should be true if the root frame is top-level.
50+
51+
`ret` is typically the returned value. If execution hits a breakpoint, `ret` will be a
52+
reference to the breakpoint.
5153
"""
52-
function finish_stack!(@nospecialize(recurse), frame::Frame, istoplevel::Bool=false)
54+
function finish_stack!(@nospecialize(recurse), frame::Frame, rootistoplevel::Bool=false)
5355
frame0 = frame
5456
frame = leaf(frame)
5557
while true
58+
istoplevel = rootistoplevel && frame.caller === nothing
5659
ret = finish_and_return!(recurse, frame, istoplevel)
5760
isa(ret, BreakpointRef) && return ret
5861
frame === frame0 && return ret
@@ -93,14 +96,22 @@ end
9396
next_until!(predicate, frame::Frame, istoplevel::Bool=false) =
9497
next_until!(predicate, finish_and_return!, frame, istoplevel)
9598

99+
"""
100+
pc = next_call!(recurse, frame, istoplevel=false)
101+
pc = next_call!(frame, istoplevel=false)
102+
103+
Execute the current statement. Continue stepping through `frame` until the next
104+
`:return` or `:call` expression.
105+
"""
96106
next_call!(@nospecialize(recurse), frame::Frame, istoplevel::Bool=false) =
97107
next_until!(is_call_or_return, recurse, frame, istoplevel)
98108
next_call!(frame::Frame, istoplevel::Bool=false) = next_call!(finish_and_return!, frame, istoplevel)
99109

100110
"""
101-
maybe_next_call!(predicate, frame, istoplevel=false)
111+
pc = maybe_next_call!(recurse, frame, istoplevel=false)
112+
pc = maybe_next_call!(frame, istoplevel=false)
102113
103-
Return the current statement of `frame` if it is a `:return` or `:call` expression.
114+
Return the current program counter of `frame` if it is a `:return` or `:call` expression.
104115
Otherwise, step through the statements of `frame` until the next `:return` or `:call` expression.
105116
"""
106117
function maybe_next_call!(@nospecialize(recurse), frame::Frame, istoplevel::Bool=false)
@@ -112,8 +123,8 @@ maybe_next_call!(frame::Frame, istoplevel::Bool=false) =
112123
maybe_next_call!(finish_and_return!, frame, istoplevel)
113124

114125
"""
115-
through_methoddef_or_done!(recurse, frame)
116-
through_methoddef_or_done!(frame)
126+
pc = through_methoddef_or_done!(recurse, frame)
127+
pc = through_methoddef_or_done!(frame)
117128
118129
Runs `frame` at top level until it either finishes (e.g., hits a `return` statement)
119130
or defines a new method.
@@ -144,6 +155,15 @@ function changed_line!(expr, line, fls)
144155
end
145156
end
146157

158+
"""
159+
pc = next_line!(recurse, frame, istoplevel=false)
160+
pc = next_line!(frame, istoplevel=false)
161+
162+
Execute until reaching the first call of the next line of the source code.
163+
Upon return, `pc` is either the new program counter, `nothing` if a `return` is reached,
164+
or a `BreakpointRef` if it encountered a wrapper call. In the latter case, call `leaf(frame)`
165+
to obtain the new execution frame.
166+
"""
147167
function next_line!(@nospecialize(recurse), frame::Frame, istoplevel::Bool=false)
148168
initial = linenumber(frame)
149169
first = true

0 commit comments

Comments
 (0)