public Expression VisitSuper(SuperExpression node) { var name = "__value"; if (HoistedLocals.ContainsKey(name) == false) { HoistedLocals.Add(name, node); } return(node); }
public object VisitSuper(SuperExpression node) { if (Target is object) { node.Type = TypeProvider.ObjectType; return(NoTarget); } node.Type = Target.GetType().BaseType; return(Target); }
public object VisitSuperExpression(SuperExpression expression) { if (!scope.InClass) { Interpreter.ScopeError(expression.Keyword, "Cannot use 'super' outside of a class."); } else if (!scope.InSubclass) { Interpreter.ScopeError(expression.Keyword, "Cannot use 'super' in a class with no superclass."); } scope.ResolveValue(expression, expression.Keyword); return(null); }
public object VisitSuperExpression(SuperExpression expression) { var distance = locals[expression]; var superclass = (LoxClass)environment.Get(superToken, distance); // "this" is always one level closer than "super"'s environment var instance = (LoxInstance)environment.Get(thisToken, distance - 1); var method = superclass[expression.Method.Lexeme]; if (method == null) { throw new LoxRunTimeException(expression.Method, $"Undefined property '{expression.Method.Lexeme}'."); } return(method.Bind(instance)); }