public Void visitClassStmt(Stmt.Class stmt)
        {
            environment.Define(stmt.name.lexeme, null);

            Dictionary <string, Function> methods = new Dictionary <string, Function>();

            foreach (Stmt.Function method in stmt.methods)
            {
                Function fn = new Function(method, environment);
                methods.Add(method.name.lexeme, fn);
            }

            Class klass = new Class(stmt.name.lexeme, methods);

            environment.Assign(stmt.name, klass);

            return(null);
        }
Exemple #2
0
        public Void visitClassStmt(Stmt.Class stmt)
        {
            Declare(stmt.name);
            Define(stmt.name);

            BeginScope();

            scopes.Peek().Add("this", true);

            foreach (Stmt.Function fn in stmt.methods)
            {
                FunctionType declaration = FunctionType.METHOD;
                ResolveFunction(fn, declaration);
            }

            EndScope();

            return(null);
        }