Skip to content

vmstack: ensure consistent ordering of internal slice#455

Open
hsslbchtop wants to merge 1 commit intomasterfrom
vmstack-constistent-slice-order
Open

vmstack: ensure consistent ordering of internal slice#455
hsslbchtop wants to merge 1 commit intomasterfrom
vmstack-constistent-slice-order

Conversation

@hsslbchtop
Copy link
Contributor

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 to stack[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) becomes stack.Len()
  • index stack[0] was ambiguos and could have both meanining - top and bottom of the stack:
    • if stack was Unmarshalled, then stack[0] was meant to access bottom of the stack, hence Peek(len-1) should be used instead
    • if stack was constructed (usually in order to be marshalled later), then stack[x] == Peek(x)
    • similarly if stack was created using slice stack := []VmStackValue{a,b,c} (in this case a meant 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants