aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-10-20 17:39:03 +0100
committerMichael Williamson <mike@zwobble.org>2023-10-20 17:39:03 +0100
commit005b955b8ff214c55501f7f8d3a0db09f0fb8f11 (patch)
tree041af9d82ae016c576009e78251ec19363054add
parent06a52c7230e5d95ed6ea3093a0312e6eaed43fe4 (diff)
Store main module on each bin
-rw-r--r--examples/01-true/shed.toml4
-rw-r--r--examples/02-hello-world/shed.toml4
-rw-r--r--examples/03-val/shed.toml4
-rw-r--r--examples/04-val-as-namespace-statement/shed.toml4
-rw-r--r--examples/05-string-add/shed.toml4
-rw-r--r--examples/06-if/shed.toml4
-rw-r--r--examples/07-mutual-recursion/shed.toml4
-rw-r--r--examples/08-blocks/shed.toml4
-rw-r--r--examples/09-var/shed.toml4
-rw-r--r--examples/10-while/shed.toml4
-rw-r--r--examples/11-tuples/shed.toml4
-rw-r--r--examples/12-named-args/shed.toml4
-rw-r--r--examples/13-target-ignore/shed.toml4
-rw-r--r--examples/14-structs/shed.toml4
-rw-r--r--examples/15-struct-hoisting/shed.toml4
-rw-r--r--examples/15-sums/shed.toml4
-rw-r--r--src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java2
-rw-r--r--src/main/java/org/shedlang/compiler/backends/PatioBackend.java2
-rw-r--r--src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java2
-rw-r--r--src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java2
-rw-r--r--src/main/java/org/shedlang/compiler/config/BinConfig.java12
-rw-r--r--src/main/java/org/shedlang/compiler/config/ProjectConfig.java9
22 files changed, 28 insertions, 65 deletions
diff --git a/examples/01-true/shed.toml b/examples/01-true/shed.toml
index e508461b..a5ab3d51 100644
--- a/examples/01-true/shed.toml
+++ b/examples/01-true/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "True"
-
[[shed.bins]]
name = "true"
+main-module = "True"
[[shed.examples]]
bin = "true"
diff --git a/examples/02-hello-world/shed.toml b/examples/02-hello-world/shed.toml
index 156fa7c6..9e3bb804 100644
--- a/examples/02-hello-world/shed.toml
+++ b/examples/02-hello-world/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/examples/03-val/shed.toml b/examples/03-val/shed.toml
index 156fa7c6..9e3bb804 100644
--- a/examples/03-val/shed.toml
+++ b/examples/03-val/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/examples/04-val-as-namespace-statement/shed.toml b/examples/04-val-as-namespace-statement/shed.toml
index 156fa7c6..9e3bb804 100644
--- a/examples/04-val-as-namespace-statement/shed.toml
+++ b/examples/04-val-as-namespace-statement/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/examples/05-string-add/shed.toml b/examples/05-string-add/shed.toml
index 156fa7c6..9e3bb804 100644
--- a/examples/05-string-add/shed.toml
+++ b/examples/05-string-add/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/examples/06-if/shed.toml b/examples/06-if/shed.toml
index bbbffff5..2b94bc57 100644
--- a/examples/06-if/shed.toml
+++ b/examples/06-if/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "Counting"
-
[[shed.bins]]
name = "counting"
+main-module = "Counting"
[[shed.examples]]
bin = "counting"
diff --git a/examples/07-mutual-recursion/shed.toml b/examples/07-mutual-recursion/shed.toml
index cb1607ce..3abd2bf8 100644
--- a/examples/07-mutual-recursion/shed.toml
+++ b/examples/07-mutual-recursion/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "MutualRecursion"
-
[[shed.bins]]
name = "mutual-recursion"
+main-module = "MutualRecursion"
[[shed.examples]]
bin = "mutual-recursion"
diff --git a/examples/08-blocks/shed.toml b/examples/08-blocks/shed.toml
index a2d8202b..d6081ebc 100644
--- a/examples/08-blocks/shed.toml
+++ b/examples/08-blocks/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "Counting"
-
[[shed.bins]]
name = "counting"
+main-module = "Counting"
[[shed.examples]]
bin = "counting"
diff --git a/examples/09-var/shed.toml b/examples/09-var/shed.toml
index 156fa7c6..9e3bb804 100644
--- a/examples/09-var/shed.toml
+++ b/examples/09-var/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/examples/10-while/shed.toml b/examples/10-while/shed.toml
index bbbffff5..2b94bc57 100644
--- a/examples/10-while/shed.toml
+++ b/examples/10-while/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "Counting"
-
[[shed.bins]]
name = "counting"
+main-module = "Counting"
[[shed.examples]]
bin = "counting"
diff --git a/examples/11-tuples/shed.toml b/examples/11-tuples/shed.toml
index 156fa7c6..9e3bb804 100644
--- a/examples/11-tuples/shed.toml
+++ b/examples/11-tuples/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/examples/12-named-args/shed.toml b/examples/12-named-args/shed.toml
index 156fa7c6..9e3bb804 100644
--- a/examples/12-named-args/shed.toml
+++ b/examples/12-named-args/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/examples/13-target-ignore/shed.toml b/examples/13-target-ignore/shed.toml
index 156fa7c6..9e3bb804 100644
--- a/examples/13-target-ignore/shed.toml
+++ b/examples/13-target-ignore/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/examples/14-structs/shed.toml b/examples/14-structs/shed.toml
index 156fa7c6..9e3bb804 100644
--- a/examples/14-structs/shed.toml
+++ b/examples/14-structs/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/examples/15-struct-hoisting/shed.toml b/examples/15-struct-hoisting/shed.toml
index 156fa7c6..9e3bb804 100644
--- a/examples/15-struct-hoisting/shed.toml
+++ b/examples/15-struct-hoisting/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/examples/15-sums/shed.toml b/examples/15-sums/shed.toml
index 3a2d316f..7432f9c1 100644
--- a/examples/15-sums/shed.toml
+++ b/examples/15-sums/shed.toml
@@ -1,8 +1,6 @@
-[shed]
-main = "HelloWorld"
-
[[shed.bins]]
name = "hello-world"
+main-module = "HelloWorld"
[[shed.examples]]
bin = "hello-world"
diff --git a/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java b/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java
index 5c27757c..dd33ae89 100644
--- a/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/GenerateInstructionsBackend.java
@@ -15,8 +15,6 @@ public class GenerateInstructionsBackend implements Backend {
TypeInfos typeInfos,
Path targetDir
) {
- System.out.println("main: " + config.main());
-
for (var namespace : namespaces) {
var namespaceName = namespace.namespaceName();
var instructions = namespace.instructions();
diff --git a/src/main/java/org/shedlang/compiler/backends/PatioBackend.java b/src/main/java/org/shedlang/compiler/backends/PatioBackend.java
index a647e842..e4edc9bf 100644
--- a/src/main/java/org/shedlang/compiler/backends/PatioBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/PatioBackend.java
@@ -17,8 +17,6 @@ public class PatioBackend implements Backend {
TypeInfos typeInfos,
Path targetDir
) {
- System.out.println("main: " + config.main());
-
var context = PatioCodeGenContext.forTypeInfos(typeInfos);
for (var namespace : namespaces) {
diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
index 77159c8c..80015357 100644
--- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmBackend.java
@@ -64,7 +64,7 @@ public class LlvmBackend implements Backend {
}
for (var bin : config.bins()) {
- var mainModule = this.generateMain(config.main(), typeInfos);
+ var mainModule = this.generateMain(bin.mainModule(), typeInfos);
var mainObjectPath = compileLlvmModule(mainModule, targetDir.resolve("bins"), bin.name());
var gccArgs = new ArrayList<String>();
diff --git a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
index 218a6f69..06e4bc25 100644
--- a/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
+++ b/src/main/java/org/shedlang/compiler/backends/wasm/WasmBackend.java
@@ -66,7 +66,7 @@ public class WasmBackend implements Backend {
ldArgs.add(objectFilePath.toString());
}
- var mainModule = this.generateMain(config.main(), typeInfos);
+ var mainModule = this.generateMain(bin.mainModule(), typeInfos);
var mainObjectPath = writeObjectFile(mainModule, targetDir.resolve("bins"), bin.name());
ldArgs.add(mainObjectPath.toString());
diff --git a/src/main/java/org/shedlang/compiler/config/BinConfig.java b/src/main/java/org/shedlang/compiler/config/BinConfig.java
index c3e70f2d..1d2a0677 100644
--- a/src/main/java/org/shedlang/compiler/config/BinConfig.java
+++ b/src/main/java/org/shedlang/compiler/config/BinConfig.java
@@ -1,11 +1,19 @@
package org.shedlang.compiler.config;
+import org.shedlang.compiler.types.NamespaceName;
import org.tomlj.TomlTable;
-public record BinConfig(String name) {
+import java.util.Arrays;
+
+public record BinConfig(String name, NamespaceName mainModule) {
public static BinConfig fromToml(TomlTable table) {
var name = table.getString("name");
- return new BinConfig(name);
+ var mainModuleString = table.getString("main-module");
+ // TODO: error checking
+ // TODO: extract namespace name parsing
+ var mainModule = new NamespaceName(Arrays.asList(mainModuleString.split("/")));
+
+ return new BinConfig(name, mainModule);
}
}
diff --git a/src/main/java/org/shedlang/compiler/config/ProjectConfig.java b/src/main/java/org/shedlang/compiler/config/ProjectConfig.java
index 1d6a9a9f..0e4d22e2 100644
--- a/src/main/java/org/shedlang/compiler/config/ProjectConfig.java
+++ b/src/main/java/org/shedlang/compiler/config/ProjectConfig.java
@@ -1,12 +1,10 @@
package org.shedlang.compiler.config;
-import org.shedlang.compiler.types.NamespaceName;
import org.tomlj.Toml;
import org.tomlj.TomlTable;
import java.io.IOException;
import java.nio.file.Path;
-import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
@@ -28,13 +26,6 @@ public class ProjectConfig {
this.config = config;
}
- public NamespaceName main() {
- var string = config.getString("shed.main");
- // TODO: error checking
- // TODO: extract namespace name parsing
- return new NamespaceName(Arrays.asList(string.split("/")));
- }
-
public Path targetDir() {
return root.resolve("target");
}