Skip to content

Commit f013956

Browse files
committed
added zip.__reduce__
1 parent 3cda2d4 commit f013956

File tree

1 file changed

+15
-0
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator

1 file changed

+15
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/PZipBuiltins.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@
2727

2828
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ITER__;
2929
import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEXT__;
30+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REDUCE__;
3031

3132
import java.util.List;
3233

3334
import com.oracle.graal.python.builtins.Builtin;
3435
import com.oracle.graal.python.builtins.CoreFunctions;
3536
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
3637
import com.oracle.graal.python.builtins.PythonBuiltins;
38+
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
3739
import com.oracle.graal.python.nodes.control.GetNextNode;
3840
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
3941
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
42+
import com.oracle.graal.python.nodes.object.GetClassNode;
4043
import com.oracle.graal.python.runtime.exception.PythonErrorType;
4144
import com.oracle.truffle.api.dsl.Cached;
4245
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -82,4 +85,16 @@ static Object doPZip(PZip self) {
8285
return self;
8386
}
8487
}
88+
89+
@Builtin(name = __REDUCE__, minNumOfPositionalArgs = 1)
90+
@GenerateNodeFactory
91+
public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
92+
@Specialization
93+
Object reducePos(PZip self,
94+
@Cached GetClassNode getClass) {
95+
Object type = getClass.execute(self);
96+
PTuple tuple = factory().createTuple(self.getIterators());
97+
return factory().createTuple(new Object[]{type, tuple});
98+
}
99+
}
85100
}

0 commit comments

Comments
 (0)