From 8fadd33ba6ce06ac1cd8d119f4bbf39c1634420e Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 13 Jun 2022 18:29:09 -0400 Subject: Update VM docs with fused merged-array instructions --- docs/implementation/vm.html | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'docs/implementation') diff --git a/docs/implementation/vm.html b/docs/implementation/vm.html index 7a0093db..ba2e9c84 100644 --- a/docs/implementation/vm.html +++ b/docs/implementation/vm.html @@ -114,7 +114,7 @@ 0B -ARRO +LSTO X N @@ -122,19 +122,27 @@ 0C -ARRM +LSTM X 0B N Create length-N reference list +0D +ARMO +HR +0B +N +Create length-N merged array + + 0E -ARRH +ARMM HR - - -Merge top of stack (for []) +0D +N +Create length-N merged reference list 10 @@ -405,15 +413,15 @@ 0B -ARRO +LSTO x0 xm x0 xm N total variables (m=n-1) 0B -ARRH -l a -List to array +ARMO +x0 xm [x0 xm] + 10 @@ -532,9 +540,9 @@

When a block is pushed with DFND, an instance of the block is created, with its parent frame set to be the frame of the currently-executing block. Setting the parent frame when the block is first seen, instead of when it's evaluated, is what distinguishes lexical from dynamic scoping. If it's an immediate block, it's evaluated immediately, and otherwise it's pushed onto the stack. When the block is evaluated, its frame is initialized using any arguments passed to it, the next instruction's index is pushed onto the return stack, and execution moves to the first instruction in the block. When the RETN instruction is encountered, an index is popped from the return stack and execution returns to this location. As an alternative to maintaining an explicit return stack, a block can be implemented as a native function that creates a new execution stack and returns the value in it when the RETN instruction is reached. This approach uses the implementation language's call stack for the return stack.

Local variables are manipulated with the VARO (or VARU) and VARM instructions, which load the value of a variable and a reference to it (see the next section) respectively. These instructions reference variables by frame depth and slot index. The frame depth indicates in which frame the variable is found: the current frame has depth 0, its block's parent frame has depth 1, and so on. The slot index is an index within that frame.

Slots should be initialized with some indication they are not yet defined. The variable can be defined with SETN only if it hasn't been defined yet, and can be accessed with VARO or VARU or modified with SETU, SETM, or SETC only if it has been defined.

-

Variable references: ARRM ARRH VARM SETN SETU SETM SETC

+

Variable references: LSTM ARMM VARM SETN SETU SETM SETC

A variable reference indicates a particular frame slot in a way that's independent of the execution context. For example, it could be a pointer to the slot, or a reference to the frame along with the index of the slot. VARM pushes a variable reference to the stack.

-

A reference list is a list of variable references or reference lists. It's created with the ARRM instruction. In the Javascript VM there's no difference between a reference list and an ordinary BQN list other than the contents. The ARRH instruction converts this to a merged reference list, which matches an array of rank 1 or more by splitting it into cells.

+

A reference list is a list of variable references or reference lists. It's created with the LSTM instruction. In the Javascript VM there's no difference between a reference list and an ordinary BQN list other than the contents. The ARMM instruction makes a merged reference list, which matches an array of rank 1 or more by splitting it into cells.

The SETN, SETU, SETM, and SETC instructions set a value for a reference. If the reference is to a variable, they simply set its value. For a reference list, the value needs to be destructured. It must be a list of the same length, and each reference in the reference list is set to the corresponding element of the value list.

SETM and SETC additionally need to get the current value of a reference. For a variable reference this is its current value (with an error if it's not defined yet); for a reference list it's a list of the values of each reference in the list.

-- cgit v1.2.3