summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-04-28 21:26:49 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-04-28 21:26:49 +0200
commita7224f85bef1aba5c04a91f0459f196eced261d2 (patch)
tree5613e042593b24d260764ff8c5ea8d5e646a60fb
parent40d6caab0f02ad741086c3b428b2622a862650e4 (diff)
downloadrebel-a7224f85bef1aba5c04a91f0459f196eced261d2.tar
rebel-a7224f85bef1aba5c04a91f0459f196eced261d2.zip
rebel-lang: value: fix Value enum variant names to match Type variants
-rw-r--r--crates/rebel-lang/examples/repl.rs4
-rw-r--r--crates/rebel-lang/src/value.rs56
2 files changed, 30 insertions, 30 deletions
diff --git a/crates/rebel-lang/examples/repl.rs b/crates/rebel-lang/examples/repl.rs
index 8d76ec8..42e8d62 100644
--- a/crates/rebel-lang/examples/repl.rs
+++ b/crates/rebel-lang/examples/repl.rs
@@ -12,14 +12,14 @@ fn intrinsic_array_len(params: &[Value]) -> Result<Value> {
let Value::Array(array) = &params[0] else {
panic!();
};
- Ok(Value::Integer(array.len().try_into().or(Err(EvalError))?))
+ Ok(Value::Int(array.len().try_into().or(Err(EvalError))?))
}
fn intrinsic_string_len(params: &[Value]) -> Result<Value> {
assert!(params.len() == 1);
let Value::Str(string) = &params[0] else {
panic!();
};
- Ok(Value::Integer(
+ Ok(Value::Int(
string.chars().count().try_into().or(Err(EvalError))?,
))
}
diff --git a/crates/rebel-lang/src/value.rs b/crates/rebel-lang/src/value.rs
index db15d10..1eafc97 100644
--- a/crates/rebel-lang/src/value.rs
+++ b/crates/rebel-lang/src/value.rs
@@ -20,8 +20,8 @@ pub type Result<T> = std::result::Result<T, EvalError>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Value {
Unit,
- Boolean(bool),
- Integer(i64),
+ Bool(bool),
+ Int(i64),
Str(String),
Tuple(Vec<Value>),
Array(Vec<Value>),
@@ -33,8 +33,8 @@ impl Value {
pub fn typ(&self) -> typing::Result<Type> {
Ok(match self {
Value::Unit => Type::Unit,
- Value::Boolean(_) => Type::Bool,
- Value::Integer(_) => Type::Int,
+ Value::Bool(_) => Type::Bool,
+ Value::Int(_) => Type::Int,
Value::Str(_) => Type::Str,
Value::Tuple(elems) => Type::Tuple(
elems
@@ -96,26 +96,26 @@ impl Value {
Ok(match (tl, op, tr) {
(Str(s1), Add, Str(s2)) => Str(s1 + &s2),
- (Integer(i1), Add, Integer(i2)) => Integer(i1.checked_add(i2).ok_or(EvalError)?),
+ (Int(i1), Add, Int(i2)) => Int(i1.checked_add(i2).ok_or(EvalError)?),
(Array(elems1), Add, Array(elems2)) => Array([elems1, elems2].concat()),
- (Integer(i1), Sub, Integer(i2)) => Integer(i1.checked_sub(i2).ok_or(EvalError)?),
+ (Int(i1), Sub, Int(i2)) => Int(i1.checked_sub(i2).ok_or(EvalError)?),
(Array(elems1), Sub, Array(elems2)) => Array(
elems1
.into_iter()
.filter(|elem| !elems2.contains(elem))
.collect(),
),
- (Integer(i1), Mul, Integer(i2)) => Integer(i1.checked_mul(i2).ok_or(EvalError)?),
- (Integer(i1), Div, Integer(i2)) => Integer(i1.checked_div(i2).ok_or(EvalError)?),
- (Integer(i1), Rem, Integer(i2)) => Integer(i1.checked_rem(i2).ok_or(EvalError)?),
- (Boolean(b1), And, Boolean(b2)) => Boolean(b1 && b2),
- (Boolean(b1), Or, Boolean(b2)) => Boolean(b1 || b2),
- (l, Eq, r) => Boolean(l == r),
- (l, Ne, r) => Boolean(l != r),
- (Integer(i1), Lt, Integer(i2)) => Boolean(i1 < i2),
- (Integer(i1), Le, Integer(i2)) => Boolean(i1 <= i2),
- (Integer(i1), Ge, Integer(i2)) => Boolean(i1 >= i2),
- (Integer(i1), Gt, Integer(i2)) => Boolean(i1 > i2),
+ (Int(i1), Mul, Int(i2)) => Int(i1.checked_mul(i2).ok_or(EvalError)?),
+ (Int(i1), Div, Int(i2)) => Int(i1.checked_div(i2).ok_or(EvalError)?),
+ (Int(i1), Rem, Int(i2)) => Int(i1.checked_rem(i2).ok_or(EvalError)?),
+ (Bool(b1), And, Bool(b2)) => Bool(b1 && b2),
+ (Bool(b1), Or, Bool(b2)) => Bool(b1 || b2),
+ (l, Eq, r) => Bool(l == r),
+ (l, Ne, r) => Bool(l != r),
+ (Int(i1), Lt, Int(i2)) => Bool(i1 < i2),
+ (Int(i1), Le, Int(i2)) => Bool(i1 <= i2),
+ (Int(i1), Ge, Int(i2)) => Bool(i1 >= i2),
+ (Int(i1), Gt, Int(i2)) => Bool(i1 > i2),
_ => return Err(EvalError),
})
}
@@ -127,8 +127,8 @@ impl Value {
let typ = Self::eval(ctx, expr)?;
Ok(match (op, typ) {
- (Not, Boolean(val)) => Boolean(!val),
- (Neg, Integer(val)) => Integer(val.checked_neg().ok_or(EvalError)?),
+ (Not, Bool(val)) => Bool(!val),
+ (Neg, Int(val)) => Int(val.checked_neg().ok_or(EvalError)?),
_ => return Err(EvalError),
})
}
@@ -142,7 +142,7 @@ impl Value {
let Array(elems) = expr_value else {
return Err(EvalError);
};
- let Integer(index) = index_value else {
+ let Int(index) = index_value else {
return Err(EvalError);
};
let index: usize = index.try_into().or(Err(EvalError))?;
@@ -261,8 +261,8 @@ impl Value {
Ok(match lit {
Literal::Unit => Unit,
- Literal::Bool(val) => Boolean(*val),
- Literal::Int(val) => Integer(i64::try_from(*val).or(Err(EvalError))?),
+ Literal::Bool(val) => Bool(*val),
+ Literal::Int(val) => Int(i64::try_from(*val).or(Err(EvalError))?),
Literal::Str { pieces, kind } => Str(StrDisplay {
pieces,
kind: *kind,
@@ -297,8 +297,8 @@ impl Display for Value {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Value::Unit => f.write_str("()"),
- Value::Boolean(value) => value.fmt(f),
- Value::Integer(value) => value.fmt(f),
+ Value::Bool(value) => value.fmt(f),
+ Value::Int(value) => value.fmt(f),
Value::Str(value) => write!(f, "{value:?}"),
Value::Tuple(elems) => {
let mut first = true;
@@ -350,8 +350,8 @@ struct Stringify<'a>(&'a Value);
impl<'a> Display for Stringify<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.0 {
- Value::Boolean(value) => value.fmt(f),
- Value::Integer(value) => value.fmt(f),
+ Value::Bool(value) => value.fmt(f),
+ Value::Int(value) => value.fmt(f),
Value::Str(value) => value.fmt(f),
_ => Err(std::fmt::Error),
}
@@ -378,10 +378,10 @@ impl<'a> ScriptStringify<'a> {
impl<'a> Display for ScriptStringify<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.0 {
- Value::Boolean(value) => {
+ Value::Bool(value) => {
value.fmt(f)?;
}
- Value::Integer(value) => {
+ Value::Int(value) => {
value.fmt(f)?;
}
Value::Str(value) => {