2019-11-13 11:34:03 +00:00
|
|
|
package vm
|
|
|
|
|
|
|
|
type (
|
|
|
|
enumerator interface {
|
|
|
|
Next() bool
|
|
|
|
Value() StackItem
|
|
|
|
}
|
|
|
|
|
|
|
|
arrayWrapper struct {
|
|
|
|
index int
|
|
|
|
value []StackItem
|
|
|
|
}
|
|
|
|
|
|
|
|
concatEnum struct {
|
|
|
|
current enumerator
|
|
|
|
second enumerator
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2019-11-13 12:29:27 +00:00
|
|
|
type (
|
|
|
|
iterator interface {
|
|
|
|
enumerator
|
|
|
|
Key() StackItem
|
|
|
|
}
|
|
|
|
|
|
|
|
mapWrapper struct {
|
|
|
|
index int
|
2020-03-31 10:30:38 +00:00
|
|
|
m []MapElement
|
2019-11-13 12:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
concatIter struct {
|
|
|
|
current iterator
|
|
|
|
second iterator
|
|
|
|
}
|
|
|
|
|
|
|
|
keysWrapper struct {
|
|
|
|
iter iterator
|
|
|
|
}
|
|
|
|
|
|
|
|
valuesWrapper struct {
|
|
|
|
iter iterator
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2019-11-13 11:34:03 +00:00
|
|
|
func (a *arrayWrapper) Next() bool {
|
|
|
|
if next := a.index + 1; next < len(a.value) {
|
|
|
|
a.index = next
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *arrayWrapper) Value() StackItem {
|
|
|
|
return a.value[a.index]
|
|
|
|
}
|
|
|
|
|
2019-11-13 12:29:27 +00:00
|
|
|
func (a *arrayWrapper) Key() StackItem {
|
|
|
|
return makeStackItem(a.index)
|
|
|
|
}
|
|
|
|
|
2019-11-13 11:34:03 +00:00
|
|
|
func (c *concatEnum) Next() bool {
|
|
|
|
if c.current.Next() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
c.current = c.second
|
|
|
|
|
|
|
|
return c.current.Next()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *concatEnum) Value() StackItem {
|
|
|
|
return c.current.Value()
|
|
|
|
}
|
2019-11-13 12:29:27 +00:00
|
|
|
|
|
|
|
func (i *concatIter) Next() bool {
|
|
|
|
if i.current.Next() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
i.current = i.second
|
|
|
|
|
|
|
|
return i.second.Next()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *concatIter) Value() StackItem {
|
|
|
|
return i.current.Value()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *concatIter) Key() StackItem {
|
|
|
|
return i.current.Key()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mapWrapper) Next() bool {
|
2020-03-31 10:30:38 +00:00
|
|
|
if next := m.index + 1; next < len(m.m) {
|
2019-11-13 12:29:27 +00:00
|
|
|
m.index = next
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mapWrapper) Value() StackItem {
|
2020-03-31 10:30:38 +00:00
|
|
|
return m.m[m.index].Value
|
2019-11-13 12:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mapWrapper) Key() StackItem {
|
2020-03-31 10:30:38 +00:00
|
|
|
return m.m[m.index].Key
|
2019-11-13 12:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e *keysWrapper) Next() bool {
|
|
|
|
return e.iter.Next()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *keysWrapper) Value() StackItem {
|
|
|
|
return e.iter.Key()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *valuesWrapper) Next() bool {
|
|
|
|
return e.iter.Next()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *valuesWrapper) Value() StackItem {
|
|
|
|
return e.iter.Value()
|
|
|
|
}
|