diff --git a/src/main/java/de/maishai/Compiler.java b/src/main/java/de/maishai/Compiler.java index 043d1cf..7301c38 100644 --- a/src/main/java/de/maishai/Compiler.java +++ b/src/main/java/de/maishai/Compiler.java @@ -6,6 +6,7 @@ import de.maishai.ast.records.Class; import de.maishai.ast.records.Program; import de.maishai.typedast.CodeGenUtils; import de.maishai.typedast.typedclass.TypedClass; +import de.maishai.typedast.typedclass.TypedProgram; import org.antlr.v4.runtime.*; import java.io.IOException; @@ -16,26 +17,6 @@ import java.util.List; * Decaf language Compiler */ public class Compiler { -/* - public static void main(String[] args) { - generateAST(""" - public class ClassWithConstructorWithParameters { - int x; - public ClassWithConstructorWithParameters(int startValue, int repetitions) { - this.x = startValue; - while (repetitions > 0) { - int innerRepetitions; - innerRepetitions = this.x; - while (innerRepetitions > 0) { - this.x = this.x * this.x; - innerRepetitions -= 1; - } - repetitions -= 1; - } - } - } - """); - } */ public static Program generateAST(List fromSources) { List classes = new ArrayList<>(); @@ -65,19 +46,19 @@ public class Compiler { return generateAST(sources); } - public static TypedClass generateTypedASTFromAst(Program ast) { + public static TypedProgram generateTypedASTFromAst(Program ast) { TypedClass typedAST = new TypedClass(); - typedAST = (TypedClass) typedAST.startConversion(ast); - return typedAST; + TypedProgram typedProgram = new TypedProgram(ast); + return typedProgram; } - public static byte[] generateByteCodeArrayFromTypedAst(TypedClass typedAST) { + public static byte[] generateByteCodeArrayFromTypedAst(TypedProgram typedAST) { return typedAST.codeGen(); } public static byte[] generateByteCodeArray(List fromSources) { Program ast = generateAST(fromSources); - TypedClass typedAST = generateTypedASTFromAst(ast); + TypedProgram typedAST = generateTypedASTFromAst(ast); return generateByteCodeArrayFromTypedAst(typedAST); } @@ -99,7 +80,7 @@ public class Compiler { classes.add(ast); } Program program = new Program(classes); - TypedClass typedAST = generateTypedASTFromAst(program); + TypedProgram typedAST = generateTypedASTFromAst(program); //TODO: Für jede Klasse einzeln Bytecode generieren return generateByteCodeArrayFromTypedAst(typedAST); } diff --git a/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java b/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java new file mode 100644 index 0000000..3c636bd --- /dev/null +++ b/src/main/java/de/maishai/typedast/typedclass/TypedProgram.java @@ -0,0 +1,33 @@ +package de.maishai.typedast.typedclass; + +import de.maishai.ast.records.Program; +import de.maishai.typedast.ClassContext; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; + +import java.util.ArrayList; +import java.util.List; + +public class TypedProgram { + private List typedClasses = new ArrayList<>(); + + + public TypedProgram(Program program){ + startConversion(program); + } + public void startConversion(Program program){ + + program.classes().toString(); + + } + + + public byte[] codeGen() { + //TODO: implement this quickly + + return null; + } + + + +}