summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-04-26 17:11:09 +0100
committerMichael Williamson <mike@zwobble.org>2026-04-26 17:11:09 +0100
commit971321393c5965dd14eb604e22e907d6b94b0c8a (patch)
tree31aa42b932474944d7117c81586679b87ea839ca /src
parent72c84ea17a7e4b27cf9428ef23f713e32f5339d3 (diff)
Add stubbed Java generator
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/HobgoblinCompiler.java12
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/generators/Generator.java9
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/generators/java/JavaGenerator.java22
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java3
4 files changed, 44 insertions, 2 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/HobgoblinCompiler.java b/src/main/java/org/zwobble/hobgoblin/compiler/HobgoblinCompiler.java
index d9f7d21..5d59d96 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/HobgoblinCompiler.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/HobgoblinCompiler.java
@@ -1,5 +1,7 @@
package org.zwobble.hobgoblin.compiler;
+import org.zwobble.hobgoblin.compiler.ast.typed.TypedNamespaceNode;
+import org.zwobble.hobgoblin.compiler.generators.Generator;
import org.zwobble.hobgoblin.compiler.parser.Parser;
import org.zwobble.hobgoblin.compiler.typechecker.TypeChecker;
import org.zwobble.hobgoblin.compiler.typechecker.TypeCheckerGlobalContext;
@@ -12,6 +14,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.List;
public class HobgoblinCompiler {
public static final String FILE_NAME_EXTENSION = ".hob";
@@ -19,10 +22,12 @@ public class HobgoblinCompiler {
private HobgoblinCompiler() {
}
- public static void compile(Path projectRoot) throws IOException {
+ public static void compile(Path projectRoot, List<Generator> generators) throws IOException {
var sourceDirectory = projectRoot.resolve("src");
var sourceFiles = sourceDirectory.toFile()
.listFiles(file -> file.toPath().toString().endsWith(FILE_NAME_EXTENSION));
+
+ var typedNamespaceNodes = new ArrayList<TypedNamespaceNode>();
for (var sourceFile : sourceFiles) {
var namespaceName = sourceFileNamespaceName(sourceDirectory, sourceFile.toPath());
var sourceContents = Files.readString(sourceFile.toPath(), StandardCharsets.UTF_8);
@@ -33,6 +38,11 @@ public class HobgoblinCompiler {
typeCheckerContext.addBuiltinScalarType(new ScalarType("Int32"));
var typedNamespaceNode = TypeChecker.typeCheckNamespace(untypedNamespaceNode, typeCheckerContext);
+ typedNamespaceNodes.add(typedNamespaceNode);
+ }
+
+ for (var generator : generators) {
+ generator.generate(typedNamespaceNodes);
}
}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/generators/Generator.java b/src/main/java/org/zwobble/hobgoblin/compiler/generators/Generator.java
new file mode 100644
index 0000000..2457609
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/generators/Generator.java
@@ -0,0 +1,9 @@
+package org.zwobble.hobgoblin.compiler.generators;
+
+import org.zwobble.hobgoblin.compiler.ast.typed.TypedNamespaceNode;
+
+import java.util.List;
+
+public interface Generator {
+ void generate(List<TypedNamespaceNode> namespaces);
+}
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/generators/java/JavaGenerator.java b/src/main/java/org/zwobble/hobgoblin/compiler/generators/java/JavaGenerator.java
new file mode 100644
index 0000000..ced3d81
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/generators/java/JavaGenerator.java
@@ -0,0 +1,22 @@
+package org.zwobble.hobgoblin.compiler.generators.java;
+
+import org.zwobble.hobgoblin.compiler.ast.typed.TypedNamespaceNode;
+import org.zwobble.hobgoblin.compiler.generators.Generator;
+
+import java.nio.file.Path;
+import java.util.List;
+
+public class JavaGenerator implements Generator {
+ private final Path root;
+ private final String packageName;
+
+ public JavaGenerator(Path root, String packageName) {
+ this.root = root;
+ this.packageName = packageName;
+ }
+
+ @Override
+ public void generate(List<TypedNamespaceNode> namespaces) {
+
+ }
+}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
index 354cb08..e892cd9 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
@@ -4,6 +4,7 @@ import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import java.io.IOException;
+import java.util.List;
import java.util.stream.Stream;
public class ExampleTests {
@@ -17,6 +18,6 @@ public class ExampleTests {
}
private void runTest(ExampleSet exampleSet) throws IOException {
- HobgoblinCompiler.compile(exampleSet.path());
+ HobgoblinCompiler.compile(exampleSet.path(), List.of());
}
}