logo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crate::convert::implicitly_convert_to_int;
use crate::extn::core::integer::Integer;
use crate::extn::prelude::*;

pub fn chr(interp: &mut Artichoke, value: Value, encoding: Option<Value>) -> Result<Value, Error> {
    let value = value.try_convert_into::<Integer>(interp)?;
    let s = value.chr(interp, encoding)?;
    spinoso_string::String::alloc_value(s, interp)
}

pub fn element_reference(interp: &mut Artichoke, value: Value, bit: Value) -> Result<Value, Error> {
    let value = value.try_convert_into::<Integer>(interp)?;
    let bit = implicitly_convert_to_int(interp, bit)?;
    let bit = value.bit(bit)?;
    Ok(interp.convert(bit))
}

pub fn div(interp: &mut Artichoke, value: Value, denominator: Value) -> Result<Value, Error> {
    let value = value.try_convert_into::<Integer>(interp)?;
    let quotient = value.div(interp, denominator)?;
    Ok(interp.convert_mut(quotient))
}

pub fn is_allbits(interp: &mut Artichoke, value: Value, mask: Value) -> Result<Value, Error> {
    let value = value.try_convert_into::<Integer>(interp)?;
    let mask = implicitly_convert_to_int(interp, mask)?;
    let result = value.is_allbits(mask);
    Ok(interp.convert(result))
}

pub fn is_anybits(interp: &mut Artichoke, value: Value, mask: Value) -> Result<Value, Error> {
    let value = value.try_convert_into::<Integer>(interp)?;
    let mask = implicitly_convert_to_int(interp, mask)?;
    let result = value.is_anybits(mask);
    Ok(interp.convert(result))
}

pub fn is_nobits(interp: &mut Artichoke, value: Value, mask: Value) -> Result<Value, Error> {
    let value = value.try_convert_into::<Integer>(interp)?;
    let mask = implicitly_convert_to_int(interp, mask)?;
    let result = value.is_nobits(mask);
    Ok(interp.convert(result))
}

pub fn size(interp: &Artichoke) -> Result<Value, Error> {
    qed::const_assert!(Integer::size() < i8::MAX as usize);
    const SIZE: i64 = Integer::size() as i64;
    Ok(interp.convert(SIZE))
}