Skip to content

Commit

Permalink
adding labels to DAST figures to reference them
Browse files Browse the repository at this point in the history
  • Loading branch information
adri09070 committed Aug 1, 2024
1 parent 5a178c5 commit d40d90b
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions chapters/dast/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,24 @@ interpreter := DASTInterpreter new.
interpreter initializeWithProgram: (RBParser parseExpression: 'Point x: 1 y: 2').
```

You can see the stack of AST nodes the current context still has to interpret by inspecting: `interpreter currentContext nodes`. The nodes will be interpreted from last to first.

_Node stack:_
![Initial Node stack](./figures/interpreter-example-initial-nodes.png width=70)
You can see the stack of AST nodes the current context still has to interpret by inspecting: `interpreter currentContext nodes`. The nodes will be interpreted from last to first (Figure *@fig:initial-nodes@*).

![Initial Node stack](./figures/interpreter-example-initial-nodes.png width=70&label=fig:initial-nodes)

You can see the value stack of the current context (where the interpreter pushes the values of the AST nodes it interprets) by inspecting: `interpreter currentContext stack`. It is empty at the moment because nothing has been evaluated yet.

Evaluate `interpreter stepInto` 3 times to evaluate the receiver and arguments of the `#x:y:` message being interpreted (Figure *@fig:nodes-after-into@* and *@fig:values-after-into@*).

Evaluate `interpreter stepInto` 3 times to evaluate the receiver and arguments of the `#x:y:` message being interpreted.

_New node stack:_
![Node stack after stepping into](./figures/interpreter-example-nodes-after-step-into.png width=70)
![Node stack after stepping into](./figures/interpreter-example-nodes-after-step-into.png width=70&label=fig:nodes-after-into)

_New value stack:_
![Value stack after stepping into](./figures/interpreter-example-value-stack-after-step-into.png width=70)
![Value stack after stepping into](./figures/interpreter-example-value-stack-after-step-into.png width=70&label=fig:values-after-into)


Finally, the message send itself is ready to be interpreted. If you evaluate `interpreter stepOver`, the interpreter will pop the receiver and arguments from the value stack, evaluate the message send completely, and push its value on the value stack.
Finally, the message send itself is ready to be interpreted. If you evaluate `interpreter stepOver`, the interpreter will pop the receiver and arguments from the value stack, evaluate the message send completely, and push its value on the value stack (Figure *@fig:nodes-after-over@* and *@fig:values-after-over@*).

_New node stack:_
![Node stack after stepping over](./figures/interpreter-example-nodes-after-step-over.png width=70)
![Node stack after stepping over](./figures/interpreter-example-nodes-after-step-over.png width=70&label=fig:nodes-after-over)

_New value stack:_
![Value stack after stepping over](./figures/interpreter-example-value-stack-after-step-over.png width=70 )
![Value stack after stepping over](./figures/interpreter-example-value-stack-after-step-over.png width=70&label=fig:values-after-over)

As you can see, the value of the message send is the point it created: `(1@2)`

Expand All @@ -73,34 +66,34 @@ Metacello new
#### Example

Open a class browser on the class `SindarinDebuggerTest`.
Right-click on its method `methodWithTwoAssignments`, and set a DAST breakpoint on the method via the context menu `Breakpoints > DAST breakpoint`
Right-click on its method `methodWithTwoAssignments`, and set a DAST breakpoint on the method via the context menu `Breakpoints > DAST breakpoint` (Figure *@fig:set-dast-breakpoint@*).

![Setting a DAST breakpoint on a method](./figures/debugger-example-set-dast-breakpoint.png width=70)
![Setting a DAST breakpoint on a method](./figures/debugger-example-set-dast-breakpoint.png width=70&label=fig:set-dast-breakpoint)

Then, open a playground, try to execute this code:

```Smalltalk
SindarinDebuggerTest new methodWithTwoAssignments
```

