mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 09:28:03 +00:00
Started typeCheck for TypedProgram
This commit is contained in:
parent
d99dbd4f64
commit
e97b9e55c8
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user