@@ -127,10 +127,20 @@ The examples above trace simple straight-line code. Real programs
127127make function calls. ** invoke** and ** return** contexts let a
128128debugger follow execution across function boundaries.
129129
130- Consider a contract with an internal ` add ` function:
130+ Click ** "Try it"** on the example below, then step through the
131+ trace. Watch for ** invoke** contexts on the JUMP into ` add ` and
132+ ** return** contexts on the JUMP back to the caller:
131133
132- ```
133- name Adder;
134+ <TraceExample
135+ title = " Function call and return"
136+ description = " Calls an internal add function and stores the result"
137+ source = { ` name Adder;
138+
139+ define {
140+ function add(a: uint256, b: uint256) -> uint256 {
141+ return a + b;
142+ };
143+ }
134144
135145storage {
136146 [0] result: uint256;
@@ -140,28 +150,24 @@ create {
140150 result = 0;
141151}
142152
143- func add(a: uint256, b: uint256) -> uint256 {
144- return a + b;
145- }
146-
147153code {
148154 result = add(3, 4);
149- }
150- ```
155+ } ` }
156+ />
151157
152- The compiler produces a sequence of instructions. The relevant
153- instructions look like this (offsets are illustrative):
158+ As you step through, three phases are visible:
154159
155160### Before the call — setting up arguments
156161
157162At the call site, the compiler pushes arguments onto the stack and
158- prepares the jump. The instruction at the JUMP has an ** invoke**
159- context:
163+ prepares the jump. The JUMP instruction carries an ** invoke**
164+ context identifying the function, its target, and the argument
165+ locations:
160166
161167<SchemaExample
162168 schema = " program/context/function/invoke"
163169 href = " /spec/program/context/function/invoke"
164- title = " Instruction at call site ( JUMP) "
170+ title = " Invoke context on the JUMP"
165171>
166172 { ` {
167173 "invoke": {
@@ -195,13 +201,13 @@ variables.
195201
196202### Returning — the result
197203
198- When ` add ` finishes, the JUMP back to the caller has a ** return **
199- context:
204+ When ` add ` finishes, the JUMP back to the caller carries a
205+ ** return ** context with a pointer to the result :
200206
201207<SchemaExample
202208 schema = " program/context/function/return"
203209 href = " /spec/program/context/function/return"
204- title = " Instruction at return site ( JUMP) "
210+ title = " Return context on the JUMP back "
205211>
206212 { ` {
207213 "return": {
0 commit comments