This will open the DASTDebugger on the method `SindarinDebuggerTest>>#methodWithTwoAssignments`:
This will open the `DASTDebugger` on the method `SindarinDebuggerTest>>#methodWithTwoAssignments` (Figure *@fig:dast-debugger-opening@*).

![DASTDebugger opening](./figures/debugger-example-dast-debugger-open.png width=70)
![DASTDebugger opening](./figures/debugger-example-dast-debugger-open.png width=70&label=fig:dast-debugger-opening)

You can observe what the interpreter does if you click on _Step over_ 7 times.
This will execute all code related to the next 7 AST nodes that has bytecodes associated to it.
The debugger now stops on the message send `#x:y:`:
The debugger now stops on the message send `#x:y:` (Figure *@fig:dast-debugger-after-over@*).

![DASTDebugger after 7 step overs](./figures/debugger-example-after-step-over.png width=70)
![DASTDebugger after 7 step overs](./figures/debugger-example-after-step-over.png width=70&label=fig:dast-debugger-after-over)

Now, you can click on _Step_ to enter the method `Point>>#x:y:`:
Now, you can click on _Step_ to enter the method `Point>>#x:y:` (Figure *@fig:dast-debugger-after-step@*).

![DASTDebugger after step](./figures/debugger-example-after-step.png width=70)
![DASTDebugger after step](./figures/debugger-example-after-step.png width=70&label=fig:dast-debugger-after-step)

Then, it is possible to select the context `SindarinDebuggerTest>>#methodWithTwoAssignments` in the context stack and click on the _Restart_ button.
This will restart completely the execution of this context, starting from the creation of the method's temporary variables:
This will restart completely the execution of this context, starting from the creation of the method's temporary variables (Figure *@fig:dast-debugger-after-restart@*).

![DASTDebugger after restart](./figures/debugger-example-after-restart.png width=70)
![DASTDebugger after restart](./figures/debugger-example-after-restart.png width=70&label=fig:dast-debugger-after-restart)

Finally, you can click on _Proceed_, which will execute the program to the end using the DAST interpreter.

Expand All @@ -116,17 +109,17 @@ In a playground, paste this code and debug it:
^ block value + b + a
```

Click on _Over_ once in the `StDebugger` then click on the button with an exclamation mark icon in the top-right corner:
Click on _Over_ once in the `StDebugger` then click on the button with an exclamation mark icon in the top-right corner (Figure *@fig:dast-debugger-switch@*).

![Switch from StDebugger to DAST](./figures/switch-example-dast-debugger-opening.png width=90)
![Switch from StDebugger to DAST](./figures/switch-example-dast-debugger-opening.png width=90&label=fig:dast-debugger-switch)

This will close the StDebugger and open the DAST debugger on the same program, at the same instruction, which will be executed with the DAST interpreter.
This will close the `StDebugger` and open the DAST debugger on the same program, at the same instruction, which will be executed with the DAST interpreter.
Click on _Step Through_ 8 times to enter the block.
Click on _Step Over_ 17 times and on _Step Through_ again to enter the block `[ a:= a + 2. c:=c+4. b:=b+3 ]`.
Click on _Step_Over_ 10 times to stop on this instruction `b + 3`.
Now, you can click on the grey button above the context stack in the DAST debugger:
Click on _Step Over_ 10 times to stop on this instruction `b + 3`.
Now, you can click on the grey button above the context stack in the DAST debugger (Figure *@fig:stdebugger-switch@*).

![Switch from DASTDebugger to StDebugger](./figures/switch-example-stdebugger-opening.png width=70)
![Switch from DASTDebugger to StDebugger](./figures/switch-example-stdebugger-opening.png width=70&label=fig:stdebugger-switch)

This will reopen the `StDebugger` to the same instruction we have stopped to in the `DASTDebugger`.
You may now proceed the execution to terminate the program.
Expand Down

0 comments on commit d40d90b

Please sign in to comment.