vm: properly convert arrays to stackItems
They should be arrays of stackItems, not arrays of values.
This commit is contained in:
parent
d04bc0cbe3
commit
f3ed91a1f7
1 changed files with 25 additions and 4 deletions
|
@ -9,13 +9,34 @@ type stackItem struct {
|
|||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
func appendToItems(items *[]stackItem, val StackItem, seen map[StackItem]bool) {
|
||||
if arr, ok := val.Value().([]StackItem); ok {
|
||||
if seen[val] {
|
||||
return
|
||||
}
|
||||
seen[val] = true
|
||||
intItems := make([]stackItem, 0, len(arr))
|
||||
for _, v := range arr {
|
||||
appendToItems(&intItems, v, seen)
|
||||
}
|
||||
*items = append(*items, stackItem{
|
||||
Value: intItems,
|
||||
Type: val.String(),
|
||||
})
|
||||
|
||||
} else {
|
||||
*items = append(*items, stackItem{
|
||||
Value: val,
|
||||
Type: val.String(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func stackToArray(s *Stack) []stackItem {
|
||||
items := make([]stackItem, 0, s.Len())
|
||||
seen := make(map[StackItem]bool)
|
||||
s.Iter(func(e *Element) {
|
||||
items = append(items, stackItem{
|
||||
Value: e.value,
|
||||
Type: e.value.String(),
|
||||
})
|
||||
appendToItems(&items, e.value, seen)
|
||||
})
|
||||
return items
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue