Exemplo n.º 1
0
 public SilverFunction(string name, List<FunctionArgument> arguments, BlockExpression body, SilverScope context)
 {
     Name = name;
     Arguments = arguments;
     Body = body;
     Context = context;
 }
Exemplo n.º 2
0
        public override object Run(Scope scope)
        {
            var body = (Body as BlockExpression);
            body.Scope.MergeWithScope(Silver.Globals);
            body.Scope.MergeWithScope(scope);

            var visitor = new VariableNameVisitor();
            visitor.Visit(body);

            body.SetChildrenScopes(body.Scope);

            dynamic block = CompilerServices.CreateLambdaForExpression(body);
            dynamic res = block();

            if (res is Symbol) {
                var symval = new BlockExpression(new List<Expression> {new VariableExpression(res)}, body.Scope);
                res = CompilerServices.CreateLambdaForExpression(symval)();
            }
            else if (res is SilverInstance) {
                var so = (SilverInstance) res;
                if (so is SilverBoxedInstance) {
                    res = ((SilverBoxedInstance) so).BoxedObject;
                }
            }
            else if (res is SilverNumber)
            {
                res = SilverNumber.Convert(res);
            }
            else if (res is SilverString) {
                res = (string) res;
            }
            else if (res is SilverArray) {
                res = ConvertElements((SilverArray)res);
            }
            else if (res is SilverDictionary) {
                res = ConvertElements((SilverDictionary)res);
            }

            body.Scope.MergeIntoScope(scope);

            return res;
        }
Exemplo n.º 3
0
        internal object Run(SilverScope scope)
        {
            var body = (BlockExpression) Body;

            body.SetScope(scope);

            body.SetChildrenScopes(body.Scope);

            dynamic block = CompilerServices.CreateLambdaForExpression(Expression.Block(body));

            dynamic res = block();

            if (res is Symbol) {
                var symval = new BlockExpression(new List<Expression> {new VariableExpression(res)}, body.Scope);
                res = CompilerServices.CreateLambdaForExpression(symval)();
            }

            return res;
        }
 protected virtual Expression VisitBlock(BlockExpression node)
 {
     node.Body.ForEach(arg => Visit(arg));
     return node;
 }