internal override bool BinaryOperation(BinaryOperationBinder binder, Any arg, out Any result) { var number = arg as Number; if (number != null) { switch (binder.Operation) { case ExpressionType.Add: result = new Number(Value + number.Value); break; case ExpressionType.Subtract: result = new Number(Value - number.Value); break; case ExpressionType.Multiply: result = new Number(Value * number.Value); break; case ExpressionType.Divide: result = new Number(Value / number.Value); break; case ExpressionType.LessThan: result = Value < number.Value ? Bool.True : Bool.False; break; case ExpressionType.LessThanOrEqual: result = Value <= number.Value ? Bool.True : Bool.False; break; default: throw new ArgumentOutOfRangeException(); } return true; } return base.BinaryOperation(binder, arg, out result); }
internal override bool GetMemberOperation(GetMemberBinder binder, out Any result) { if (Members.TryGetValue(binder.Name, out result)) { return true; } return base.GetMemberOperation(binder, out result); }
internal override bool UnaryOperation(UnaryOperationBinder binder, out Any result) { switch (binder.Operation) { case ExpressionType.IsTrue: result = Value.Length > 0 ? Bool.True : Bool.False; return true; } return base.UnaryOperation(binder, out result); }
internal override bool GetMemberOperation(GetMemberBinder binder, out Any result) { Func<Iter, Any> member; if (!members.TryGetValue(binder.Name, out member)) { result = null; return false; } result = member(this); return true; }
internal override bool UnaryOperation(UnaryOperationBinder binder, out Any result) { switch (binder.Operation) { case ExpressionType.IsTrue: result = ((int)Value) != 0 ? Bool.True : Bool.False; return true; case ExpressionType.Negate: result = new Number(-Value); return true; } return base.UnaryOperation(binder, out result); }
internal override bool BinaryOperation(BinaryOperationBinder binder, Any arg, out Any result) { var str = arg as String; if (str != null) { switch (binder.Operation) { case ExpressionType.Add: result = new String(Value + str.Value); break; default: throw new ArgumentOutOfRangeException(); } return true; } return base.BinaryOperation(binder, arg, out result); }
internal override bool InvokeOperation(InvokeBinder binder, Args args, out Any result) { result = signature(args); return(true); }
internal override bool GetIndexOperation(GetIndexBinder binder, Args indices, out Any result) { var idx = (int)((Number)indices[0]).Value; result = values[idx]; return(true); }
internal override bool SetMemberOperation(SetMemberBinder binder, Any value) { members[binder.Name] = value; return true; }
internal override bool InvokeOperation(InvokeBinder binder, Args args, out Any result) { result = ctor(args); return true; }
internal override bool BinaryOperation(BinaryOperationBinder binder, Any arg, out Any result) { var number = arg as Number; if (number != null) { switch (binder.Operation) { case ExpressionType.Add: result = new Number(Value + number.Value); break; case ExpressionType.Subtract: result = new Number(Value - number.Value); break; case ExpressionType.Multiply: result = new Number(Value * number.Value); break; case ExpressionType.Divide: result = new Number(Value / number.Value); break; case ExpressionType.LessThan: result = Value < number.Value ? Bool.True : Bool.False; break; case ExpressionType.LessThanOrEqual: result = Value <= number.Value ? Bool.True : Bool.False; break; default: throw new ArgumentOutOfRangeException(); } return(true); } return(base.BinaryOperation(binder, arg, out result)); }
internal virtual bool GetIndexOperation(GetIndexBinder binder, Args indices, out Any result) { result = null; return false; }
internal override bool GetIndexOperation(GetIndexBinder binder, Args indices, out Any result) { var idx = (int)((Number)indices[0]).Value; result = values[idx]; return true; }
internal override bool SetMemberOperation(SetMemberBinder binder, Any value) { Members[binder.Name] = value; return(true); }
internal virtual bool UnaryOperation(UnaryOperationBinder binder, out Any result) { result = null; return false; }
internal virtual bool SetMemberOperation(SetMemberBinder binder, Any value) { return false; }
internal virtual bool SetIndexOperation(SetIndexBinder binder, Args indices, Any value) { return false; }
internal virtual bool InvokeOperation(InvokeBinder binder, Args args, out Any result) { result = null; return false; }
internal virtual bool GetMemberOperation(GetMemberBinder binder, out Any result) { result = null; return false; }