From 60cc72634c4d8762046f3600dcdd39dd48745a68 Mon Sep 17 00:00:00 2001 From: gnsxun Date: Sun, 22 May 2022 11:02:35 +0900 Subject: [PATCH 1/4] Add count.reduce() --- vm/src/stdlib/itertools.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index bd4de3ce0a4..a2c6094f8d8 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -193,7 +193,12 @@ mod decl { } #[pyimpl(with(IterNext, Constructor))] - impl PyItertoolsCount {} + impl PyItertoolsCount { + #[pymethod(magic)] + fn reduce(&self, vm: &VirtualMachine) -> (PyTypeRef, BigInt) { + (vm.ctx.types.map_type.clone(), self.cur.read().clone()) + } + } impl IterNextIterable for PyItertoolsCount {} impl IterNext for PyItertoolsCount { fn next(zelf: &Py, vm: &VirtualMachine) -> PyResult { From 777cdc691dc26b388601e21d62421ff181cf2a83 Mon Sep 17 00:00:00 2001 From: gnsxun Date: Sun, 22 May 2022 14:10:14 +0900 Subject: [PATCH 2/4] change reduce() return type --- vm/src/stdlib/itertools.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index a2c6094f8d8..e2ee18c5e6e 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -195,8 +195,8 @@ mod decl { #[pyimpl(with(IterNext, Constructor))] impl PyItertoolsCount { #[pymethod(magic)] - fn reduce(&self, vm: &VirtualMachine) -> (PyTypeRef, BigInt) { - (vm.ctx.types.map_type.clone(), self.cur.read().clone()) + fn reduce(zelf: PyRef, vm: &VirtualMachine) -> (PyTypeRef, (BigInt,)) { + (zelf.class().clone(), (zelf.cur.read().clone(),)) } } impl IterNextIterable for PyItertoolsCount {} From bda6328318863a277d6564a979fe62badeede1f4 Mon Sep 17 00:00:00 2001 From: gnsxun Date: Sun, 22 May 2022 14:26:12 +0900 Subject: [PATCH 3/4] add comment future occur --- vm/src/stdlib/itertools.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index e2ee18c5e6e..daabf1f9040 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -194,8 +194,12 @@ mod decl { #[pyimpl(with(IterNext, Constructor))] impl PyItertoolsCount { + + // TODO: Implement this + // if (lz->cnt == PY_SSIZE_T_MAX) + // return Py_BuildValue("0(00)", Py_TYPE(lz), lz->long_cnt, lz->long_step); #[pymethod(magic)] - fn reduce(zelf: PyRef, vm: &VirtualMachine) -> (PyTypeRef, (BigInt,)) { + fn reduce(zelf: PyRef) -> (PyTypeRef, (BigInt,)) { (zelf.class().clone(), (zelf.cur.read().clone(),)) } } @@ -308,6 +312,7 @@ mod decl { Ok(*times.read()) } + #[pymethod(magic)] fn reduce(zelf: PyRef, vm: &VirtualMachine) -> PyResult { let cls = zelf.class().clone(); From cbd64581f1191660443a337b5da61e4ba5be3aa9 Mon Sep 17 00:00:00 2001 From: gnsxun Date: Mon, 23 May 2022 00:09:17 +0900 Subject: [PATCH 4/4] change the format. --- vm/src/stdlib/itertools.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index daabf1f9040..cad3dca66e2 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -194,7 +194,6 @@ mod decl { #[pyimpl(with(IterNext, Constructor))] impl PyItertoolsCount { - // TODO: Implement this // if (lz->cnt == PY_SSIZE_T_MAX) // return Py_BuildValue("0(00)", Py_TYPE(lz), lz->long_cnt, lz->long_step); @@ -312,7 +311,6 @@ mod decl { Ok(*times.read()) } - #[pymethod(magic)] fn reduce(zelf: PyRef, vm: &VirtualMachine) -> PyResult { let cls = zelf.class().clone();