diff --git a/vm/src/function/number.rs b/vm/src/function/number.rs index 12f6d70cc..5fa1e247e 100644 --- a/vm/src/function/number.rs +++ b/vm/src/function/number.rs @@ -1,4 +1,5 @@ use crate::{AsObject, PyObjectRef, PyResult, TryFromObject, VirtualMachine}; +use num_bigint::BigInt; use num_complex::Complex64; use std::ops::Deref; @@ -125,3 +126,32 @@ impl TryFromObject for ArgIntoBool { }) } } + +// Implement ArgIndex to seperate between "true" int and int generated by index +#[derive(Debug, PartialEq)] +#[repr(transparent)] +pub struct ArgIndex { + value: BigInt, +} + +impl From for BigInt { + fn from(arg: ArgIndex) -> Self { + arg.value + } +} + +impl Deref for ArgIndex { + type Target = BigInt; + + fn deref(&self) -> &Self::Target { + &self.value + } +} + +impl TryFromObject for ArgIndex { + fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult { + Ok(Self { + value: obj.try_index(vm)?.as_bigint().clone(), + }) + } +}