package org.karaffe.compiler;

public class KaraffeCompiler {
    private final CompilerContext context;

    public KaraffeCompiler() {
        this(new CompilerContext());
    }

    public KaraffeCompiler(CompilerContext context) {
        this.context = context;
    }

    public void run() {
        if (this.context.getRawArgs().length == 0) {
            this.context.addOutputs("Usage:");
            this.context.addOutputs("  krfc <options> <sources>");
        }
    }

    public String out() {
        return context.getOutputText();
    }
}

@@ -24,16 +24,680 @@
 piler;%0A%0A
+import net.nokok.azm.ClassWriter;%0Aimport net.nokok.azm.Opcodes;%0Aimport net.nokok.azm.Type;%0Aimport org.antlr.v4.runtime.CharStream;%0Aimport org.antlr.v4.runtime.CharStreams;%0Aimport org.antlr.v4.runtime.CommonTokenStream;%0Aimport org.karaffe.compiler.frontend.karaffe.antlr.KaraffeBaseVisitor;%0Aimport org.karaffe.compiler.frontend.karaffe.antlr.KaraffeLexer;%0Aimport org.karaffe.compiler.frontend.karaffe.antlr.KaraffeParser;%0Aimport org.karaffe.compiler.util.KaraffeSource;%0A%0Aimport java.io.IOException;%0Aimport java.io.UncheckedIOException;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 public c
@@ -984,36 +984,292 @@
 ext.
-getRawArgs().length == 0) %7B%0A
+requireShowUsage()) %7B%0A            this.context.addOutputs(%22Usage:%22);%0A            this.context.addOutputs(%22  krfc %3Coptions%3E %3Csources%3E%22);%0A            return;%0A        %7D%0A        for (String arg : context.getRawArgs()) %7B%0A            if (arg.endsWith(%22.krf%22)) %7B%0A                try %7B%0A      
     
@@ -1268,32 +1268,34 @@
                 
+  
 this.context.add
@@ -1298,93 +1298,1840 @@
 .add
-Outputs(%22Usage:%22);%0A            this.context.addOutputs(%22  krfc %3Coptions%3E %3Csources%3E%22);
+Source(KaraffeSource.fromPath(Paths.get(arg)));%0A                %7D catch (IOException e) %7B%0A                    throw new UncheckedIOException(e);%0A                %7D%0A            %7D%0A        %7D%0A        List%3CKaraffeSource%3E sources = context.getSources();%0A        for (KaraffeSource source : sources) %7B%0A            CharStream charStream;%0A            if (source.hasFilePath()) %7B%0A                throw new UnsupportedOperationException(%22Not implemented%22);%0A            %7D else %7B%0A                charStream = CharStreams.fromString(sources.toString());%0A            %7D%0A            KaraffeLexer lexer = new KaraffeLexer(charStream);%0A            lexer.removeErrorListeners();%0A            KaraffeParser parser = new KaraffeParser(new CommonTokenStream(lexer));%0A            KaraffeParser.CompilationUnitContext compilationUnitContext = parser.compilationUnit();%0A            compilationUnitContext.accept(new KaraffeBaseVisitor%3CVoid%3E() %7B%0A                @Override%0A                public Void visitClassDef(KaraffeParser.ClassDefContext ctx) %7B%0A                    ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);%0A                    classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, ctx.Identifier().getText(), null, Type.getInternalName(Object.class), null);%0A                    classWriter.visitEnd();%0A                    byte%5B%5D bytes = classWriter.toByteArray();%0A                    context.addOutputFile(Paths.get(ctx.Identifier().getText() + %22.class%22), bytes);%0A                    return super.visitClassDef(ctx);%0A                %7D%0A            %7D);%0A        %7D%0A        for (Map.Entry%3CPath, byte%5B%5D%3E entry : context.getOutputFiles().entrySet()) %7B%0A            try %7B%0A                Files.write(entry.getKey(), entry.getValue());%0A            %7D catch (IOException e) %7B%0A                throw new UncheckedIOException(e);%0A            %7D
 %0A   

Add simple code generation