Add ArgIndex according to #4629

This commit is contained in:
minh.pham2000
2023-03-07 10:35:49 +07:00
parent 4d464cc9fb
commit db7b945262

View File

@@ -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<ArgIndex> 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<Self> {
Ok(Self {
value: obj.try_index(vm)?.as_bigint().clone(),
})
}
}