aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-06-14 18:29:10 +0100
committerMichael Williamson <mike@zwobble.org>2023-06-14 18:29:10 +0100
commit78c3d52bc16fefbe35dbceb778f52618078b0854 (patch)
tree3857e0897d02cea9e60dc1b4eb8cd721358bd3d0 /src
parentd267088721d40065b1e71521127073b471e84db5 (diff)
Use field names on namespace node in StackCompiler
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/StackCompiler.java20
-rw-r--r--src/test/java/org/shedlang/compiler/ast/typed/Typed.java10
-rw-r--r--src/test/java/org/shedlang/compiler/stackir/StackCompilerNamespaceTests.java3
3 files changed, 19 insertions, 14 deletions
diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
index 8e66db30..6b8452c1 100644
--- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
+++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
@@ -107,18 +107,14 @@ public class StackCompiler {
.map(statement -> compileNamespaceStatement(statement))
.reduce(P.vector(), PVector::plusAll);
- // TODO: handle exports explicitly
- for (var statement : node.body()) {
- switch (statement) {
- case TypedFunctionDefinitionNode functionDefinition ->
- instructions = instructions
- .plus(new LocalLoadInstruction(functionDefinition.name(), functionDefinition.source()))
- .plus(new NamespaceFieldStoreInstruction(
- node.namespaceName(),
- functionDefinition.name(),
- functionDefinition.source()
- ));
- }
+ for (var fieldName : node.fieldNames()) {
+ instructions = instructions
+ .plus(new LocalLoadInstruction(fieldName, node.source()))
+ .plus(new NamespaceFieldStoreInstruction(
+ node.namespaceName(),
+ fieldName,
+ node.source()
+ ));
}
return instructions;
diff --git a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java
index ae709dd4..ff87c8e8 100644
--- a/src/test/java/org/shedlang/compiler/ast/typed/Typed.java
+++ b/src/test/java/org/shedlang/compiler/ast/typed/Typed.java
@@ -51,7 +51,15 @@ public class Typed {
NamespaceName namespaceName,
List<TypedNamespaceStatementNode> body
) {
- return new TypedNamespaceNode(namespaceName, body, List.of(), Sources.NULL);
+ return namespace(namespaceName, body, List.of());
+ }
+
+ public static TypedNamespaceNode namespace(
+ NamespaceName namespaceName,
+ List<TypedNamespaceStatementNode> body,
+ List<String> fieldNames
+ ) {
+ return new TypedNamespaceNode(namespaceName, body, fieldNames, Sources.NULL);
}
public static TypedStringLiteralNode stringLiteral(String value) {
diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerNamespaceTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerNamespaceTests.java
index 32ff72ba..1ed17236 100644
--- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerNamespaceTests.java
+++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerNamespaceTests.java
@@ -27,7 +27,8 @@ public class StackCompilerNamespaceTests {
.addNamedParam("y", Typed.typeLevelReference("Int", Types.INT))
.addStatement(Typed.expressionStatement(Typed.stringLiteral("hello")))
.build()
- )
+ ),
+ List.of("f")
);
var instructions = StackCompiler.compileNamespace(node);