github.com/avicd/go-utilx@v0.1.0/evalx/stack.go (about)

     1  package evalx
     2  
     3  import "github.com/avicd/go-utilx/datax"
     4  
     5  type Target = uint
     6  
     7  const (
     8  	PROPERTY Target = iota
     9  	METHOD
    10  )
    11  
    12  type Stack struct {
    13  	Ctx    Context
    14  	Target datax.LinkedList[Target]
    15  	Error  error
    16  	X      any
    17  	Y      any
    18  }
    19  
    20  func StackOf(accessor Context) *Stack {
    21  	return &Stack{Ctx: accessor}
    22  }
    23  
    24  func (it *Stack) PushTarget(target Target) {
    25  	it.Target.Push(target)
    26  }
    27  
    28  func (it *Stack) PopTarget() Target {
    29  	if val, ok := it.Target.Pop(); ok {
    30  		return val
    31  	}
    32  	return PROPERTY
    33  }