diff --git a/Upsilon/Evaluator/Evaluator.cs b/Upsilon/Evaluator/Evaluator.cs index fc2f37a..c5158f5 100644 --- a/Upsilon/Evaluator/Evaluator.cs +++ b/Upsilon/Evaluator/Evaluator.cs @@ -285,6 +285,27 @@ namespace Upsilon.Evaluator private ScriptType EvaluateBinaryExpression(BoundBinaryExpression e) { + if (e.Operator.Kind == BoundBinaryOperator.OperatorKind.Or) + { + var l = EvaluateExpression(e.LeftExpression); + if (l.Type == Type.Boolean && ((ScriptBoolean)l).Value) + return new ScriptBoolean(true); + var r = EvaluateExpression(e.RightExpression); + if (r.Type == Type.Boolean && ((ScriptBoolean)r).Value) + return new ScriptBoolean(true); + return new ScriptBoolean(false); + } + if (e.Operator.Kind == BoundBinaryOperator.OperatorKind.And) + { + var l = EvaluateExpression(e.LeftExpression); + if (l.Type != Type.Boolean || !((ScriptBoolean)l).Value) + return new ScriptBoolean(false); + var r = EvaluateExpression(e.RightExpression); + if (r.Type != Type.Boolean || !((ScriptBoolean)r).Value) + return new ScriptBoolean(false); + return new ScriptBoolean(true); + } + var left = EvaluateExpression(e.LeftExpression); var right = EvaluateExpression(e.RightExpression); switch (e.Operator.Kind) @@ -392,11 +413,6 @@ namespace Upsilon.Evaluator } ThrowException($"Can't find operator for types '{left.Type}' and '{right.Type}'", e.Span); return new ScriptNull(); - - case BoundBinaryOperator.OperatorKind.And: - return new ScriptBoolean((ScriptBoolean) left && (ScriptBoolean) right); - case BoundBinaryOperator.OperatorKind.Or: - return new ScriptBoolean((ScriptBoolean) left || (ScriptBoolean) right); default: throw new Exception("Invalid Binary Operator: " + e.Operator.Kind); }