diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-06-11 20:03:13 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-06-11 20:03:13 +0100 |
| commit | 975e56cb795a42e576a3e44aee155ff3a81b601b (patch) | |
| tree | 7610e73325b76693294e17e5013032977e3dd8c9 /src/main/java/org/shedlang/compiler/ShedCompiler.java | |
| parent | 225ffd949c67664faceca9ab6d9b86b19a8a71dd (diff) | |
Add stubbed LLVM backend
Diffstat (limited to 'src/main/java/org/shedlang/compiler/ShedCompiler.java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/ShedCompiler.java | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/main/java/org/shedlang/compiler/ShedCompiler.java b/src/main/java/org/shedlang/compiler/ShedCompiler.java index 24455816..8cc102d8 100644 --- a/src/main/java/org/shedlang/compiler/ShedCompiler.java +++ b/src/main/java/org/shedlang/compiler/ShedCompiler.java @@ -1,14 +1,16 @@ package org.shedlang.compiler; +import org.shedlang.compiler.backends.Backend; import org.shedlang.compiler.config.ProjectConfig; import org.shedlang.compiler.parser.Parser; import org.shedlang.compiler.sources.Sources; -import org.shedlang.compiler.stackir.InstructionSerializer; import org.shedlang.compiler.stackir.StackCompiler; +import org.shedlang.compiler.stackir.instructions.Instruction; import org.shedlang.compiler.typechecker.TypeChecker; import org.shedlang.compiler.typechecker.TypeCheckerContext; import org.shedlang.compiler.types.Effects; import org.shedlang.compiler.types.FunctionType; +import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; import org.shedlang.compiler.util.P; @@ -19,25 +21,29 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.StreamSupport; import static org.shedlang.compiler.parser.Tokeniser.tokenise; public class ShedCompiler { - public void compile(Path projectRoot) throws IOException { + public void compile(Path projectRoot, Backend backend) throws IOException { var config = ProjectConfig.read(projectRoot); - System.out.println("main: " + config.main()); - var sourceRoot = projectRoot.resolve("src"); var sourceFilePaths = collectSourceFilePaths(sourceRoot); + var namespaces = new LinkedHashMap<NamespaceName, List<Instruction>>(); + for (var sourceFilePath : sourceFilePaths) { - System.out.println(sourceFilePath); + var namespaceNameParts = StreamSupport.stream(sourceRoot.relativize(sourceFilePath).spliterator(), false) + .map(element -> { + var string = element.toString(); + return string.substring(0, string.lastIndexOf('.')); + }) + .toList(); + var namespaceName = new NamespaceName(namespaceNameParts); var sourceContents = Files.readString(sourceFilePath, StandardCharsets.UTF_8); var source = Sources.file(sourceFilePath.toString(), sourceContents); @@ -60,14 +66,10 @@ public class ShedCompiler { var typedNode = TypeChecker.typeCheckNamespace(untypedNode, context); var instructions = StackCompiler.compileNamespace(typedNode); - - var builder = new StringBuilder(); - InstructionSerializer.serializeInstructions(instructions, builder); - var instructionsString = builder.toString(); - - System.out.println(instructionsString); - System.out.println(); + namespaces.put(namespaceName, instructions); } + + backend.compile(config, namespaces); } private List<Path> collectSourceFilePaths(Path sourceRoot) throws IOException { |
