示例#1
0
        public object VisitCall(Expr.Call expr)
        {
            var callee = Evaluate(expr.Callee);

            // Assuming 'Select' is left-to-right, we'll evaluate arguments left-to-right.
            // In C, this is undefined, so... /shrug.
            var arguments = expr.Arguments
                            .Select(arg => Evaluate(arg))
                            .ToList();

            var callable = callee as ILoxCallable;

            if (callable != null)
            {
                // JavaScript discards extra arguments and sets missing ones to 'undefined'. We'll be stricter.
                if (arguments.Count != callable.Arity)
                {
                    throw new RuntimeError(expr.Paren,
                                           string.Format("Expected {0} arguments but got {1}",
                                                         callable.Arity, arguments.Count));
                }

                return(callable.Call(this, arguments));
            }
            else
            {
                throw new RuntimeError(expr.Paren, "Can only call functions and classes");
            }
        }
示例#2
0
        public object VisitCallExpr(Expr.Call expr)
        {
            var callee = Evaluate(expr.Callee);

            var arguments = new List <object>();

            expr.Arguments.ForEach((e) =>
            {
                arguments.Add(Evaluate(e));
            });

            if (!(callee is ILoxCallable))
            {
                throw new RuntimeError(expr.Paren, "Can only call functions and classes.");
            }

            var function = callee as ILoxCallable;

            if (arguments.Count != function.Arity)
            {
                throw new RuntimeError(expr.Paren, $"Expected {function.Arity} arguments but got {arguments.Count}.");
            }

            return(function.Call(this, arguments));
        }
示例#3
0
        object Expr.IVisitor <object> .VisitCallExpr(Expr.Call expr)
        {
            object callee = Evaluate(expr.callee);

            List <object> arguments = new List <object>();

            foreach (Expr argument in expr.arguments)
            {
                arguments.Add(Evaluate(argument));
            }

            if (!(callee is LoxCallable))
            {
                throw new RuntimeError(expr.paren, "Can only call functions and classes.");
            }

            LoxCallable function = (LoxCallable)callee;

            if (arguments.Count != function.Arity())
            {
                throw new RuntimeError(expr.paren, "Expected " +
                                       function.Arity() + " arguments but got " +
                                       arguments.Count + ".");
            }

            return(function.Call(this, arguments));
        }
示例#4
0
        public object VisitCallExpr(Expr.Call expr)
        {
            Resolve(expr.Callee);

            expr.Arguments.ForEach(e => Resolve(e));

            return(null);
        }
示例#5
0
        public Unit VisitCall(Expr.Call call)
        {
            Resolve(call.Callee);
            foreach (var arg in call.Arguments)
            {
                Resolve(arg);
            }

            return(Unit.Default);
        }
示例#6
0
文件: Resolver.cs 项目: leddt/cslox
        public Void Visit(Expr.Call expr)
        {
            Resolve(expr.Callee);

            foreach (var arg in expr.Arguments)
            {
                Resolve(arg);
            }

            return(Void.Instance);
        }
示例#7
0
        object Expr.IVisitor <object> .VisitCallExpr(Expr.Call expr)
        {
            Resolve(expr.callee);

            foreach (Expr argument in expr.arguments)
            {
                Resolve(argument);
            }

            return(null);
        }
示例#8
0
        public string VisitCall(Expr.Call call)
        {
            var builder = new StringBuilder();

            builder.Append("(call ");
            builder.Append(call.Callee.Accept(this));
            foreach (var arg in call.Arguments)
            {
                builder.Append(" ");
                builder.Append(arg.Accept(this));
            }

            builder.Append(")");
            return(builder.ToString());
        }
示例#9
0
 public string VisitCallExpr(Expr.Call expr)
 {
     throw new NotImplementedException();
 }