Skip to content

Commit b18df3d

Browse files
committed
final fixes
1 parent bf86055 commit b18df3d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

posts/compiling-lisp-to-bytecode-and-running-it.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ An if-expression is compiled into these parts:
124124

125125
During execution, only one branch runs. When the conditional check is true, it increases the position by two, causing the true branch to run followed by skipping over the false branch. When the check is false, the position is incremented by one and we jump directly to the false branch.
126126

127-
There are some instructions here that we haven't seen yet. `less_than` pops two values from the stack and compares them (here, that's `1.0` and `2.0`). The true branch uses `load_var` to load a variable from the stack frame. In this case, a built-in function called `print`.
127+
There are some instructions here that we haven't seen yet. `less_than` pops two values from the stack and compares them (here, that's `1.0` and `2.0`), and the true branch uses `load_var` to load a variable from the stack frame. In this case, a built-in function called `print`.
128128

129129
In order to call a built-in function, or a closure, we use `call_lambda` followed by the number of arguments we're consuming from the stack. Here, we're passing a single argument, `1.0`.
130130

@@ -171,7 +171,9 @@ In order to represent user-defined functions, they are stored in bytecode as a c
171171

172172
When `push_closure` runs, this entire closure is pushed onto the stack, and it can then be stored in the current stack frame using `store_var`.
173173

174-
As execution enters a closure, a child stack frame is created with the arguments that were popped from the stack by `call_lambda`. The child stack frame allows local variables to be set (and discarded after the closure). If the variable isn't found in the current stack frame, the VM looks for it in parent frames, working its way up through the nested stack frames until it either finds the variable or reaches the top.
174+
A closure needs to be on the stack in order to be executed by `call_lambda`. It's pushed onto the stack by calling `load_var` on a variable that points to a closure.
175+
176+
When execution enters a closure, a child stack frame is created with the arguments that were popped from the stack by `call_lambda`. The child stack frame allows local variables to be set (and discarded after the closure). If the variable isn't found in the current stack frame, the VM looks for it in parent frames, working its way up through the nested stack frames until it either finds the variable or reaches the top.
175177

176178
```rust
177179
struct StackFrame {

0 commit comments

Comments
 (0)