From db7b94526257c2e1235a88787fe26f305119d55f Mon Sep 17 00:00:00 2001 From: "minh.pham2000" Date: Tue, 7 Mar 2023 10:35:49 +0700 Subject: [PATCH] Add ArgIndex according to #4629 --- vm/src/function/number.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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(), + }) + } +}