Esempio n. 1
0
        public static Expression Walk(Expression currentScopeVar, Ast.DataDecl decl)
        {
            Expression handlerDict =
                Expression.MakeIndex(
                    currentScopeVar,
                    typeof(DictionaryBonsaiFunction).GetProperty("Item",
                        typeof(BonsaiFunction), new Type[] { typeof(SymbolId) }),
                        new Expression[] { Expression.Constant("dataHandlers".ToSymbol()).ConvertTo<SymbolId>() });

            Expression handler =
                Expression.MakeIndex(
                    handlerDict.ConvertTo<Dictionary<SymbolId, BonsaiFunction>>(),
                    typeof(Dictionary<SymbolId, BonsaiFunction>).GetProperty("Item"),
                    new Expression[] { Expression.Constant(decl.DataTypeId.ToSymbol()).ConvertTo<SymbolId>() });

            var args = new List<Expression>(decl.Expressions.Count + 1);
            args.Add(handler);
            args.Add(currentScopeVar);
            args.AddRange(
                decl.Expressions.Select(
                    ex => Walk(currentScopeVar, ex).ConvertTo<object>()));

            return Expression.Dynamic(
                new BonsaiBinder(new CallInfo(1)),
                typeof(object),
                args.ToArray());
        }
Esempio n. 2
0
 public static Expression Walk(Expression currentScopeVar, Ast.Reference reference)
 {
     return Expression.MakeIndex(
         currentScopeVar,
         typeof(DictionaryBonsaiFunction).GetProperty("Item",
             typeof(BonsaiFunction), new Type[] { typeof(SymbolId) }),
         new Expression[] { Expression.Constant(SymbolTable.StringToId(reference.Name)) });
 }
Esempio n. 3
0
 public static Expression Walk(Expression currentScopeVar, Ast.Call call)
 {
     var arguments = new List<Expression>(call.Arguments.Count + 2);
     arguments.Add(Walk(currentScopeVar, call.Target));
     arguments.Add(currentScopeVar);
     foreach (var arg in call.Arguments) {
         arguments.Add(Walk(currentScopeVar, arg));
     }
     return Expression.Dynamic(
         new BonsaiBinder(new CallInfo(arguments.Count)),
         typeof(object),
         arguments);
 }
Esempio n. 4
0
        public static Expression Walk(Expression currentScopeVar, Ast.Block block)
        {
            var innerScopeParam = Expression.Parameter(typeof(DictionaryBonsaiFunction));

            var expressions = new List<Expression>();
            foreach(var statement in block.Statements) {
                expressions.Add(Walk(innerScopeParam, statement));
            }

            return Expression.New(
                typeof(BlockBonsaiFunction).GetConstructor(new Type[] { typeof(Func<DictionaryBonsaiFunction, object>), typeof(DictionaryBonsaiFunction) }),
                Expression.Lambda(
                    Expression.Block(expressions),
                    innerScopeParam),
                currentScopeVar);
        }
Esempio n. 5
0
 public static Expression Walk(Expression currentScopeVar, Ast.Sequence sequence)
 {
     return Expression.Block(
         sequence.Statements.Select(c => Walk(currentScopeVar, c)));
 }
Esempio n. 6
0
 public static Expression Walk(Expression currentScopeVar, Ast.Symbol symbol)
 {
     return Expression.Constant(
         Microsoft.Scripting.SymbolTable.StringToId(symbol.Name));
 }
Esempio n. 7
0
 public static Expression Walk(Expression currentScopeVar, Ast.String str)
 {
     return Expression.Constant(str.Value);
 }
Esempio n. 8
0
 public static Expression Walk(Expression currentScopeVar, Ast.Number number)
 {
     return Expression.Constant(number.Value);
 }
Esempio n. 9
0
 public static Expression Walk(Expression currentScopeVar, Ast.Node node)
 {
     Debug.Assert(node != null);
     var method = typeof(BonsaiExpressionGenerator).GetMethod("Walk", new Type[] { typeof(Expression), node.GetType() });
     Debug.Assert(method != null);
     try {
         return (Expression)method.Invoke(null, new object[] { currentScopeVar, node });
     } catch (TargetInvocationException ex) {
         throw ex.InnerException;
     }
 }