From 60925955a77b4f31b5308e1ceb6d71d055b17b06 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 28 Oct 2021 17:41:28 -0400 Subject: Add table for SET opcode behavior --- docs/implementation/vm.html | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'docs/implementation/vm.html') diff --git a/docs/implementation/vm.html b/docs/implementation/vm.html index d25e39a1..629c883e 100644 --- a/docs/implementation/vm.html +++ b/docs/implementation/vm.html @@ -516,6 +516,37 @@

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 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.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OpcodeSlot must beReads value first
SETNUnset
SETUSet
SETMSetYes
SETCSetYes

Bodies: SETH VFYM PRED

SETH is a modification of SETN for use in header destructuring. It differs in that it doesn't place its result on the stack (making it more like SETN followed by POPS), and that if the assignment fails because the reference and value don't conform then it moves on to the next eligible body in the block rather than giving an error. VFYM converts a BQN value c to a special reference: assigning a value v to it should check if vc but do no assignment. Only SETH needs to accept these references, and it should treat non-matching values as failing assignment.

PRED drops the top value of the stack, but also checks whether it matches the number 1. If it does match, execution continues; if not, evaluation of the current body ends and evaluation moves to the next eligible body.

-- cgit v1.2.3