public override DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
 {
     try
     {
         return(new DynamicMetaObject(
                    (Static.GetTargetType(target.Value)
                     .Null(t => YacqExpression.TypeCandidate(this._symbols, t))
                     ?? target.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType)
                    )
                    .Method(this._symbols, this.Name,
                            args.SelectAll(o => o.Expression.Reduce(this._symbols).TryConvert(o.RuntimeType))
                            )
                    .Reduce(this._symbols)
                    .If(e => e.Type == typeof(void), e =>
                        Expression.Block(e, Expression.Default(typeof(Object)))
                        )
                    .If(e => e.Type.IsValueType, e =>
                        e.TryConvert(typeof(Object))
                        ),
                    target.Restrictions
                    ));
     }
     catch (Exception ex)
     {
         return(errorSuggestion
                ?? new DynamicMetaObject(
                    Expression.Throw(Expression.Constant(ex), typeof(Object)),
                    BindingRestrictions.Empty
                    ));
     }
 }
示例#2
0
 public static Expression DumpObject(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(JsonConvert))
            .Method(s, "SerializeObject",
                    e.Left,
                    Expression.Constant(Formatting.None),
                    SerializerSettings
                    ));
 }
示例#3
0
            public static Expression Missing(DispatchExpression e, SymbolTable s, Type t)
            {
                Type type;

                if (e.DispatchType == DispatchTypes.Method &&
                    !s.ExistsKey(DispatchTypes.Method, e.Name) &&
                    (type = FilterRegistrant.GetFilter(e.Name).FirstOrDefault()) != null
                    )
                {
                    return(YacqExpression.Dispatch(
                               s,
                               DispatchTypes.Constructor,
                               YacqExpression.TypeCandidate(type),
                               null,
                               e.Arguments
                               )
                           .Method(s, "Filter", YacqExpression.Identifier(s, "it")));
                }
                return(DispatchExpression.DefaultMissing(e, s, t));
            }
示例#4
0
 public static Expression Tab(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(Setting))
            .Member(s, "Instance")
            .Member(s, "StateProperty")
            .Member(s, "TabInformations")
            .Method(s, "SelectMany",
                    YacqExpression.Function(s, "\\",
                                            YacqExpression.Vector(s, YacqExpression.Identifier(s, "e")),
                                            YacqExpression.Identifier(s, "e")
                                            )
                    )
            .Method(s, "First",
                    YacqExpression.LambdaList(s,
                                              YacqExpression.Identifier(s, "=="),
                                              YacqExpression.Identifier(s, "$0").Member(s, "Name"),
                                              e.Arguments[0]
                                              )
                    )
            .Member(s, "TweetSources")
            .Method(s, "Single"));
 }
示例#5
0
 /// <summary>
 /// Creates a <see cref="Type"/> object for the type. After defining members on the type, this method is called in order to load its Type object.
 /// </summary>
 /// <param name="symbols">The additional symbol table for reducing.</param>
 /// <returns>The new Type object for this type.</returns>
 public Type Create(SymbolTable symbols = null)
 {
     if (this.IsCreated)
     {
         return(this._type.CreateType());
     }
     if (this.GetConstructors().IsEmpty())
     {
         this.DefineConstructor(null);
     }
     if (this._cctor != null)
     {
         this._cctor.Null(c => c.GetILGenerator().Emit(OpCodes.Ret));
     }
     return(this._type.CreateType()
            .Apply(
                t => this._initializers.ForEach(_ =>
                                                new SymbolTable(symbols)
     {
         { "this", YacqExpression.TypeCandidate(t) },
     }
                                                .Let(s => _.Item2.Reduce(s, _.Item3.ReplaceGenericArguments(
                                                                             new Dictionary <Type, Type>()
     {
         { this._type, t },
     }
                                                                             ))
                                                     .Apply(e => (e != null
                         ? (LambdaExpression)e
                         : Expression.Lambda(_.Item2.Reduce(s))
                                                                  ).CompileToMethod(_.Item1))
                                                     )
                                                ),
                t => this._prologue.GetILGenerator().Emit(OpCodes.Ret),
                t => this._implType.CreateType(),
                t => this.IsCreated = true
                ));
 }
示例#6
0
 public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
 {
     try
     {
         return(new DynamicMetaObject(
                    YacqExpression.Function(this._symbols, "=",
                                            (Static.GetTargetType(target.Value)
                                             .Null(t => YacqExpression.TypeCandidate(this._symbols, t))
                                             ?? target.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType)
                                            ).Member(this._symbols, this.Name),
                                            value.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType)
                                            ).Reduce(this._symbols).TryConvert(typeof(Object)),
                    target.Restrictions
                    ));
     }
     catch (Exception ex)
     {
         return(errorSuggestion
                ?? new DynamicMetaObject(
                    Expression.Throw(Expression.Constant(ex), typeof(Object)),
                    BindingRestrictions.Empty
                    ));
     }
 }
示例#7
0
 public override Expression Deserialize()
 {
     return(YacqExpression.TypeCandidate(
                this.Candidates.Select(t => t.Deserialize())
                ));
 }
示例#8
0
 public static Expression RangeExact(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(LongRange))
            .Method(s, "FromPivotValue", e.Arguments[0]));
 }
示例#9
0
 public static Expression RangeFromTo(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(LongRange))
            .Method(s, "FromBetweenValues", e.Left, e.Arguments[0]));
 }
示例#10
0
 public static Expression ShowManualPage(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(Process)).Method(s, "Start",
                                                                 Expression.Constant("http://yacq.net/")
                                                                 ));
 }
示例#11
0
 public static Expression ExitRepl(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(Environment)).Method(s, "Exit",
                                                                     Expression.Constant(0)
                                                                     ));
 }
示例#12
0
 public static Expression CollectGarbage(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(GC)).Method(s, "Collect"));
 }
示例#13
0
        private static Expression Load(SymbolTable symbols, Object obj, String name)
        {
            if (name.StartsWithInvariant(CtsPrefix))
            {
                return(Expression.Constant(((IEnumerable <IGrouping <String, Type> >)obj)
                                           .Select(g => g.Key.Apply(k => symbols[k] = YacqExpression.TypeCandidate(symbols, g)))
                                           .ToArray()
                                           ));
            }
            else
            {
                var stream = (Stream)obj;
                switch (Path.GetExtension(name).ToLowerInvariant())
                {
                case ".dll":
#if SILVERLIGHT
                    throw new NotImplementedException("Loading DLL is not implemented in Sliverlight environment.");
#else
                    return(Expression.Constant(new Byte[stream.Length].Apply(b => stream.Read(b, 0, b.Length))
                                               .Let(Assembly.Load)
                                               .Apply(a => a.GetTypes()
                                                      .Where(t => t.IsPublic)
                                                      .ForEach(symbols.Import)
                                                      )
                                               ));
#endif
                case ".yacb":
                    throw new NotImplementedException("YACQ Binary code is not implemented.");

                default:
                    return(new StreamReader(stream, true)
                           .Dispose(r => YacqServices.Parse(symbols, r.ReadToEnd())));
                }
            }
        }