示例#1
0
 public object VisitSuperExpr(Expr.Super expr)
 {
     if (currentClass == ClassType.None)
     {
         Basil.Error(expr.Keyword, "Cannot use 'super' outside of a class.");
     }
     else if (currentClass != ClassType.Subclass)
     {
         Basil.Error(expr.Keyword, "Cannot use 'super' in a class with no superclass.");
     }
     ResolveLocal(expr, expr.Keyword);
     return(null);
 }
示例#2
0
        public object VisitSuperExpr(Expr.Super expr)
        {
            int        distance   = locals[expr];
            BasilClass superclass = (BasilClass)environment.GetAt(distance, "super");
            // "this" is always one level nearer than "super"'s environment.
            BasilInstance objekt = (BasilInstance)environment.GetAt(distance - 1, "this");
            BasilFunction method = superclass.FindMethod(objekt, expr.Method.lexeme);

            if (method == null)
            {
                throw new RuntimeError(expr.Method, $"Undefined property '{expr.Method.lexeme}'.");
            }
            return(method);
        }
示例#3
0
 public string VisitSuperExpr(Expr.Super expr)
 {
     throw new System.NotImplementedException();
 }