Skip to content

Commit 0d7e3d3

Browse files
authored
Remove non-standard binary operators (#147)
The following are not part of the language definition: - `map + map -> map` - `double + int -> double` - `int + double -> double` - `double + uint -> double` - `uint + double -> double` - `double - int -> double` - `int - double -> double` - `double - uint -> double` - `uint - double -> double` - `double * int -> double` - `int * double -> double` - `double * uint -> double` - `uint * double -> double` - `double / int -> double` - `int / double -> double` - `double / uint -> double` - `uint / double -> double` - `double % double -> double` - `double % int -> double` - `int % double -> double` - `double % uint -> double` - `uint % double -> double` Fixes #146
1 parent ec9eb58 commit 0d7e3d3

File tree

2 files changed

+1
-44
lines changed

2 files changed

+1
-44
lines changed

interpreter/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,6 @@ mod tests {
235235

236236
// Test that we can index into a string
237237
assert_output("str[0] == 'f'", Ok(true.into()));
238-
239-
// Test that we can merge two maps
240-
assert_output(
241-
"{'a': 1} + {'a': 2, 'b': 3}",
242-
Ok(HashMap::from([("a", 2), ("b", 3)]).into()),
243-
);
244238
}
245239

246240
#[test]

interpreter/src/objects.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -772,12 +772,7 @@ impl ops::Add<Value> for Value {
772772
.ok_or(ExecutionError::IntegerOverflow("add", l.into(), r.into()))
773773
.map(Value::UInt),
774774

775-
// Float matrix
776775
(Value::Float(l), Value::Float(r)) => Value::Float(l + r).into(),
777-
(Value::Int(l), Value::Float(r)) => Value::Float(l as f64 + r).into(),
778-
(Value::Float(l), Value::Int(r)) => Value::Float(l + r as f64).into(),
779-
(Value::UInt(l), Value::Float(r)) => Value::Float(l as f64 + r).into(),
780-
(Value::Float(l), Value::UInt(r)) => Value::Float(l + r as f64).into(),
781776

782777
(Value::List(l), Value::List(r)) => {
783778
Value::List(l.iter().chain(r.iter()).cloned().collect::<Vec<_>>().into()).into()
@@ -788,17 +783,6 @@ impl ops::Add<Value> for Value {
788783
new.push_str(&r);
789784
Value::String(new.into()).into()
790785
}
791-
// Merge two maps should overwrite keys in the left map with the right map
792-
(Value::Map(l), Value::Map(r)) => {
793-
let mut new = HashMap::default();
794-
for (k, v) in l.map.iter() {
795-
new.insert(k.clone(), v.clone());
796-
}
797-
for (k, v) in r.map.iter() {
798-
new.insert(k.clone(), v.clone());
799-
}
800-
Value::Map(Map { map: Arc::new(new) }).into()
801-
}
802786
// todo! Check for integer overflow in duration math
803787
#[cfg(feature = "chrono")]
804788
(Value::Duration(l), Value::Duration(r)) => Value::Duration(l + r).into(),
@@ -829,12 +813,8 @@ impl ops::Sub<Value> for Value {
829813
.ok_or(ExecutionError::IntegerOverflow("sub", l.into(), r.into()))
830814
.map(Value::UInt),
831815

832-
// Float matrix
833816
(Value::Float(l), Value::Float(r)) => Value::Float(l - r).into(),
834-
(Value::Int(l), Value::Float(r)) => Value::Float(l as f64 - r).into(),
835-
(Value::Float(l), Value::Int(r)) => Value::Float(l - r as f64).into(),
836-
(Value::UInt(l), Value::Float(r)) => Value::Float(l as f64 - r).into(),
837-
(Value::Float(l), Value::UInt(r)) => Value::Float(l - r as f64).into(),
817+
838818
// todo: implement checked sub for these over-flowable operations
839819
#[cfg(feature = "chrono")]
840820
(Value::Duration(l), Value::Duration(r)) => Value::Duration(l - r).into(),
@@ -870,12 +850,7 @@ impl ops::Div<Value> for Value {
870850
.ok_or(ExecutionError::DivisionByZero(l.into()))
871851
.map(Value::UInt),
872852

873-
// Float matrix
874853
(Value::Float(l), Value::Float(r)) => Value::Float(l / r).into(),
875-
(Value::Int(l), Value::Float(r)) => Value::Float(l as f64 / r).into(),
876-
(Value::Float(l), Value::Int(r)) => Value::Float(l / r as f64).into(),
877-
(Value::UInt(l), Value::Float(r)) => Value::Float(l as f64 / r).into(),
878-
(Value::Float(l), Value::UInt(r)) => Value::Float(l / r as f64).into(),
879854

880855
(left, right) => Err(ExecutionError::UnsupportedBinaryOperator(
881856
"div", left, right,
@@ -900,12 +875,7 @@ impl ops::Mul<Value> for Value {
900875
.ok_or(ExecutionError::IntegerOverflow("mul", l.into(), r.into()))
901876
.map(Value::UInt),
902877

903-
// Float matrix
904878
(Value::Float(l), Value::Float(r)) => Value::Float(l * r).into(),
905-
(Value::Int(l), Value::Float(r)) => Value::Float(l as f64 * r).into(),
906-
(Value::Float(l), Value::Int(r)) => Value::Float(l * r as f64).into(),
907-
(Value::UInt(l), Value::Float(r)) => Value::Float(l as f64 * r).into(),
908-
(Value::Float(l), Value::UInt(r)) => Value::Float(l * r as f64).into(),
909879

910880
(left, right) => Err(ExecutionError::UnsupportedBinaryOperator(
911881
"mul", left, right,
@@ -935,13 +905,6 @@ impl ops::Rem<Value> for Value {
935905
.ok_or(ExecutionError::RemainderByZero(l.into()))
936906
.map(Value::UInt),
937907

938-
// Float matrix
939-
(Value::Float(l), Value::Float(r)) => Value::Float(l % r).into(),
940-
(Value::Int(l), Value::Float(r)) => Value::Float(l as f64 % r).into(),
941-
(Value::Float(l), Value::Int(r)) => Value::Float(l % r as f64).into(),
942-
(Value::UInt(l), Value::Float(r)) => Value::Float(l as f64 % r).into(),
943-
(Value::Float(l), Value::UInt(r)) => Value::Float(l % r as f64).into(),
944-
945908
(left, right) => Err(ExecutionError::UnsupportedBinaryOperator(
946909
"rem", left, right,
947910
)),

0 commit comments

Comments
 (0)