Skip to content

Commit dc85f25

Browse files
committed
Make function call tracing example interactive
Replace the static BUG code block with an interactive TraceExample component that lets readers compile and step through the Adder contract, seeing invoke/return contexts at function boundaries. Static SchemaExample blocks are kept for the narrative walkthrough and for external call/revert examples (which BUG can't demonstrate).
1 parent da7f541 commit dc85f25

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

packages/web/docs/core-schemas/programs/tracing.mdx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,20 @@ The examples above trace simple straight-line code. Real programs
127127
make function calls. **invoke** and **return** contexts let a
128128
debugger 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
135145
storage {
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-
147153
code {
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

157162
At 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

Comments
 (0)