format: fix the program example's pre-execution stack pointers#278
Open
gnidan wants to merge 1 commit into
Open
format: fix the program example's pre-execution stack pointers#278gnidan wants to merge 1 commit into
gnidan wants to merge 1 commit into
Conversation
The Incrementer example annotated its stack-resident local against post-execution machine state, contradicting the pointer convention the instruction schema declares: a context's pointers describe the state a debugger observes when stopped at the instruction, before it executes. Reworked the example to that convention. localValue (produced by the SLOAD at offset 1) is first observable at offset 2, where the pre-execution stack holds it at the top (slot 0); at offset 4 it sits one below the PUSH1 result (slot 1) and is then consumed by ADD, so it is no longer in scope at offsets 5-6. Previously it was shown live on the stack after ADD, which would have made a debugger display it off by one. Also drops a stale 'value = tmp;' line left over from an earlier naming of the pseudo-code.
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
Incrementerexample inprogram.schema.yamlsizes its stack-resident local against post-execution machine state, contradicting the pointer convention the instruction schema declares.Convention (
program/instruction.schema.yaml, and theinvokeschema'sInternalCallnote): a context's pointers describe the machine state a debugger observes when it is stopped at the instruction — that is, before the instruction executes. Stackslotcounts from the top of that pre-execution stack.Applying that convention to
let localValue = storedValue; storedValue += 1;(call bytecode), the pre-execution stack at each instruction is:PUSH0SLOAD[0x00]PUSH1 0x01[localValue]ADD[localValue, 0x01]PUSH0[storedValue+1]SSTORE[storedValue+1, 0x00]So
localValueis observable only at offsets 2 and 4. It first appears at offset 2 — one step after theSLOADthat computes it, because its value is not on the stack at theSLOADtrace step itself — and is gone onceADDconsumes it. The previous example placed it at slot 0 as early as offset 1 and kept it live through offset 5, which would make a debugger display it off by one.storedValuestays at storage slot 0 throughout.Per-offset stack notes are inlined so the slot math is checkable against the ops, and a stale
value = tmp;line (a leftover from an earlier naming of the pseudo-code) is removed.Schema example and validity tests pass.