Started typeCheck for TypedProgram

This commit is contained in:
Ahmad 2024-05-14 14:45:16 +02:00
parent d99dbd4f64
commit e97b9e55c8
2 changed files with 40 additions and 26 deletions

View File

@ -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<String> fromSources) {
List<Class> 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<String> 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);
}

View File

@ -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<TypedClass> 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;
}
}