public static Expression Clear(DispatchExpression e, SymbolTable s, Type t) { return YacqExpression.Dispatch( s, DispatchTypes.Method, s.Resolve("*textbox*"), "Clear" ); }
public static Expression Write(DispatchExpression e, SymbolTable s, Type t) { return YacqExpression.Dispatch( s, DispatchTypes.Method, s.Resolve("*textbox*"), "AppendText", YacqExpression.Dispatch( s, DispatchTypes.Method, e.Left, "ToString" ) ); }
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); }
public static Expression WriteLine(DispatchExpression e, SymbolTable s, Type t) { return YacqExpression.Dispatch( s, DispatchTypes.Method, YacqExpression.Dispatch( s, DispatchTypes.Method, "+", YacqExpression.Dispatch( s, DispatchTypes.Method, e.Left, "ToString" ), Expression.Constant("\n") ), "printn" ); }
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"); }
public static Expression ReferenceNotEqual(DispatchExpression e, SymbolTable s, Type t) { return e.Arguments.Count == 2 ? YacqBinder.IsInDynamicContext(s, e.Arguments.Take(2)) ? (Expression) Expression.Dynamic( YacqBinder.BinaryOperation(s, ExpressionType.NotEqual), typeof(Object), e.Arguments.Take(2).ReduceAll(s) ) : new [] { e.Arguments[0].Reduce(s), e.Arguments[1].Reduce(s), } .Let(a => YacqExpression.ConvertNumericTypeForAlithmetics(a[0].Type, a[1].Type) .Let(_ => Expression.ReferenceNotEqual(a[0].TryConvert(_), a[1].TryConvert(_))) ) : YacqExpression.Function(s, "&&", YacqExpression.Function(s, "!==", e.Arguments[0], e.Arguments[1]), YacqExpression.Function(s, "!==", e.Arguments.Skip(1)) ); }
public static Expression Global(DispatchExpression e, SymbolTable s, Type t) { return YacqExpression.SymbolTable(s.Resolve("$global").Const<SymbolTable>()); }
public static Expression Compare(DispatchExpression e, SymbolTable s, Type t) { return e.Arguments[0].Method(s, "CompareTo", e.Arguments[1]); }
public static Expression HereSymbol(DispatchExpression e, SymbolTable s, Type t) { return s.Resolve("$global"); }
public static Expression Nothing(DispatchExpression e, SymbolTable s, Type t) { return t == null || t.IsGenericParameter ? Expression.Constant(null) : t == typeof(void) ? (Expression) Expression.Empty() : Expression.Default(t); }
public static Expression NotAnd(DispatchExpression e, SymbolTable s, Type t) { return YacqExpression.Function(s, "!", YacqExpression.Function(s, "&", e.Arguments) ); }
/// <summary> /// Default definition method of <see cref="SymbolTable.Missing"/>. /// </summary> /// <param name="e">The expression to be reduced.</param> /// <param name="s">The symbol table which this symbol (value) belongs.</param> /// <param name="t">The expected <see cref="Expression.Type"/> from the caller, or <c>null</c> if any type will be accepted.</param> /// <returns>The reduced expression.</returns> public static Expression DefaultMissing(DispatchExpression e, SymbolTable s, Type t) { return(e._left is DynamicExpression || YacqBinder.IsInDynamicContext(s, e.Arguments.StartWith(e.Left)) ? e.DispatchByDynamicBinder(s, t) : e.DispatchByTypeSystem(s, t)); }
public static Expression PowerAssign(DispatchExpression e, SymbolTable s, Type t) { // TODO: Support type-specific Power method return e.Arguments[0].Reduce(s).Let(l => (e.Arguments.Count == 2 ? e.Arguments[1] : YacqExpression.Function(s, "**", e.Arguments.Skip(1)) ).Let(r => l.Type == r.Type(s) && l.Type == typeof(Double) ? (Expression) Expression.PowerAssign(l, r.Reduce(s)) : YacqExpression.Function(s, "=", l, ((Expression) YacqExpression.Function(s, "**", e.Arguments[0], r)).If( _ => !YacqBinder.IsInDynamicContext(s, r), _ => _.ReduceAndTryConvert(s, l.Type) ) ) ) ); }
public static Expression RightShift(DispatchExpression e, SymbolTable s, Type t) { return (YacqBinder.IsInDynamicContext(s, e.Arguments.Take(2)) ? (Expression) Expression.Dynamic( YacqBinder.BinaryOperation(s, ExpressionType.RightShift), typeof(Object), e.Arguments.Take(2).ReduceAll(s) ) : Expression.RightShift(e.Arguments[0].Reduce(s), e.Arguments[1].ReduceAndTryConvert(s, typeof(Int32))) ).Let(_ => e.Arguments.Count > 2 ? (Expression) YacqExpression.Function(s, ">>", e.Arguments .Skip(2) .StartWith(_) ) : _ ); }
public static Expression GetTypeObject(DispatchExpression e, SymbolTable s, Type t) { return Expression.Constant( ((TypeCandidateExpression) e.Left.Reduce(s)).ElectedType ); }
private static Expression _Try(DispatchExpression e, SymbolTable s, Type t, Type returnType) { return Expression.MakeTry( returnType, e.Left.Reduce(s), null, null, e.Arguments .SkipLast(e.Arguments.Count % 2) .Buffer(2) .Select(c => (c.First() as VectorExpression) .Null(v => (IList<Expression>) v.Elements, new [] { c.First(), }) .Let(ves => (ves[0].List(":").If( les => les != null, les => new SymbolTable(s) { {les.First().Id(), Expression.Parameter( ((TypeCandidateExpression) les.Last().Reduce(s)).ElectedType, les.First().Id() )} } .Let(ns => Expression.Catch( (ParameterExpression) ns.Literals.Values.Single(), c.Last().Reduce(ns), ves.Count > 1 ? ves[1].Reduce(ns) : null )), les => Expression.Catch( ((TypeCandidateExpression) ves[0].Reduce(s)).ElectedType, c.Last().Reduce(s), ves.Count > 1 ? ves[1].Reduce(s) : null ) ) )) ) .If(_ => e.Arguments.Count % 2 == 1, _ => _.StartWith(Expression.Catch( typeof(Exception), e.Arguments.Last().Reduce(s)) ) ) .ToArray() ); }
public static Expression MakeSequenceType(DispatchExpression e, SymbolTable s, Type t) { return YacqExpression.TypeCandidate( typeof(IEnumerable<>).MakeGenericType(((TypeCandidateExpression) e.Left.Reduce(s)).ElectedType) ); }
public static Expression MakeArrayType(DispatchExpression e, SymbolTable s, Type t) { return YacqExpression.TypeCandidate( ((TypeCandidateExpression) e.Left.Reduce(s)).ElectedType.MakeArrayType() ); }
public static Expression GetStaticMembersAndSymbols(DispatchExpression e, SymbolTable s, Type t) { return Expression.Constant(((TypeCandidateExpression) e.Left.Reduce(s)).Candidates .Select(Static.Type) .ToArray() .Let(ts => DispatchExpression.GetMembers(s, ts) .Where(m => m.GetAccessibility() == MemberAccessibilities.Public && !m.IsSpecialName()) .OrderBy(m => m is MethodInfo ? ((MethodInfo) m).IsExtensionMethod() ? 2 : 1 : 0 ) .ThenBy(m => m.Name) .Select(m => m is MethodBase ? "(" + m.Name + ")" : m.Name ) .Concat(s.AllKeys .Where(_ => ts.Any(_.TypeMatch)) .OrderBy(_ => _.DispatchType.HasFlag(DispatchTypes.Member) ? 0 : 1 ) .ThenBy(m => m.Name) .Select(_ => _.DispatchType.HasFlag(DispatchTypes.Member) ? _.Name : "(" + _.Name + ")" ) ) .Distinct() )); }
public static Expression And(DispatchExpression e, SymbolTable s, Type t) { return (YacqBinder.IsInDynamicContext(s, e.Arguments.Take(2)) ? (Expression) Expression.Dynamic( YacqBinder.BinaryOperation(s, ExpressionType.And), typeof(Object), e.Arguments.Take(2).ReduceAll(s) ) : new [] { e.Arguments[0].Reduce(s), e.Arguments[1].Reduce(s), } .Let(a => YacqExpression.ConvertNumericTypeForAlithmetics(a[0].Type, a[1].Type) .Let(_ => Expression.And(a[0].TryConvert(_), a[1].TryConvert(_))) ) ).Let(_ => e.Arguments.Count > 2 ? (Expression) YacqExpression.Function(s, "&", e.Arguments .Skip(2) .StartWith(_) ) : _ ); }
public static Expression RightShiftAssign(DispatchExpression e, SymbolTable s, Type t) { return e.Arguments[0].Reduce(s).Let(l => (e.Arguments.Count == 2 ? e.Arguments[1] : YacqExpression.Function(s, ">>", e.Arguments.Skip(1)) ).Let(r => r.Type(s) == typeof(Int32) && new [] { typeof(SByte), typeof(Byte), typeof(Int16), typeof(UInt16), typeof(Int32), typeof(UInt32), typeof(Int64), typeof(UInt64), }.Contains(l.Type) || l.Type.GetMethod("op_RightShift", BindingFlags.Public | BindingFlags.Static, null, new [] { l.Type, r.Type(s), }, null) != null ? (Expression) Expression.RightShiftAssign(l, r.Reduce(s)) : YacqExpression.Function(s, "=", l, ((Expression) YacqExpression.Function(s, ">>", e.Arguments[0], r)).If( _ => !YacqBinder.IsInDynamicContext(s, r), _ => _.ReduceAndTryConvert(s, l.Type) ) ) ) ); }
public static Expression AndAssign(DispatchExpression e, SymbolTable s, Type t) { return YacqBinder.IsInDynamicContext(s, e.Arguments.Take(2)) ? (Expression) YacqExpression.Function(s, "=", e.Arguments[0], YacqExpression.Function(s, "&", e.Arguments) ) : Expression.AndAssign(e.Arguments[0].Reduce(s), e.Arguments.Count == 2 ? e.Arguments[1].Reduce(s) : YacqExpression.Function(s, "&", e.Arguments.Skip(1)).Reduce(s) ); }
public static Expression Break(DispatchExpression e, SymbolTable s, Type t) { return YacqExpression.TypeCandidate(typeof(Debugger)) .Member(s, "IsAttached") .Method(s, "cond", YacqExpression.Function(s, "let", YacqExpression.TypeCandidate(typeof(Debugger)).Method("Break"), Expression.Constant(false) ), YacqExpression.Function(s, "let", YacqExpression.TypeCandidate(typeof(Debugger)).Method("Launch"), Expression.Constant(true) ) ); }
internal static Dispatch Dispatch(DispatchExpression expression) { return new Dispatch() { DispatchType = expression.DispatchType, Left = expression.Left.Null(e => Serialize(e)), Name = expression.Name, TypeArguments = expression.TypeArguments.Select(TypeRef.Serialize).ToArray(), Arguments = expression.Arguments.Select(Serialize).ToArray(), }.Apply(n => n.TypeHint = expression.TryType().Null(t => TypeRef.Serialize(t))); }
public static Expression Not(DispatchExpression e, SymbolTable s, Type t) { return YacqBinder.IsInDynamicContext(s, e.Arguments[0]) ? (Expression) Expression.Dynamic( YacqBinder.UnaryOperation(s, ExpressionType.Not), typeof(Object), e.Arguments[0].Reduce(s) ) : Expression.Not(e.Arguments[0].Reduce(s)); }
/// <summary> /// Default definition method of <see cref="SymbolTable.Missing"/>. /// </summary> /// <param name="e">The expression to be reduced.</param> /// <param name="s">The symbol table which this symbol (value) belongs.</param> /// <param name="t">The expected <see cref="Expression.Type"/> from the caller, or <c>null</c> if any type will be accepted.</param> /// <returns>The reduced expression.</returns> public static Expression DefaultMissing(DispatchExpression e, SymbolTable s, Type t) { return e._left is DynamicExpression || YacqBinder.IsInDynamicContext(s, e.Arguments.StartWith(e.Left)) ? e.DispatchByDynamicBinder(s, t) : e.DispatchByTypeSystem(s, t); }
public static Expression OnesComplement(DispatchExpression e, SymbolTable s, Type t) { return YacqBinder.IsInDynamicContext(s, e.Arguments[0]) ? (Expression) Expression.Dynamic( YacqBinder.UnaryOperation(s, ExpressionType.OnesComplement), typeof(Object), e.Arguments[0].Reduce(s) ) : Expression.OnesComplement(e.Arguments[0].Reduce(s) .Let(_ => _.TryConvert(YacqExpression.ConvertNumericTypeForAlithmetics(_.Type, false))) ); }
public static Expression GetGlobalSymbols(DispatchExpression e, SymbolTable s, Type t) { return Expression.Constant( (e.Left.Reduce(s) as SymbolTableExpression) .Null(se => se.Symbols, s) .AllKeys .Where(_ => _.LeftType == null) .OrderBy(_ => _.DispatchType.HasFlag(DispatchTypes.Member) ? 0 : 1 ) .ThenBy(m => m.Name) .Select(_ => _.DispatchType.HasFlag(DispatchTypes.Member) ? _.Name : "(" + _.Name + ")" ) ); }
public static Expression Assign(DispatchExpression e, SymbolTable s, Type t) { return (e.Arguments[0].List(".") .Null(l => YacqBinder.IsInDynamicContext(s, l.First()) ? Expression.Dynamic( YacqBinder.SetMember(s, l.Last().Id()), typeof(Object), l.First().Reduce(s), e.Arguments[1].Reduce() ) : null ) ?? e.Arguments[0].Reduce(s).Let(l => (Expression) Expression.Assign(l, e.Arguments.Last().Reduce(s, l.Type)) ) ).Let(_ => e.Arguments.Count > 2 ? (Expression) YacqExpression.Function(s, "=", e.Arguments .Skip(1) .SkipLast(1) .EndWith(_) ) : _ ); }
public static Expression PostDecrementAssign(DispatchExpression e, SymbolTable s, Type t) { return e.Arguments[0].Reduce(s).Let(a => YacqBinder.IsInDynamicContext(s, e.Arguments[0]) ? Expression.Dynamic( YacqBinder.UnaryOperation(s, ExpressionType.PostDecrementAssign), typeof(Object), a ) : new [] { typeof(Int16), typeof(UInt16), typeof(Int32), typeof(UInt32), typeof(Int64), typeof(UInt64), typeof(Single), typeof(Double), }.Contains(a.Type) || a.Type.GetMethod("op_Decrement", BindingFlags.Public | BindingFlags.Static, null, new [] { a.Type, }, null) != null ? (Expression) Expression.PostDecrementAssign(a) : YacqExpression.Function(s, "$", YacqExpression.Vector(s, YacqExpression.Identifier(s, "._val"), a ), YacqExpression.Function(s, "=", a, YacqExpression.Function(s, "-", a, Expression.Constant(1)).ReduceAndTryConvert(s, a.Type) ), YacqExpression.Identifier(s, "._val") ) ); }
public static Expression Here(DispatchExpression e, SymbolTable s, Type t) { return YacqExpression.SymbolTable(YacqExpression.Variable(s, ModuleIdentifier).Const<SymbolTable>()); }