Enum ConstValue

Source
pub enum ConstValue {
    Unknown,
    Bool(bool),
    Str(String),
    Int(BigInt),
    Rat(BigRational),
    Float(OrderedFloat<f64>),
    Complex(Box<Value>, Box<Value>),
}
Expand description

constant implements Values representing untyped Go constants and their corresponding operations.

A special Unknown value may be used when a value is unknown due to an error. Operations on unknown values produce unknown values unless specified otherwise.

Because BigFloat library is not available at the moment(2020/5) float numbers arbitrary precision is not supported for now float numbers is simply represented as f64 todo: This is against the Go specs. All the values involved in the evaluation

Variants§

§

Unknown

§

Bool(bool)

§

Str(String)

§

Int(BigInt)

§

Rat(BigRational)

§

Float(OrderedFloat<f64>)

§

Complex(Box<Value>, Box<Value>)

Implementations§

Source§

impl Value

Source

pub fn with_bool(b: bool) -> Value

Source

pub fn with_str(s: String) -> Value

Source

pub fn with_i64(i: i64) -> Value

Source

pub fn with_u64(u: u64) -> Value

Source

pub fn with_f64(f: f64) -> Value

Source

pub fn with_literal(tok: &Token) -> Value

Source

pub fn is_int(&self) -> bool

Source

pub fn representable( &self, base: &BasicDetail, rounded: Option<&mut Value>, ) -> bool

Source

pub fn to_int(&self) -> Cow<'_, Value>

Source

pub fn to_float(&self) -> Value

Source

pub fn to_complex(&self) -> Value

Source

pub fn make_imag(&self) -> Value

Source

pub fn real(&self) -> Value

real returns the real part of x, which must be a numeric or unknown value. If x is Unknown, the result is Unknown.

Source

pub fn imag(&self) -> Value

imag returns the imaginary part of x, which must be a numeric or unknown value. If x is Unknown, the result is Unknown.

Source

pub fn sign(&self) -> isize

sign returns -1, 0, or 1 depending on whether x < 0, x == 0, or x > 0; x must be numeric or Unknown. For complex values x, the sign is 0 if x == 0, otherwise it is != 0. If x is Unknown, the result is 1.

Source

pub fn binary_op(x: &Value, op: &Token, y: &Value) -> Value

binary_op returns the result of the binary expression x op y. The operation must be defined for the operands. If one of the operands is Unknown, the result is Unknown. binary_op doesn’t handle comparisons or shifts; use compare or shift instead.

To force integer division of Int operands, use op == Token::QUO_ASSIGN instead of Token::QUO; the result is guaranteed to be Int in this case. Division by zero leads to a run-time panic.

Source

pub fn unary_op(op: &Token, y: &Value, prec: usize) -> Value

unary_op returns the result of the unary expression op y. The operation must be defined for the operand. If prec > 0 it specifies the ^ (xor) result size in bits. If y is Unknown, the result is Unknown.

Source

pub fn compare(x: &Value, op: &Token, y: &Value) -> bool

compare returns the result of the comparison x op y. The comparison must be defined for the operands. If one of the operands is Unknown, the result is false.

Source

pub fn shift(x: &Value, op: &Token, s: usize) -> Value

Source

pub fn bool_as_bool(&self) -> bool

Source

pub fn str_as_string(&self) -> String

Source

pub fn int_as_u64(&self) -> (u64, bool)

int_as_u64 returns the Go uint64 value and whether the result is exact;

Source

pub fn int_as_i64(&self) -> (i64, bool)

int_as_i64 returns the Go int64 value and whether the result is exact;

Source

pub fn num_as_f64(&self) -> (OrderedFloat<f64>, bool)

num_as_f64 returns the nearest Go float64 value of x and whether the result is exact; x must be numeric or an Unknown, but not Complex. For values too small (too close to 0) to represent as float64, num_as_f64 silently underflows to 0. The result sign always matches the sign of x, even for 0. If x is Unknown, the result is (0, false).

Source

pub fn num_as_f32(&self) -> (OrderedFloat<f32>, bool)

num_as_f32 is like num_as_f64 but for float32 instead of float64.

Source

pub fn complex_as_complex64( &self, ) -> (OrderedFloat<f32>, OrderedFloat<f32>, bool)

Source

pub fn complex_as_complex128( &self, ) -> (OrderedFloat<f64>, OrderedFloat<f64>, bool)

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

For numeric values, the result may be an approximation; for String values the result may be a shortened string. Use ExactString for a string representing a value exactly.

Source§

impl Hash for Value

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Value

Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.