diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-03-24 14:52:59 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-03-24 14:52:59 +0000 |
| commit | 85f9578fb680ab4ee959469133714acd908a7c10 (patch) | |
| tree | 49e87c6e15d590d0dba9aa2e9832fef9d88e6540 /src/main/java/org/shedlang/compiler/runtime | |
| parent | c5b7107068537447a93982ead0217ac17070231c (diff) | |
Support custom runtimes when compiling
Diffstat (limited to 'src/main/java/org/shedlang/compiler/runtime')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/runtime/ShedRuntime.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/runtime/ShedRuntime.java b/src/main/java/org/shedlang/compiler/runtime/ShedRuntime.java new file mode 100644 index 00000000..25a81345 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/runtime/ShedRuntime.java @@ -0,0 +1,73 @@ +package org.shedlang.compiler.runtime; + +import org.shedlang.compiler.backends.paths.TargetDir; +import org.shedlang.compiler.config.GcConfig; +import org.shedlang.compiler.config.GcMarkAndSweepConfig; +import org.shedlang.compiler.filesystem.ShedCompilerFiles; +import org.shedlang.compiler.util.processes.ProcessError; + +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.shedlang.compiler.util.processes.ProcessRunner.runInheritIo; + +public class ShedRuntime { + private static final Map<GcConfig, String> STANDARD_RUNTIMES = Map.ofEntries( + Map.entry(GcConfig.BUMP, "bump"), + Map.entry(GcMarkAndSweepConfig.DEFAULT, "mark-and-sweep") + ); + + public static ShedRuntime defaultRuntime(String targetName) { + return new ShedRuntime( + ShedCompilerFiles.standardRuntimeTargetDir( + targetName, + "mark-and-sweep" + ) + ); + } + + public static ShedRuntime runtime( + String targetName, + Optional<GcConfig> gcConfig, + TargetDir targetDir + ) throws ProcessError, InterruptedException { + var gc = gcConfig.orElse(GcConfig.DEFAULT); + var standardRuntimeName = STANDARD_RUNTIMES.get(gc); + + if (standardRuntimeName != null) { + return new ShedRuntime( + ShedCompilerFiles.standardRuntimeTargetDir( + targetName, + standardRuntimeName + ) + ); + } + + // TODO: deal with stale compiled runtimes (in build.py?) + // TODO: handle GC config + var runtimeDir = targetDir.topLevel("runtime"); + var buildRuntimeCommand = List.of( + "python3", + ShedCompilerFiles.getRoot().resolve("runtime/build.py").toString(), + "custom", + "--target", targetName, + "--gc", gc.name(), + "--output-dir", runtimeDir.toString() + ); + runInheritIo(buildRuntimeCommand); + + return new ShedRuntime(runtimeDir); + } + + private final Path dir; + + private ShedRuntime(Path dir) { + this.dir = dir; + } + + public Path dir() { + return this.dir; + } +} |
