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

            environment.Define("this", instance);
            return(new LoxFunction(_declaration, environment, _isInitializer));
        }
예제 #2
0
파일: LoxClass.cs 프로젝트: loqix/CSharpLox
        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);
        }
예제 #3
0
파일: LoxClass.cs 프로젝트: loqix/CSharpLox
        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);
        }