Ejemplo n.º 1
0
        public LoxFunction Bind(LoxInstance instance)
        {
            Environment environment = new Environment(_closure);

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

            if (_methods.TryGetValue("init", out LoxFunction initializer))
            {
                initializer.Bind(instance).Call(interpreter, arguments);
            }

            return(instance);
        }
Ejemplo n.º 3
0
        public Option <LoxFunction> FindMethod(LoxInstance instance, string name)
        {
            if (_methods.TryGetValue(name, out LoxFunction method))
            {
                return(method.Bind(instance).Some());
            }

            return(_superclass.Match(
                       some: superclass => superclass.FindMethod(instance, name),
                       none: Option.None <LoxFunction>
                       ));
        }