Exemplo n.º 1
0
 private Expression Convert(LinqExp.MethodCallExpression linqCall)
 {
     return(Expression.Call(
                ConvertExp(linqCall.Object),
                linqCall.Method,
                Convert(linqCall.Arguments)));
 }
Exemplo n.º 2
0
            private MemberBinding Convert(LinqExp.MemberBinding linqBinding)
            {
                switch (linqBinding.BindingType)
                {
                case LinqExp.MemberBindingType.Assignment:
                    var linqMemberAssignment = (LinqExp.MemberAssignment)linqBinding;

                    return(Expression.Bind(
                               linqMemberAssignment.Member,
                               ConvertExp(linqMemberAssignment.Expression)));

                case LinqExp.MemberBindingType.MemberBinding:
                    var linqMemberBinding = (LinqExp.MemberMemberBinding)linqBinding;

                    return(Expression.MemberBind(
                               linqMemberBinding.Member,
                               linqMemberBinding.Bindings.Project(Convert)));

                case LinqExp.MemberBindingType.ListBinding:
                    var linqListBinding = (LinqExp.MemberListBinding)linqBinding;

                    return(Expression.ListBind(
                               linqListBinding.Member,
                               linqListBinding.Initializers.Project(Convert)));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
Exemplo n.º 3
0
 private Expression ConvertLambda(LinqExp.LambdaExpression linqLambda)
 {
     return(Expression.Lambda(
                linqLambda.Type,
                ConvertExp(linqLambda.Body),
                linqLambda.Parameters.Project(Convert)));
 }
Exemplo n.º 4
0
 private Expression Convert(LinqExp.ConditionalExpression linqConditional)
 {
     return(Expression.Condition(
                ConvertExp(linqConditional.Test),
                ConvertExp(linqConditional.IfTrue),
                ConvertExp(linqConditional.IfFalse)));
 }
Exemplo n.º 5
0
        public static MethodCallExpression Call(Expression instance, MethodInfo method, params Expression[] arguments)
        {
            Contract.RequiresNotNull(method, "method");
            Contract.Requires(!method.IsGenericMethodDefinition, "method");
            Contract.Requires(!method.ContainsGenericParameters, "method");
            if (method.IsStatic) {
                Contract.Requires(instance == null, "instance", "Instance must be null for static method");
            } else {
                Contract.RequiresNotNull(instance, "instance");
                if (!TypeUtils.CanAssign(method.DeclaringType, instance.Type)) {
                    throw new ArgumentException(
                        String.Format(
                             "Invalid instance type for {0}.{1}. Expected {0}, got {2}.",
                             method.DeclaringType.Name,
                             method.Name,
                             instance.Type.Name
                        ),
                        "instance"
                    );
                }
            }

            Contract.RequiresNotNullItems(arguments, "arguments");
            ParameterInfo[] parameters = method.GetParameters();

            ValidateCallArguments(parameters, arguments);

            return new MethodCallExpression(method, instance, CollectionUtils.ToReadOnlyCollection(arguments), parameters);
        }
 internal MethodCallExpression(MethodInfo /*!*/ method, Expression instance, ReadOnlyCollection<Expression> /*!*/ arguments, ParameterInfo[] /*!*/ parameters)
     : base(AstNodeType.Call) {
     _method = method;
     _instance = instance;
     _arguments = new List<Expression>(arguments);
     _parameterInfos = parameters;
 }
Exemplo n.º 7
0
        public static UnaryExpression Not(Expression expression)
        {
            Contract.RequiresNotNull(expression, "expression");
            Contract.Requires(TypeUtils.IsIntegerOrBool(expression.Type), "expression", "Expression type must be integer or boolean.");

            return new UnaryExpression(AstNodeType.Not, expression, expression.Type);
        }
Exemplo n.º 8
0
 internal override Expression UpdateFromReturn(MethodBinderContext context, Expression[] parameters) {
     return Ast.Call(
         typeof(BinderOps).GetMethod("UpdateBox").MakeGenericMethod(_elementType),
         Ast.Convert(parameters[Index], BoxType),
         Ast.Read(_tmp)
     );
 }
Exemplo n.º 9
0
 public static ThrowStatement Throw(SourceSpan span, Expression value)
 {
     if (value != null) {
         Contract.Requires(TypeUtils.CanAssign(typeof(Exception), value.Type));
     }
     return new ThrowStatement(span, value);
 }
Exemplo n.º 10
0
    public static Expression Apply(Expression[] args)
    {
      if (args.Length == 0)
      {
        return null;
      }

      Expression c = Ast.ConvertHelper(args[0], typeof(Callable));
      if (args.Length > 1)
      {
        Expression arg = Ast.ConvertHelper(args[args.Length - 1], typeof(object));
        
        if (arg.IsConstant(null)) Debugger.Break();

        for (int i = args.Length - 2; i > 0; i--)
        {
          arg = MakeCons(args[i], arg);
        }
        
        return Ast.ComplexCallHelper(c, ICallable_Call, Ast.Call(ListToVector, arg));
      }
      else
      {
        return null;
      }
    }
Exemplo n.º 11
0
        public static ScopeStatement Scope(SourceSpan span, Expression scope, Statement body) {
            Contract.RequiresNotNull(scope, "scope");
            Contract.RequiresNotNull(body, "body");
            Contract.Requires(TypeUtils.CanAssign(typeof(IAttributesCollection), scope.Type), "scope", "Scope must be IAttributesCollection");

            return new ScopeStatement(span, scope, body);
        }
Exemplo n.º 12
0
        public static SwitchStatement Switch(SourceSpan span, SourceLocation header, Expression value, params SwitchCase[] cases)
        {
            Contract.RequiresNotNull(value, "value");
            Contract.Requires(value.Type == typeof(int), "value", "Value must be int");
            Contract.RequiresNotEmpty(cases, "cases");
            Contract.RequiresNotNullItems(cases, "cases");

            bool @default = false;
            int max = Int32.MinValue;
            int min = Int32.MaxValue;
            foreach (SwitchCase sc in cases) {
                if (sc.IsDefault) {
                    Contract.Requires(@default == false, "cases", "Only one default clause allowed");
                    @default = true;
                } else {
                    int val = sc.Value;
                    if (val > max) max = val;
                    if (val < min) min = val;
                }
            }

            Contract.Requires(UniqueCaseValues(cases, min, max), "cases", "Case values must be unique");

            return new SwitchStatement(span, header, value, CollectionUtils.ToReadOnlyCollection(cases));
        }
Exemplo n.º 13
0
        public DoStatement While(Expression condition)
        {
            Contract.RequiresNotNull(condition, "condition");
            Contract.Requires(condition.Type == typeof(bool), "condition", "Condition must be boolean");

            return new DoStatement(_statementSpan, _doLocation, condition, _body);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Called by <see cref="DoStatementBuilder"/>.
 /// </summary>
 internal DoStatement(SourceSpan span, SourceLocation header, Expression /*!*/ test, Statement /*!*/ body)
     : base(AstNodeType.DoStatement, span)
 {
     _header = header;
     _test = test;
     _body = body;
 }
Exemplo n.º 15
0
        public static NewArrayExpression NewArrayHelper(Type type, IList<Expression> initializers)
        {
            Contract.RequiresNotNullItems(initializers, "initializers");
            Contract.RequiresNotNull(type, "type");
            Contract.Requires(type.IsArray, "type", "Not an array type");

            Type element = type.GetElementType();
            Expression[] clone = null;
            for (int i = 0; i < initializers.Count; i++) {
                Expression initializer = initializers[i];
                if (!TypeUtils.CanAssign(element, initializer.Type)) {
                    if (clone == null) {
                        clone = new Expression[initializers.Count];
                        for (int j = 0; j < i; j++) {
                            clone[j] = initializers[j];
                        }
                    }
                    initializer = Ast.Convert(initializer, element);
                }
                if (clone != null) {
                    clone[i] = initializer;
                }
            }

            return NewArray(type, clone ?? initializers);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Performs an assignment variable = value
 /// </summary>
 public static BoundAssignment Assign(Variable variable, Expression value)
 {
     Contract.RequiresNotNull(variable, "variable");
     Contract.RequiresNotNull(value, "value");
     Contract.Requires(TypeUtils.CanAssign(variable.Type, value.Type));
     return new BoundAssignment(variable, value);
 }
Exemplo n.º 17
0
        public override Expression asCLRSetValueExpression(Expression newValue)
        {
            // Context.markAsUncompilable();
            // return Expression.Constant(newValue);

            throw new InvalidOperationException("A NonStackResidentVariableDeclaration cannot be used to generate code. Use either an InstanceVariableDeclaration or a NamespaceResidentVariableDeclaration instead.");
        }
Exemplo n.º 18
0
 private Expression[] GetParameters(Expression[] parameters) {
     Expression[] res = new Expression[_nameIndexes.Length];
     for (int i = 0; i < _nameIndexes.Length; i++) {
         res[i] = parameters[_nameIndexes[i] + _argIndex];
     }
     return res;
 }
Exemplo n.º 19
0
        public static Expression Eqv(Expression[] obj)
        {
            if (obj.Length == 2)
              {
            var o1 = Unwrap(obj[0]);
            var o2 = Unwrap(obj[1]);

            Func<Type, bool> p = t => o1.Type == t || o2.Type == t;
            bool vt = !(o1.Type.IsValueType || o2.Type.IsValueType);

            if (p(typeof(SymbolId))
              || p(typeof(bool))
              || (vt && !p(typeof(object)) && !p(typeof(Fraction)) && !p(typeof(IntX)) && !p(typeof(ComplexFraction)))
              )
            {
              return Ast.Equal(obj[0], obj[1]);
            }
            else if (p(typeof(double)))
            {
              return null;
            }
            else if (o1 is ConstantExpression || o2 is ConstantExpression)
            {
              return Ast.Call(typeof(object).GetMethod("Equals", BindingFlags.Public | BindingFlags.Static), obj);
            }
              }
              return null;
        }
Exemplo n.º 20
0
 private IEnumerable <Expression> Convert(IEnumerable <LinqExp.Expression> linqExpressions)
 {
     return(linqExpressions.Project(arg =>
                                    (arg.NodeType == LinqExp.ExpressionType.Quote)
             ? Expression.Constant(((LinqExp.UnaryExpression)arg).Operand, arg.Type)
             : ConvertExp(arg)));
 }
Exemplo n.º 21
0
 internal ConditionalExpression(Expression/*!*/ test, Expression/*!*/ ifTrue, Expression/*!*/ ifFalse, Type/*!*/ type)
     : base(AstNodeType.Conditional) {
     _test = test;
     _true = ifTrue;
     _false = ifFalse;
     _expressionType = type;
 }
Exemplo n.º 22
0
 private Expression[] ConstantNames() {
     Expression[] res = new Expression[_names.Length];
     for (int i = 0; i < _names.Length; i++) {
         res[i] = Ast.Constant(_names[i]);
     }
     return res;
 }
Exemplo n.º 23
0
        /// <summary>
        /// Creates a new ErrorInfo which represents an exception that should
        /// be thrown.
        /// </summary>
        public static ErrorInfo FromException(Expression exceptionValue)
        {
            Contract.RequiresNotNull(exceptionValue, "exceptionValue");
            Contract.Requires(typeof(Exception).IsAssignableFrom(exceptionValue.Type), "exceptionValue", "must by an Exception instance");

            return new ErrorInfo(exceptionValue, null);
        }
Exemplo n.º 24
0
        public static UnaryExpression Negate(Expression expression)
        {
            Contract.RequiresNotNull(expression, "expression");
            Contract.Requires(TypeUtils.IsArithmetic(expression.Type) && !TypeUtils.IsUnsigned(expression.Type), "expression", "Expression must be signed numeric type");

            return new UnaryExpression(AstNodeType.Negate, expression, expression.Type);
        }
Exemplo n.º 25
0
        internal override MemberTracker BindToInstance(Expression instance) {
            if (IsStatic) {
                return this;
            }

            return new BoundMemberTracker(this, instance);
        }
Exemplo n.º 26
0
 static Expression MakeCallBack(Variable proc, Expression[] a)
 {
     var procr = Ast.ConvertHelper(Ast.Read(proc), typeof(Callable));
       MethodInfo call = GetCallable(a.Length);
       var expr = Ast.Call(procr, call, a);
       return expr;
 }
Exemplo n.º 27
0
 internal ArrayIndexAssignment(Expression /*!*/ array, Expression /*!*/ index, Expression /*!*/ value)
     : base(AstNodeType.ArrayIndexAssignment) {
     _array = array;
     _index = index;
     _value = value;
     _elementType = array.Type.GetElementType();
 }
Exemplo n.º 28
0
        public static VariableReference[] Bind(Expression test, Statement target) {
            Assert.NotNull(test, target);

            RuleBinder rb = new RuleBinder();
            rb.WalkNode(test);
            rb.WalkNode(target);
            return rb.GetReferences();
        }
Exemplo n.º 29
0
        public static IfStatementTest IfCondition(SourceSpan span, SourceLocation header, Expression test, Statement body)
        {
            Contract.RequiresNotNull(test, "test");
            Contract.RequiresNotNull(body, "body");
            Contract.Requires(test.Type == typeof(bool), "test", "Test must be boolean");

            return new IfStatementTest(span, header, test, body);
        }
Exemplo n.º 30
0
 public static Expression IsNull(Expression[] values)
 {
   if (values.Length != 1)
   {
     return null;
   }
   return Ast.Equal(values[0], Ast.Null());
 }
Exemplo n.º 31
0
        internal SwitchStatement(SourceSpan span, SourceLocation header, Expression/*!*/ testValue, ReadOnlyCollection<SwitchCase>/*!*/ cases)
            : base(AstNodeType.SwitchStatement, span) {
            Assert.NotNullItems(cases);

            _testValue = testValue;
            _cases = cases;
            _header = header;
        }
Exemplo n.º 32
0
 public static Expression IsPair(Expression[] values)
 {
   if (values.Length != 1)
   {
     return null;
   }
   return Ast.TypeIs(values[0], typeof(Cons));
 }
Exemplo n.º 33
0
 public static Expression Cons(Expression[] values)
 {
   if (values.Length == 2)
   {
     return Ast.New(cons, values[0], values[1]);  
   }
   return null;
 }
Exemplo n.º 34
0
 /// <summary>
 /// Null test means infinite loop.
 /// </summary>
 internal LoopStatement(SourceSpan span, SourceLocation header, Expression test, Expression increment, Statement /*!*/ body, Statement @else)
     : base(AstNodeType.LoopStatement, span) {
     _test = test;
     _increment = increment;
     _body = body;
     _else = @else;
     _header = header;
 }
Exemplo n.º 35
0
 public static Expression Eq(Expression[] obj)
 {
     if (obj.Length == 2)
       {
     return Ast.Equal(obj[0], obj[1]);
       }
       return null;
 }
        internal override Expression ToExpression(MethodBinderContext context, IList<ArgBuilder> args, IList<Expression> parameters, Expression ret)
        {
            List<Expression> sets = new List<Expression>();

            Variable tmp = null;// context.GetTemporary(ret.Type, "val");

            for (int i = 0; i < _indexesUsed.Length; i++) {
                Expression value = parameters[parameters.Count - _kwArgCount + _indexesUsed[i]];
                switch(_membersSet[i].MemberType) {
                    case MemberTypes.Field:
                        FieldInfo fi = (FieldInfo)_membersSet[i];
                        if (!fi.IsLiteral && !fi.IsInitOnly) {
                            sets.Add(Ast.AssignField(Ast.Read(tmp), fi, Ast.ConvertHelper(value, fi.FieldType)));
                        } else {
                            // call a helper which throws the error but "returns object"
                            sets.Add(
                                Ast.Convert(
                                    Ast.Call(
                                        typeof(RuntimeHelpers).GetMethod("ReadOnlyAssignError"),
                                        Ast.Constant(true),
                                        Ast.Constant(fi.Name)
                                    ),
                                    fi.FieldType
                                )
                            );
                        }
                        break;
                    case MemberTypes.Property:
                        PropertyInfo pi = (PropertyInfo)_membersSet[i];
                        if (pi.GetSetMethod(ScriptDomainManager.Options.PrivateBinding) != null) {
                            sets.Add(Ast.AssignProperty(Ast.Read(tmp), pi, Ast.ConvertHelper(value, pi.PropertyType)));
                        } else {
                            // call a helper which throws the error but "returns object"
                            sets.Add(
                                Ast.Convert(
                                    Ast.Call(
                                        typeof(RuntimeHelpers).GetMethod("ReadOnlyAssignError"),
                                        Ast.Constant(false),
                                        Ast.Constant(pi.Name)
                                    ),
                                    pi.PropertyType
                                )
                            );
                        }
                        break;
                }
            }

            Expression newCall = Ast.Comma(
                0,
                ArrayUtils.Insert<Expression>(
                    Ast.Assign(tmp, ret),
                    sets.ToArray()
                )
            );

            return _builder.ToExpression(context, args, parameters, newCall);
        }
Exemplo n.º 37
0
        public InstanceVariableDeclaration(NameBindingScope scope, ESSymbol name) : base(scope, name)
        {
            var namedSlotsObject = Expression.Convert(Scope.SelfParameter, TypeGuru.esNamedSlotsObjectType);

            namedSlots = Expression.Field(namedSlotsObject, "namedSlots");
            var statusFlags = Expression.Field(namedSlotsObject, "statusFlags");

            isMutable = Expression.Equal(Expression.And(statusFlags, mutabilityFlagBitConstant), zeroConstant);
        }
Exemplo n.º 38
0
            private ParameterExpression Convert(LinqExp.ParameterExpression linqParam)
            {
                if (_parameters.TryGetValue(linqParam, out var param))
                {
                    return(param);
                }

                return(_parameters[linqParam] = Expression.Parameter(linqParam.Type, linqParam.Name));
            }
Exemplo n.º 39
0
 public override Expression asCLRSetValueExpression(Expression newValue)
 {
     return(Expression.Condition(
                isMutable,
                Expression.Assign(Expression.ArrayAccess(namedSlots, slotIndex), newValue),
                Expression.Block(
                    TypeGuru.objectType,
                    Expression.Throw(Expression.Constant(new ImmutableObjectException())),
                    newValue)));
 }
Exemplo n.º 40
0
        public static Expression[] expressionArrayFor(DynamicMetaObject[] metaObjects)
        {
            var expressionArray = new Expression[metaObjects.Length];
            int i = 0;

            foreach (var metaObject in metaObjects)
            {
                expressionArray[i++] = metaObject.Expression.withCanonicalArgumentType();
            }
            return(expressionArray);
        }
Exemplo n.º 41
0
 private NewExpression Convert(LinqExp.NewExpression linqNew)
 {
     return((linqNew.Members != null)
         ? Expression.New(
                linqNew.Constructor,
                Convert(linqNew.Arguments),
                linqNew.Members)
         : Expression.New(
                linqNew.Constructor,
                Convert(linqNew.Arguments)));
 }
Exemplo n.º 42
0
        public virtual bool compile(ScriptType rootParseNodeType, NamespaceObject environment, Object selfValue, List <ParameterExpression> rootParameters, out Expression <FuncNs.Func <Object> > lambda)
        {
            Expression rootExpression;

            if (compile(rootParseNodeType, environment, selfValue, rootParameters, out rootExpression))
            {
                lambda = Expression.Lambda <FuncNs.Func <Object> >(rootExpression, false, new ParameterExpression[0]);
                return(true);
            }

            lambda = null;
            return(false);
        }
Exemplo n.º 43
0
        public List <ParameterExpression> parametersFor(Object[] arguments)
        {
            if (arguments == null || arguments.Length < 1)
            {
                return(null);
            }
            List <ParameterExpression> rootParameters = new List <ParameterExpression>();

            for (var i = 0; i < arguments.Length; i++)
            {
                rootParameters.Add(Expression.Parameter(TypeGuru.objectType, "_a" + (i + 1)));
            }
            return(rootParameters);
        }
Exemplo n.º 44
0
        public override Expression Bind(Object[] args, ReadOnlyCollection <ParameterExpression> parameters, LabelTarget returnLabel)
        {
            Expression testRuleValidityExpression = null;
            Expression getVariableValueExpression = null;

            doAllButFinalBinding(
                args,
                (BindingHandle handle) => {
                testRuleValidityExpression = Expression.Constant(true);
                var handleConstant         = Expression.Constant(handle);
                getVariableValueExpression = handle.IsDirect ?
                                             Expression.Field(handleConstant, TypeGuru.directBindingHandleType, "value") :
                                             Expression.Property(handleConstant, "Value");
            });
            return(Expression
                   .IfThen(
                       testRuleValidityExpression,
                       Expression.Return(returnLabel, getVariableValueExpression)));
        }
Exemplo n.º 45
0
        public override Expression Bind(Object[] args, ReadOnlyCollection <ParameterExpression> parameters, LabelTarget returnLabel)
        {
            Expression          testRuleValidityExpression = null;
            Expression          setVariableValueExpression = null;
            ParameterExpression value = parameters[1];

            doAllButFinalBinding(
                args,
                (BindingHandle handle) => {
                testRuleValidityExpression = Expression.Constant(true);
                setVariableValueExpression =
                    Expression.Assign(
                        Expression.Property(Expression.Constant(handle), "Value"),
                        value);
            });

            return(Expression
                   .IfThen(
                       testRuleValidityExpression,
                       Expression.Return(returnLabel, setVariableValueExpression)));
        }
Exemplo n.º 46
0
        public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
        {
            var        method           = (ESMethod)Value;
            Expression invokeExpression = null;
            var        numArgs          = args.Length;

            if (numArgs - method.NumArgs != 1)
            {
                var esClass = ValueClass;
                var kernel  = esClass.ObjectSpace;
                return(metaObjectToThrowInvalidFunctionCallException(
                           kernel.selectorToEvaluatMethodWithNumArgs(Math.Max(0, numArgs - 1)),
                           args,
                           "Argument count mismatch",
                           ESCompiledCode.methodFunctionTypeForNumArgs(method.NumArgs),
                           ESCompiledCode.blockFunctionTypeForNumArgs(args.Length)));
            }

            invokeExpression = ExpressionTreeGuru.expressionToInvokeESMethod(this.asExpressionWithFormalType(), expressionArrayFor(args));

            return(new DynamicMetaObject(invokeExpression, DefaultBindingRestrictions, method));
        }
Exemplo n.º 47
0
        public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
        {
            var        block            = (ESBlock)Value;
            Expression invokeExpression = null;
            var        numArgs          = args.Length;

            if (numArgs != block.NumArgs)
            {
                var esClass     = ValueClass;
                var objectSpace = esClass.ObjectSpace;
                return(metaObjectToThrowInvalidFunctionCallException(
                           objectSpace.selectorToEvaluatBlockWithNumArgs(numArgs),
                           args,
                           "Argument count mismatch",
                           ESCompiledCode.blockFunctionTypeForNumArgs(block.NumArgs),
                           ESCompiledCode.blockFunctionTypeForNumArgs(args.Length)));
            }

            invokeExpression = ExpressionTreeGuru.expressionToInvokeESBlock(this.asExpressionWithFormalType(), expressionArrayFor(args));

            return(new DynamicMetaObject(invokeExpression, DefaultBindingRestrictions, block));
        }
Exemplo n.º 48
0
 public override Expression asCLRSetValueExpression(Expression newValue)
 {
     return(Expression.Invoke(Expression.Field(setVariableCallSite, CodeGenerationContext.callSiteType[1], "Target"), setVariableCallSite, Scope.SelfParameter, newValue));
 }
Exemplo n.º 49
0
 public abstract Expression asCLRSetValueExpression(Expression newValue);
Exemplo n.º 50
0
 public ESBehaviorDynamicMetaObject(Expression expression, BindingRestrictions restrictions, object value, ESBehavior valueClass) : base(expression, restrictions, value, valueClass)
 {
 }
Exemplo n.º 51
0
        public override DynamicMetaObject BindUnaryOperation(UnaryOperationBinder binder)
        {
            DynamicMetaObject messageSendMO;
            Expression        value;
            DynamicMetaObject arg;

            switch (binder.Operation)
            {
            case ExpressionType.Negate:
                if (createMetaObjectToSendMessage("negated", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.UnaryPlus:
                if (createMetaObjectToSendMessage("abs", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Not:
                if (createMetaObjectToSendMessage("not", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Decrement:
                if (createMetaObjectToSendMessage("decrement", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Increment:
                if (createMetaObjectToSendMessage("increment", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.OnesComplement:
                if (createMetaObjectToSendMessage("bitInvert", DynamicBindingGuru.emptyArgArray, out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.IsTrue:
                value = Expression.Constant(true);
                arg   = value.asDynamicMetaObject(BindingRestrictions.Empty, true);
                if (createMetaObjectToSendMessage("=", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.IsFalse:
                value = Expression.Constant(false);
                arg   = value.asDynamicMetaObject(BindingRestrictions.Empty, false);
                if (createMetaObjectToSendMessage("=", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            default:
            case ExpressionType.Extension:
                messageSendMO = null;
                break;
            }

            if (messageSendMO == null)
            {
                var esClass  = ValueClass;
                var kernel   = esClass.ObjectSpace;
                var selector = kernel.symbolFor("??");
                messageSendMO = metaObjectToSendDoesNotUnderstand(selector, DynamicBindingGuru.emptyArgArray);
            }
            return(binder.FallbackUnaryOperation(this, messageSendMO));
        }
Exemplo n.º 52
0
        public override DynamicMetaObject BindDeleteMember(DeleteMemberBinder binder)
        {
            DynamicMetaObject messageSendMO;
            var kernel     = ValueClass.ObjectSpace;
            var memberName = kernel.symbolFor(binder.Name);

            if (createMetaObjectToSendMessage("removeKey:", DynamicBindingGuru.argArrayFor(Expression.Constant(memberName).asDynamicMetaObject(BindingRestrictions.Empty, memberName)), out messageSendMO))
            {
                return(messageSendMO);
            }
            return(binder.FallbackDeleteMember(this, messageSendMO));
        }
Exemplo n.º 53
0
 public ESDynamicMetaObject(Expression expression, BindingRestrictions restrictions, Object value, ESBehavior valueClass) : base(expression, restrictions, value)
 {
     this.valueClass = valueClass;
 }
Exemplo n.º 54
0
 public static ParameterExpression parameterExpressionFrom(ESSymbol name, Type parameterType)
 {
     return(Expression.Parameter(parameterType, name.PrimitiveValue));
 }
Exemplo n.º 55
0
 public override Expression asCLRSetValueExpression(Expression newValue)
 {
     return(Expression.Throw(Expression.Constant("Method and block parameters are not assignable (" + NameString + ")"), typeof(ImmutableBindingException)));
 }
Exemplo n.º 56
0
 public override Expression asCLRSetValueExpression(Expression newValue)
 {
     return(Expression.Assign(parameter, newValue));
 }
Exemplo n.º 57
0
 public override Expression asCLRGetValueExpression()
 {
     return(Expression.ArrayAccess(namedSlots, slotIndex));
 }
Exemplo n.º 58
0
 public override Expression asCLRGetValueExpression()
 {
     return(Expression.Invoke(Expression.Field(getVariableCallSite, CodeGenerationContext.callSiteType[0], "Target"), getVariableCallSite, Scope.SelfParameter));
 }
Exemplo n.º 59
0
 public Expression asCLRSetValueExpression(Expression newValue)
 {
     return(declaration.asCLRSetValueExpression(newValue));
 }
Exemplo n.º 60
0
        public virtual bool compile(ScriptType rootParseNodeType, NamespaceObject environment, Object selfValue, List <ParameterExpression> rootParameters, out Expression expression)
        {
            BlockLiteralNode blockLiteralNode;

            if (compile(rootParseNodeType, selfValue, rootParameters, out blockLiteralNode))
            {
                expression = blockLiteralNode.asCLRExpression(environment, null);
                var undeclaredVariables = blockLiteralNode.UndeclaredVariables;
                if (undeclaredVariables != null && undeclaredVariables.Count > 0)
                {
                    handleUndeclaredVariableReferences(undeclaredVariables, SourceSpan.None);
                }
                return(ErrorCount < 1);
            }

            expression = null;
            return(false);
        }