aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/shedlang/compiler/stackir
diff options
context:
space:
mode:
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