Exemplo n.º 1
0
        private static Expression CompileObj(Obj obj, Scope scope)
        {
            var temp = scope.FreeVariable("obj");
            var expressions = new List<Expression>
            {
                Expression.Assign(temp, Expression.New(ExpandoConstructor))
            };

            foreach (var @base in obj.Properties)
            {
                var property = @base as Assign;

                foreach (var name in CompileToNames(property.Variable))
                {
                    var expression = Compile(property.Value, scope);

                    expressions.Add(Expression.Dynamic(scope.GetRuntime().SetMemberBinders.Get(name), typeof(object), temp, expression));
                }
            }

            expressions.Add(temp);

            return Expression.Block(expressions);
        }
Exemplo n.º 2
0
        private static Expression CompileExistence(Op op, Scope scope)
        {
            var p = scope.FreeVariable("ref");

            var @ref = new Literal {Value = p.Name};
            var fst = new Parens {Body = new Assign {Variable = @ref, Value = op.First}};

            return Compile(new If {Condition = new Existence {Expression = fst}, Body = @ref, ElseBody = op.Second}, scope);
        }