Skip to content

Commit 21d01bf

Browse files
committed
Implement UNPACK_SEQUENCE
1 parent e1f060c commit 21d01bf

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

‎vm/eval.go‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func (vm *Vm) PUSH(obj py.Object){
7474
vm.frame.Stack=append(vm.frame.Stack, obj)
7575
}
7676

77+
// Push items to top of vm stack
78+
func (vm*Vm) EXTEND(items py.Tuple){
79+
vm.frame.Stack=append(vm.frame.Stack, items...)
80+
}
81+
7782
// Adds a traceback to the exc passed in for the current vm state
7883
func (vm*Vm) AddTraceback(exc*py.ExceptionInfo){
7984
exc.Traceback=&py.Traceback{
@@ -725,7 +730,20 @@ func do_DELETE_NAME(vm *Vm, namei int32){
725730
// stack right-to-left.
726731
funcdo_UNPACK_SEQUENCE(vm*Vm, countint32){
727732
defervm.CheckException()
728-
vm.NotImplemented("UNPACK_SEQUENCE", count)
733+
it:=vm.POP()
734+
i:=count
735+
items:=make(py.Tuple, count)
736+
py.Iterate(it, func(item py.Object){
737+
i--
738+
ifi<0{
739+
panic(py.ExceptionNewf(py.ValueError, "Too many values to unpack (expected %d)", count))
740+
}
741+
items[i] =item
742+
})
743+
ifi!=0{
744+
panic(py.ExceptionNewf(py.ValueError, "Need more than %d values to unpack (expected %d)", count-i, count))
745+
}
746+
vm.EXTEND(items)
729747
}
730748

731749
// Implements TOS.name = TOS1, where namei is the index of name in

0 commit comments

Comments
(0)