private void Init() { _opHelper = new OperatorHelper(CallInitFunction); _loader = new AphidLoader(this); }
private object InterpretBinaryOperatorExpression(BinaryOperatorExpression expression, bool returnRef = false) { switch (expression.Operator) { case AphidTokenType.AdditionOperator: return(OperatorHelper.Add( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.MinusOperator: return(OperatorHelper.Subtract( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.MultiplicationOperator: return(OperatorHelper.Multiply( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.DivisionOperator: return(OperatorHelper.Divide( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.MemberOperator: return(InterpretMemberExpression(expression, returnRef)); case AphidTokenType.AssignmentOperator: return(InterpetAssignmentExpression(expression, returnRef)); case AphidTokenType.DivisionEqualOperator: return(InterprentOperatorAndAssignmentExpression(OperatorHelper.Divide, expression)); case AphidTokenType.MinusEqualOperator: return(InterprentOperatorAndAssignmentExpression(OperatorHelper.Subtract, expression)); case AphidTokenType.ModulusEqualOperator: return(InterprentOperatorAndAssignmentExpression(OperatorHelper.Mod, expression)); case AphidTokenType.MultiplicationEqualOperator: return(InterprentOperatorAndAssignmentExpression(OperatorHelper.Multiply, expression)); case AphidTokenType.PlusEqualOperator: return(InterprentOperatorAndAssignmentExpression(OperatorHelper.Add, expression)); case AphidTokenType.XorEqualOperator: return(InterprentOperatorAndAssignmentExpression(OperatorHelper.Xor, expression)); case AphidTokenType.NotEqualOperator: case AphidTokenType.EqualityOperator: return(InterpretEqualityExpression(expression)); case AphidTokenType.LessThanOperator: return(CompareDecimals(expression, (x, y) => x < y)); case AphidTokenType.LessThanOrEqualOperator: return(CompareDecimals(expression, (x, y) => x <= y)); case AphidTokenType.GreaterThanOperator: return(CompareDecimals(expression, (x, y) => x > y)); case AphidTokenType.GreaterThanOrEqualOperator: return(CompareDecimals(expression, (x, y) => x >= y)); case AphidTokenType.AndOperator: return(InterpretAndExpression(expression)); case AphidTokenType.OrOperator: return(InterpretOrExpression(expression)); case AphidTokenType.ModulusOperator: return(OperatorHelper.Mod( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.ShiftLeft: return(OperatorHelper.BinaryShiftLeft( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.ShiftRight: return(OperatorHelper.BinaryShiftRight( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.BinaryAndOperator: return(OperatorHelper.BinaryAnd( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.BinaryOrOperator: return(OperatorHelper.BinaryOr( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.XorOperator: return(OperatorHelper.Xor( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.PipelineOperator: return(InterpretCallExpression(new CallExpression(expression.RightOperand, expression.LeftOperand))); case AphidTokenType.RangeOperator: return(OperatorHelper.Range( InterpretExpression(expression.LeftOperand) as AphidObject, InterpretExpression(expression.RightOperand) as AphidObject)); case AphidTokenType.SelectOperator: var collection = (List <AphidObject>)((AphidObject)InterpretExpression(expression.LeftOperand)).Value; var value = ((AphidObject)InterpretExpression(expression.RightOperand)).Value; var func = value as AphidFunction; if (func != null) { return(new AphidObject(collection.Select(x => CallFunction(func, x)).ToList())); } var func2 = value as AphidInteropFunction; if (func2 != null) { return(new AphidObject(collection.Select(x => CallInteropFunction(func2, x)).ToList())); } throw new InvalidOperationException(); case AphidTokenType.SelectManyOperator: collection = (List <AphidObject>)((AphidObject)InterpretExpression(expression.LeftOperand)).Value; value = ((AphidObject)InterpretExpression(expression.RightOperand)).Value; func = value as AphidFunction; if (func != null) { return(new AphidObject(collection.SelectMany(x => (List <AphidObject>)CallFunction(func, x).Value).ToList())); } func2 = value as AphidInteropFunction; if (func2 != null) { return(new AphidObject(collection.SelectMany(x => (List <AphidObject>)CallInteropFunction(func2, x).Value).ToList())); } throw new InvalidOperationException(); case AphidTokenType.AggregateOperator: collection = (List <AphidObject>)((AphidObject)InterpretExpression(expression.LeftOperand)).Value; value = ((AphidObject)InterpretExpression(expression.RightOperand)).Value; func = value as AphidFunction; if (func != null) { return(collection.Aggregate((x, y) => CallFunction(func, x, y))); } func2 = value as AphidInteropFunction; if (func2 != null) { return(collection.Aggregate((x, y) => CallInteropFunction(func2, x, y))); } throw new InvalidOperationException(); case AphidTokenType.AnyOperator: collection = (List <AphidObject>)((AphidObject)InterpretExpression(expression.LeftOperand)).Value; value = ((AphidObject)InterpretExpression(expression.RightOperand)).Value; func = (AphidFunction)((AphidObject)InterpretExpression(expression.RightOperand)).Value; if (func != null) { return(new AphidObject(collection.Any(x => (bool)CallFunction(func, x).Value))); } func2 = value as AphidInteropFunction; if (func2 != null) { return(new AphidObject(collection.Any(x => (bool)CallInteropFunction(func2, x).Value))); } throw new InvalidOperationException(); case AphidTokenType.WhereOperator: collection = (List <AphidObject>)((AphidObject)InterpretExpression(expression.LeftOperand)).Value; value = ((AphidObject)InterpretExpression(expression.RightOperand)).Value; func = (AphidFunction)((AphidObject)InterpretExpression(expression.RightOperand)).Value; if (func != null) { return(new AphidObject(collection.Where(x => (bool)CallFunction(func, x).Value).ToList())); } func2 = value as AphidInteropFunction; if (func2 != null) { return(new AphidObject(collection.Where(x => (bool)CallInteropFunction(func2, x).Value).ToList())); } throw new InvalidOperationException(); default: throw new AphidRuntimeException("Unknown operator {0} in expression {1}", expression.Operator, expression); } }
public bool Equals(AphidObject x, AphidObject y) { return(OperatorHelper.EqualsCore(x, y)); }