コード例 #1
0
ファイル: Interpreter.cs プロジェクト: mikebrasher/LoxSharp
        public object Visit(Expr.Call expr)
        {
            object callee = Evaluate(expr.callee);

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

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

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

            ILoxCallable function = (ILoxCallable)callee;

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

            return(function.Call(this, arguments));
        }
コード例 #2
0
ファイル: Resolver.cs プロジェクト: mikebrasher/LoxSharp
        public object Visit(Expr.Call expr)
        {
            Resolve(expr.callee);

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

            return(null);
        }