示例#1
0
 public object visitSuperExpr(Expr.Super expr)
 {
     if (currentClass != ClassType.SUBCLASS)
     {
         Lox.ReportError(expr.keyword, "Can't use 'super' outside of a sub class.");
     }
     else
     {
         ResolveLocal(expr, expr.keyword.lexeme, AccessType.RHS);
     }
     return(null);
 }
示例#2
0
        public object visitSuperExpr(Expr.Super expr)
        {
            var      exprLocationData = locals[expr];
            LoxClass superclass       = (LoxClass)environment.GetAt(exprLocationData.depth, exprLocationData.index);
            // We know "this" is one environment removed from "super" because of the way we set the environments up
            // in visitClassStmt. Hacky fix but it works. We also know its index is 0 because "this" is the only variable
            // in its environment.
            LoxInstance instance = (LoxInstance)environment.GetAt(exprLocationData.depth - 1, 0);
            LoxFunction method   = superclass.FindMethod(expr.method.lexeme);

            if (method == null)
            {
                throw new RuntimeError(expr.method, "Undefined superclass property '" + expr.method.lexeme + "'.");
            }
            return(method.Bind(instance));
        }
示例#3
0
 public string visitSuperExpr(Expr.Super expr)
 {
     throw new NotImplementedException();
 }