Esempio n. 1
0
        public Void VisitBaseExpr(Expr.Base expr)
        {
            if (currentClass == ClassType.NONE)
            {
                ElizScriptCompiler.Error(expr.keyword, "Cannot use 'base' outside of a class.");
            }
            else if (currentClass != ClassType.SUBCLASS)
            {
                ElizScriptCompiler.Error(expr.keyword, "Cannot use 'base' in a class with no baseclass.");
            }

            ResolveLocal(expr, expr.keyword);
            return(null);
        }
Esempio n. 2
0
        public object VisitBaseExpr(Expr.Base expr)
        {
            int distance = locals[expr];

            ElizClass superclass = (ElizClass)environment.GetAt(distance, "base");

            // "this" is always one level nearer than "super"'s environment.
            ElizInstance @object = (ElizInstance)environment.GetAt(distance - 1, "this");

            ElizFunction method = superclass.FindMethod(expr.method.Lexeme);

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

            return(method.Bind(@object));
        }