コード例 #1
0
ファイル: Interpreter.cs プロジェクト: gajcowan/cox
        public object VisitCallExpr(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 ICallable))
            {
                // TODO: Change error message to not mention classes explicitly
                // since this shows up before classes are implemented.
                throw new RuntimeError(expr.Paren, "Can only call functions and classes.");
            }

            ICallable function = (ICallable)callee;

            if (arguments.Count < function.RequiredArguments())
            {
                throw new RuntimeError(expr.Paren, "Not enough arguments.");
            }

            return(function.Call(this, arguments));
        }