Exemple #1
0
        public LoxFunction Bind(LoxInstance instance)
        {
            var environment = new EnvironmentScope(_closure);

            environment.Define("this", instance);
            return(new LoxFunction(_declaration, environment, _isInitializer));
        }
Exemple #2
0
        public object Call(Interpreter interpreter, List <object> arguments)
        {
            var instance = new LoxInstance(this);

            if (_methods.TryGetValue("init", out var init))
            {
                init.Bind(instance).Call(interpreter, arguments);
            }
            return(instance);
        }
Exemple #3
0
        public LoxFunction FindMethod(LoxInstance instance, string name)
        {
            if (_methods.TryGetValue(name, out var value))
            {
                return(value.Bind(instance));
            }

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

            return(null);
        }