예제 #1
0
        public LoxFunction Bind(LoxInstance instance)
        {
            var environment = new Environment(closure);

            environment.Define("this", instance);
            return(new LoxFunction(declaration, environment, isInitializer));
        }
예제 #2
0
        public object Call(Interpreter interpreter, List <object> arguments)
        {
            var instance    = new LoxInstance(this);
            var initializer = FindMethod(instance, "init");

            if (initializer != null)
            {
                initializer.Call(interpreter, arguments);
            }
            return(instance);
        }
예제 #3
0
        public LoxFunction FindMethod(LoxInstance instance, string name)
        {
            if (methods.ContainsKey(name))
            {
                return(methods[name].Bind(instance));
            }

            if (superClass != null)
            {
                return(superClass.FindMethod(instance, name));
            }

            return(null);
        }