Skip to content

Commit 9b49c96

Browse files
committed
feat: parser fixes, jvm code refactoring
1 parent e6083f2 commit 9b49c96

File tree

101 files changed

+1537
-1371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1537
-1371
lines changed

backend/common/src/main/java/com/github/kayjamlang/backend/tree/KayJamExpressionVisitor.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.kayjamlang.backend.tree;
22

33
import com.github.kayjamlang.core.KayJamFile;
4-
import com.github.kayjamlang.core.containers.FunctionContainer;
4+
import com.github.kayjamlang.core.statements.FunctionStatement;
55
import com.github.kayjamlang.core.expressions.*;
66
import com.github.kayjamlang.core.expressions.loops.*;
77

@@ -45,15 +45,12 @@ public T visit(Expression expression) {
4545
return visitForExpression((ForExpression) expression);
4646
}else if(expression instanceof WhileExpression) {
4747
return visitWhileExpression((WhileExpression) expression);
48-
}else if(expression instanceof FunctionContainer) {
49-
return visitFunctionContainer((FunctionContainer) expression);
5048
}
5149

5250

5351
throw new IllegalStateException("Not implemented yet: "+expression.getClass().getSimpleName());
5452
}
5553

56-
public abstract T visitKayJamFile(KayJamFile file);
5754
public abstract T visitAccessExpression(AccessExpression expression);
5855
public abstract T visitArrayExpression(ArrayExpression expression);
5956
public abstract T visitAssertNullExpression(AssertNullExpression expression);
@@ -73,6 +70,4 @@ public T visit(Expression expression) {
7370
public abstract T visitVariableLinkExpression(VariableLinkExpression expression);
7471
public abstract T visitForExpression(ForExpression expression);
7572
public abstract T visitWhileExpression(WhileExpression expression);
76-
77-
public abstract T visitFunctionContainer(FunctionContainer expression);
7873
}

backend/common/src/main/java/com/github/kayjamlang/backend/tree/KayJamFileTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.github.kayjamlang.backend.utils.FileUtils;
44
import com.github.kayjamlang.core.KayJamFile;
55
import com.github.kayjamlang.core.KayJamLexer;
6-
import com.github.kayjamlang.core.KayJamParser;
6+
import com.github.kayjamlang.core.parser.KayJamParser;
77
import com.github.kayjamlang.core.exceptions.KayJamLexerException;
88
import com.github.kayjamlang.core.exceptions.KayJamParserException;
99

backend/jvm/src/main/java/com/github/kayjamlang/backend/jvm/JVMBackendCompiler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.github.kayjamlang.backend.IBackendOptions;
44
import com.github.kayjamlang.backend.IBackendCompiler;
55
import com.github.kayjamlang.backend.IOptions;
6+
import com.github.kayjamlang.backend.jvm.generators.JVMCodeGenerator;
67
import com.github.kayjamlang.backend.tree.KayJamFileTree;
78
import com.github.kayjamlang.core.KayJamFile;
89
import com.github.kayjamlang.core.exceptions.KayJamLexerException;
@@ -25,23 +26,22 @@ public IBackendOptions createOptionsClass() {
2526

2627
@Override
2728
public void compile(IOptions options) throws KayJamLexerException, KayJamParserException, IOException {
29+
JVMCodeGenerator codeGenerator = new JVMCodeGenerator();
2830
List<KayJamFile> files = KayJamFileTree.loadFilesFromPath(options.getInputDir().toPath());
2931
for (KayJamFile file : files) {
30-
JVMKayJamExpressionVisitor visitor = new JVMKayJamExpressionVisitor();
31-
visitor.visitKayJamFile(file);
32-
for (Map.Entry<String, ClassWriter> entry : visitor.getClasses().entrySet()) {
32+
for (Map.Entry<String, byte[]> entry : codeGenerator.generate(file).entrySet()) {
3333
File outputFile = getFile(options, entry);
3434

3535
if (outputFile.createNewFile()) {
3636
FileOutputStream fos = new FileOutputStream(outputFile);
37-
fos.write(entry.getValue().toByteArray());
37+
fos.write(entry.getValue());
3838
fos.close();
3939
}
4040
}
4141
}
4242
}
4343

44-
private static File getFile(IOptions options, Map.Entry<String, ClassWriter> entry) throws IOException {
44+
private static File getFile(IOptions options, Map.Entry<String, byte[]> entry) throws IOException {
4545
File outputFile = new File(options.getOutputDir(), "./" + entry.getKey() + ".class");
4646
if (outputFile.exists()) {
4747
if (!outputFile.delete()) {

0 commit comments

Comments
 (0)