vmstack: ensure consistent ordering of internal slice#455
Open
hsslbchtop wants to merge 1 commit intomasterfrom
Open
vmstack: ensure consistent ordering of internal slice#455hsslbchtop wants to merge 1 commit intomasterfrom
hsslbchtop wants to merge 1 commit intomasterfrom
Conversation
… top of the stack)
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.
VmStack is represented as Golang slice []VmStackValue. But notion of where is the top of the stack was different on Marshalling (top of the stack is
stack[0]) and Unrmashalling (top of the stack goes tostack[len]).This PR addresses issue by changing VmStack type from slice to struct, with the []VmStackValue slice incapsulated into private property. This interface will ensure that stack is only manipulated using interface functions (Len, Peek, Put), and the underlying slice is not accessible for direct manipulation.
Migration to interface is following:
len(stack)becomesstack.Len()stack[0]was ambiguos and could have both meanining - top and bottom of the stack:stack[0]was meant to access bottom of the stack, hencePeek(len-1)should be used insteadstack[x] == Peek(x)stack := []VmStackValue{a,b,c}(in this caseameant to be the top of the stack), then Put operations in reverse order should be done:stack.Put(c); stack.Put(b); stack.Put(a)