aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/shedlang/compiler/stackir
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-06-30 19:51:50 +0100
committerMichael Williamson <mike@zwobble.org>2023-06-30 19:51:50 +0100
commit334782898b59817a00a3ee9b8031cd974178d1ec (patch)
treed5b731976eeab3c52f47cb47e857e31a8f2639f7 /src/main/java/org/shedlang/compiler/stackir
parent71c588ca231d275c5263b3e9ca5f7f57c4e048a1 (diff)
Define builtin modules outside of code gen
Diffstat (limited to 'src/main/java/org/shedlang/compiler/stackir')
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/StackCompiler.java14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
index b8356ab4..e4c4f3e1 100644
--- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
+++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
@@ -3,6 +3,7 @@ package org.shedlang.compiler.stackir;
import org.pcollections.PVector;
import org.shedlang.compiler.ast.typed.*;
import org.shedlang.compiler.stackir.instructions.*;
+import org.shedlang.compiler.types.NamespaceName;
import org.shedlang.compiler.util.P;
import java.util.stream.Collectors;
@@ -104,9 +105,16 @@ public class StackCompiler {
}
public static PVector<Instruction> compileNamespace(TypedNamespaceNode node) {
- var instructions = node.body().stream()
- .map(statement -> compileNamespaceStatement(statement))
- .reduce(P.vector(), PVector::plusAll);
+ var instructions = P.<Instruction>vector();
+
+ instructions = instructions
+ .plus(new NamespaceImportInstruction(NamespaceName.of("Shed", "Builtins"), node.source()))
+ .plus(new FieldLoadInstruction(NamespaceName.of("Shed", "Builtins"), "print", node.source()))
+ .plus(new LocalStoreInstruction("print", node.source()));
+
+ for (var statement : node.body()) {
+ instructions = instructions.plusAll(compileNamespaceStatement(statement));
+ }
for (var fieldName : node.fieldNames()) {
instructions = instructions