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
impl Value
pub fn with_bool(b: bool) -> Value
pub fn with_str(s: String) -> Value
pub fn with_i64(i: i64) -> Value
pub fn with_u64(u: u64) -> Value
pub fn with_f64(f: f64) -> Value
pub fn with_literal(tok: &Token) -> Value
pub fn is_int(&self) -> bool
pub fn representable( &self, base: &BasicDetail, rounded: Option<&mut Value>, ) -> bool
pub fn to_int(&self) -> Cow<'_, Value>
pub fn to_float(&self) -> Value
pub fn to_complex(&self) -> Value
pub fn make_imag(&self) -> Value
Sourcepub fn real(&self) -> Value
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.
Sourcepub fn imag(&self) -> Value
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.
Sourcepub fn sign(&self) -> isize
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.
Sourcepub fn binary_op(x: &Value, op: &Token, y: &Value) -> Value
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.
Sourcepub fn unary_op(op: &Token, y: &Value, prec: usize) -> Value
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.
Sourcepub fn compare(x: &Value, op: &Token, y: &Value) -> bool
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.
pub fn shift(x: &Value, op: &Token, s: usize) -> Value
pub fn bool_as_bool(&self) -> bool
pub fn str_as_string(&self) -> String
Sourcepub fn int_as_u64(&self) -> (u64, bool)
pub fn int_as_u64(&self) -> (u64, bool)
int_as_u64 returns the Go uint64 value and whether the result is exact;
Sourcepub fn int_as_i64(&self) -> (i64, bool)
pub fn int_as_i64(&self) -> (i64, bool)
int_as_i64 returns the Go int64 value and whether the result is exact;
Sourcepub fn num_as_f64(&self) -> (OrderedFloat<f64>, bool)
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).
Sourcepub fn num_as_f32(&self) -> (OrderedFloat<f32>, bool)
pub fn num_as_f32(&self) -> (OrderedFloat<f32>, bool)
num_as_f32 is like num_as_f64 but for float32 instead of float64.