mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 14:48:03 +00:00
add System out
This commit is contained in:
parent
09a327bdee
commit
d55217e85a
@ -98,6 +98,12 @@ public class TypedBlock implements TypedNode {
|
|||||||
typedMethodCall.typeCheck(typedProgram);
|
typedMethodCall.typeCheck(typedProgram);
|
||||||
stmts.add(typedMethodCall);
|
stmts.add(typedMethodCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stmt instanceof Print printStmt) {
|
||||||
|
TypedPrint typedPrint = new TypedPrint(typedProgram, printStmt);
|
||||||
|
typedPrint.typeCheck(typedProgram);
|
||||||
|
stmts.add(typedPrint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.typeCheck(typedProgram);
|
this.typeCheck(typedProgram);
|
||||||
}
|
}
|
||||||
|
34
src/main/java/de/maishai/typedast/typedclass/TypedPrint.java
Normal file
34
src/main/java/de/maishai/typedast/typedclass/TypedPrint.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package de.maishai.typedast.typedclass;
|
||||||
|
|
||||||
|
import de.maishai.ast.records.Print;
|
||||||
|
import de.maishai.typedast.*;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||||
|
|
||||||
|
public class TypedPrint implements TypedStatement {
|
||||||
|
private TypedExpression value;
|
||||||
|
private Type type;
|
||||||
|
|
||||||
|
public TypedPrint(TypedProgram typedProgram, Print untyped) {
|
||||||
|
value = convertExpression(typedProgram, untyped.value());
|
||||||
|
type = Type.VOID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void codeGen(MethodContext ctx) {
|
||||||
|
ctx.getMv().visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
|
||||||
|
ctx.pushAnonToStack();
|
||||||
|
value.codeGen(ctx);
|
||||||
|
ctx.getMv().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", CodeGenUtils.generateDescriptor(List.of(value.getType()), type), false);
|
||||||
|
ctx.popStack();
|
||||||
|
ctx.popStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Type typeCheck(TypedProgram typedProgram) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -6,15 +6,7 @@ public class ClassCanBeBytecoded {
|
|||||||
|
|
||||||
|
|
||||||
public int test(int var1) {
|
public int test(int var1) {
|
||||||
for (int i = 0; i < 12; i = i + 1) {
|
print(var1);
|
||||||
var1 = this.c.c.c.c.x + this.x;
|
|
||||||
if (var1 * 3 == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
while (var1 < 10) {
|
|
||||||
var1 = var1 + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return var1;
|
return var1;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user