示例#1
0
        public override object Call(AstInterpreter interpreter, IEnumerable <object> arguments)
        {
            var environment = new Environment(closure);

            foreach (var parameter in declaration.Parameters.Enumerate())
            {
                environment.Define(parameter.Value, arguments.ElementAt(parameter.Index));
            }

            try
            {
                interpreter.ExecuteBlock(declaration.Body, environment);
            }
            catch (LoxReturn returnValue)
            {
                return(isInitializer ? InstanceReference : returnValue.Value);
            }

            if (isInitializer)
            {
                return(InstanceReference);
            }

            return(null);
        }
示例#2
0
        public override object Call(AstInterpreter interpreter, IEnumerable <object> arguments)
        {
            var instance = new LoxInstance(this);

            Constructor?.Bind(instance).Call(interpreter, arguments);

            return(instance);
        }
示例#3
0
 public virtual object Call(AstInterpreter interpreter, IEnumerable <object> arguments)
 {
     throw new NotImplementedException();
 }