예제 #1
0
        public Expression VisitSuper(SuperExpression node)
        {
            var name = "__value";

            if (HoistedLocals.ContainsKey(name) == false)
            {
                HoistedLocals.Add(name, node);
            }
            return(node);
        }
예제 #2
0
 public object VisitSuper(SuperExpression node)
 {
     if (Target is object)
     {
         node.Type = TypeProvider.ObjectType;
         return(NoTarget);
     }
     node.Type = Target.GetType().BaseType;
     return(Target);
 }
예제 #3
0
파일: Resolver.cs 프로젝트: h2oboi89/lox
        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);
        }
예제 #4
0
        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));
        }