From df051fd643d19efc6a4fc98ce7cdc8fe43b33d5e Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sun, 23 Feb 2020 21:20:32 -0800 Subject: [PATCH] Fix n vs n-1 mistake --- content/blog/05_compiler_execution.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/blog/05_compiler_execution.md b/content/blog/05_compiler_execution.md index 73c21e6..7563f20 100644 --- a/content/blog/05_compiler_execution.md +++ b/content/blog/05_compiler_execution.md @@ -334,10 +334,10 @@ code for the global function: {{< gmachine "Unwind-Global" >}} {{< gmachine_inner "Before">}} - \( \text{Unwind} : i \quad a, a_0, a_1, ..., a_n : s \quad d \quad h[\substack{a : \text{NGlobal} \; n \; c \\ a_k : \text{NApp} \; a_{k-1} \; a_k'}] \quad m \) + \( \text{Unwind} : i \quad a, a_0, a_1, ..., a_{n-1} : s \quad d \quad h[\substack{a : \text{NGlobal} \; n \; c \\ a_k : \text{NApp} \; a_{k-1} \; a_k'}] \quad m \) {{< /gmachine_inner >}} {{< gmachine_inner "After" >}} - \( c \quad a_0', a_1', ..., a_n', a_n : s \quad d \quad h[\substack{a : \text{NGlobal} \; n \; c \\ a_k : \text{NApp} \; a_{k-1} \; a_k'}] \quad m \) + \( c \quad a_0', a_1', ..., a_{n-1}', a_{n-1} : s \quad d \quad h[\substack{a : \text{NGlobal} \; n \; c \\ a_k : \text{NApp} \; a_{k-1} \; a_k'}] \quad m \) {{< /gmachine_inner >}} {{< gmachine_inner "Description" >}} Call a global function. @@ -345,12 +345,12 @@ code for the global function: {{< /gmachine >}} In this rule, we used a general rule for \\(a\_k\\), in which \\(k\\) is any number -between 0 and \\(n\\). We also expect the `NGlobal` node to contain two parameters, +between 1 and \\(n-1\\). We also expect the `NGlobal` node to contain two parameters, \\(n\\) and \\(c\\). \\(n\\) is the arity of the function (the number of arguments it expects), and \\(c\\) are the instructions to construct the function's tree. -The attentive reader will have noticed a catch: we kept \\(a\_n\\) on the stack! -This once again goes back to replacing a node in-place. \\(a\_n\\) is the address of the "root" of the +The attentive reader will have noticed a catch: we kept \\(a\_{n-1}\\) on the stack! +This once again goes back to replacing a node in-place. \\(a\_{n-1}\\) is the address of the "root" of the whole expression we're simplifying. Thus, to replace the value at this address, we need to keep the address until we have something to replace it with.