mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-07 00:06:12 +00:00
Codegen implementation stuff & typed AST nodes
This commit is contained in:
@@ -2,6 +2,7 @@ package codegen;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.ErrorHandler;
|
||||
import com.dfsek.terra.addons.terrascript.ast.Stmt.Block;
|
||||
import com.dfsek.terra.addons.terrascript.ast.TypedStmt;
|
||||
import com.dfsek.terra.addons.terrascript.codegen.TerraScript;
|
||||
import com.dfsek.terra.addons.terrascript.codegen.asm.TerraScriptClassGenerator;
|
||||
import com.dfsek.terra.addons.terrascript.lexer.Lexer;
|
||||
@@ -10,11 +11,59 @@ import com.dfsek.terra.addons.terrascript.semanticanalysis.SemanticAnalyzer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class CodeGenTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
testValid("""
|
||||
|
||||
if (1 == 1) print("Dis is true");
|
||||
|
||||
num a = 1;
|
||||
num b = 2;
|
||||
str e = "test";
|
||||
|
||||
if (a <= b) {
|
||||
print("a is <= b");
|
||||
} else {
|
||||
print("a is not <= b");
|
||||
}
|
||||
|
||||
if (e == "foo") {
|
||||
print("e is == foo");
|
||||
} else if (e == "bar") {
|
||||
print("e is == bar");
|
||||
} else {
|
||||
print("e is not foo or bar");
|
||||
}
|
||||
|
||||
if (true && false || (false && true)) {
|
||||
print("Thin is tru");
|
||||
} else {
|
||||
print("Thin is not tru :(");
|
||||
}
|
||||
|
||||
fun loopTwiceThenBreak() {
|
||||
num i = 0;
|
||||
while (true) {
|
||||
if (i == 2) break;
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
loopTwiceThenBreak();
|
||||
|
||||
retNum();
|
||||
bool bln = true;
|
||||
|
||||
print(takesArgs("test", 3, true));
|
||||
print(retStr());
|
||||
|
||||
doStuff("Ayo", "world", true);
|
||||
|
||||
fun retNum(): num {
|
||||
return 3 + 3;
|
||||
}
|
||||
@@ -49,26 +98,14 @@ public class CodeGenTest {
|
||||
print("c is false");
|
||||
}
|
||||
}
|
||||
|
||||
num a = 1;
|
||||
num b = 2;
|
||||
str e = "test";
|
||||
|
||||
retNum();
|
||||
bool bln = true;
|
||||
|
||||
print(takesArgs("test", 3, true));
|
||||
print(retStr());
|
||||
|
||||
doStuff("Ay0o", "world", true);
|
||||
""");
|
||||
}
|
||||
|
||||
private void testValid(String validSource) {
|
||||
try {
|
||||
Block script = Parser.parse(new Lexer(validSource).analyze());
|
||||
SemanticAnalyzer.analyze(script, new ErrorHandler());
|
||||
TerraScript ts = new TerraScriptClassGenerator("./build/codegentest").generate(script);
|
||||
TypedStmt.Block typedScript = SemanticAnalyzer.analyze(script, new ErrorHandler());
|
||||
TerraScript ts = new TerraScriptClassGenerator("./build/codegentest").generate(typedScript);
|
||||
ts.execute();
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
Reference in New Issue
Block a user