mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
27 lines
439 B
Go
27 lines
439 B
Go
package vm
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/formancehq/ledger/internal/machine"
|
|
)
|
|
|
|
func (m *Machine) popValue() machine.Value {
|
|
l := len(m.Stack)
|
|
x := m.Stack[l-1]
|
|
m.Stack = m.Stack[:l-1]
|
|
return x
|
|
}
|
|
|
|
func pop[T machine.Value](m *Machine) T {
|
|
x := m.popValue()
|
|
if v, ok := x.(T); ok {
|
|
return v
|
|
}
|
|
panic(fmt.Errorf("unexpected type '%T' on stack", x))
|
|
}
|
|
|
|
func (m *Machine) pushValue(v machine.Value) {
|
|
m.Stack = append(m.Stack, v)
|
|
}
|