Skip to content

vmstack: ensure consistent ordering of internal slice#455

Merged
hsslbchtop merged 1 commit into
masterfrom
vmstack-constistent-slice-order
Apr 14, 2026
Merged

vmstack: ensure consistent ordering of internal slice#455
hsslbchtop merged 1 commit into
masterfrom
vmstack-constistent-slice-order

Conversation

@hsslbchtop
Copy link
Copy Markdown
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)

@hsslbchtop hsslbchtop force-pushed the vmstack-constistent-slice-order branch 4 times, most recently from 4702b72 to 2c2f2fd Compare April 14, 2026 16:45
@hsslbchtop hsslbchtop force-pushed the vmstack-constistent-slice-order branch from 2c2f2fd to c0208c0 Compare April 14, 2026 16:50
@hsslbchtop hsslbchtop force-pushed the vmstack-constistent-slice-order branch from c0208c0 to 8753457 Compare April 14, 2026 17:04
@hsslbchtop hsslbchtop merged commit 4a73e4b into master Apr 14, 2026
1 check failed
@hsslbchtop hsslbchtop deleted the vmstack-constistent-slice-order branch April 14, 2026 17:05
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.

3 participants