Beispiel #1
0
        public static void Doo3()
        {
            Func <dynamic, dynamic, object> binOp = (v1, v2) => v1 * v2;

            var scope  = Expression.Parameter(typeof(IScope), "scope");
            var stack  = Expression.Parameter(typeof(Stack), "stack");
            var value1 = Expression.Parameter(typeof(object), "value1");
            var value2 = Expression.Parameter(typeof(object), "value2");
            var result = Expression.Parameter(typeof(object), "result");
            var block  = Expression.Block(
                new ParameterExpression[] { value1, value2, result },
                Expression.Assign(value2, Expression.Call(stack, "Pop", Type.EmptyTypes)),
                Expression.Assign(value1, Expression.Call(stack, "Pop", Type.EmptyTypes)),
                Expression.Assign(result, Expression.Call(Expression.Constant(binOp.Target), binOp.Method, value1, value2)),
                Expression.Call(stack, "Push", Type.EmptyTypes, result));
            var lambda = Expression.Lambda <Action <IScope, IStack> >(block, scope, stack);
            var action = lambda.Compile();

            var xcontext = Context.Root(Binder.From("root"));
            var xstack   = Stack.From(Integer.From(10), Integer.From(10));

            action(xcontext, xstack);

            xstack.Push(Integer.From(10));
            xstack.Push(Integer.From(10));

            action(xcontext, xstack);
        }
Beispiel #2
0
        public static void Doo2()
        {
            var woo    = new Woo();
            var chars1 = "a";
            var chars2 = "b";
            var int1   = Integer.From(11);
            var int2   = Integer.From(12);

            woo.Call(woo, chars1, chars2);
            woo.Call(woo, chars1, chars2);

            Environment.Exit(12);
        }
 public static Func <long, T>?GetIntegerConverter <T>() =>
 (Func <long, T>?)Integer.From(typeof(T));