Implement for-range statement on arrays

This commit is contained in:
Marc Vertes
2018-02-14 16:31:49 +01:00
parent 11795336f5
commit b5af29ca57
3 changed files with 51 additions and 5 deletions

View File

@@ -142,3 +142,18 @@ func arrayLit(n *Node, f *Frame) {
}
(*f)[n.findex] = a
}
func _range(n *Node, f *Frame) {
i, index := 0, n.Child[0].findex
if (*f)[index] != nil {
i = (*f)[index].(int)
}
a := value(n.Child[2], f).([]interface{})
if i >= len(a) {
(*f)[n.findex] = false
return
}
(*f)[index] = i + 1
(*f)[n.Child[1].findex] = a[i]
(*f)[n.findex] = true
}