From e95529aca0d2cade09cafefdc4b973e7bb308787 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 10 Mar 2023 06:07:25 +0900 Subject: [PATCH] introduce ArgSize --- vm/src/function/mod.rs | 2 +- vm/src/function/number.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/vm/src/function/mod.rs b/vm/src/function/mod.rs index d606d60403..cda8be6be3 100644 --- a/vm/src/function/mod.rs +++ b/vm/src/function/mod.rs @@ -17,7 +17,7 @@ pub use builtin::{IntoPyNativeFunc, OwnedParam, PyNativeFunc, RefParam}; pub use either::Either; pub use getset::PySetterValue; pub(super) use getset::{IntoPyGetterFunc, IntoPySetterFunc, PyGetterFunc, PySetterFunc}; -pub use number::{ArgIndex, ArgIntoBool, ArgIntoComplex, ArgIntoFloat}; +pub use number::{ArgIndex, ArgIntoBool, ArgIntoComplex, ArgIntoFloat, ArgSize}; pub use protocol::{ArgCallable, ArgIterable, ArgMapping, ArgSequence}; use crate::{builtins::PyStr, convert::TryFromBorrowedObject, PyObject, PyResult, VirtualMachine}; diff --git a/vm/src/function/number.rs b/vm/src/function/number.rs index 4434482adc..7585d53eed 100644 --- a/vm/src/function/number.rs +++ b/vm/src/function/number.rs @@ -154,3 +154,31 @@ impl TryFromObject for ArgIndex { }) } } + +#[derive(Debug)] +#[repr(transparent)] +pub struct ArgSize { + value: isize, +} + +impl From for isize { + fn from(arg: ArgSize) -> Self { + arg.value + } +} + +impl Deref for ArgSize { + type Target = isize; + + fn deref(&self) -> &Self::Target { + &self.value + } +} + +impl TryFromObject for ArgSize { + fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult { + Ok(Self { + value: obj.try_index(vm)?.try_to_primitive(vm)?, + }) + } +}