コード例 #1
0
ファイル: LoxClass.cs プロジェクト: drewbanas/jloxcs
        public LoxFunction findMethod(string name)
        {
            if (methods.ContainsKey(name))
            {
                return(methods[name]);
            }

            if (superclass != null)
            {
                return(superclass.findMethod(name));
            }

            return(null);
        }
コード例 #2
0
ファイル: LoxInstance.cs プロジェクト: drewbanas/jloxcs
        public object get(Token name)
        {
            if (fields.ContainsKey(name.lexeme))
            {
                return(fields[name.lexeme]);
            }

            LoxFunction method = klass.findMethod(name.lexeme);

            if (method != null)
            {
                return(method.bind(this));// method;
            }
            throw new RuntimeError(name, "Undefined property '" + name.lexeme + "'.");
        }
コード例 #3
0
        public object visitSuperExpr(Expr.Super expr)
        {
            int      distance   = locals[expr];
            LoxClass superclass = (LoxClass)environment.getAt(distance, "super");

            // "this" is always one level nearer than "super"'s environment
            LoxInstance object_ = (LoxInstance)environment.getAt(distance - 1, "this");

            LoxFunction method = superclass.findMethod(expr.method.lexeme);

            if (method == null)
            {
                throw new RuntimeError(expr.method, "Undefined property '" + expr.method.lexeme + "'.");
            }

            return(method.bind(object_));
        }