diff --git a/src/interpreter.cc b/src/interpreter.cc index e219958..35aa26b 100644 --- a/src/interpreter.cc +++ b/src/interpreter.cc @@ -161,20 +161,8 @@ static Result equality_operator(Interpreter&, std::vector args) template static Result comparison_operator(Interpreter&, std::vector args) { - using NN = Shape; - using BB = Shape; - - if (NN::typecheck(args)) { - auto [a, b] = NN::move_from(args); - return Value::from(Binary_Predicate{}(std::move(a), std::move(b))); - } - - if (BB::typecheck(args)) { - auto [a, b] = BB::move_from(args); - return Value::from(Binary_Predicate{}(a, b)); - } - - unreachable(); + assert(args.size() == 2, "Operator handler cannot accept any shape different then 2 arguments"); + return Value::from(Binary_Predicate{}(args.front(), args.back())); } /// Registers constants like `fn = full note = 1/1` diff --git a/src/tests/interpreter.cc b/src/tests/interpreter.cc index 03badda..09c169e 100644 --- a/src/tests/interpreter.cc +++ b/src/tests/interpreter.cc @@ -102,6 +102,24 @@ suite intepreter_test = [] { evaluates_to(Value::from(true), "0 <= 0"); evaluates_to(Value::from(true), "1 < 2"); evaluates_to(Value::from(false), "1 > 2"); + + evaluates_to(Value::from(true), "c == c"); + evaluates_to(Value::from(false), "c != c"); + + evaluates_to(Value::from(true), "c < d"); + evaluates_to(Value::from(true), "c != (c 4)"); + evaluates_to(Value::from(true), "(c 4) == (c 4)"); + evaluates_to(Value::from(true), "(c 3) != (c 4)"); + evaluates_to(Value::from(true), "(c 3) < (c 4)"); + evaluates_to(Value::from(true), "((c+12) 3) == (c 4)"); + + // Value is partially ordered, ensure that different types + // are always not equal and not ordered + evaluates_to(Value::from(false), "0 < c"); + evaluates_to(Value::from(false), "0 > c"); + evaluates_to(Value::from(false), "0 <= c"); + evaluates_to(Value::from(false), "0 >= c"); + evaluates_to(Value::from(true), "0 != c"); }; // Added to explicitly test against bug that was in old implementation of enviroments.