From 317f6fa18dfb5dd0020a086d2815c538fcb558ff Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 21 Oct 2023 13:44:25 +0100 Subject: Generate stack IR for imports --- .../org/shedlang/compiler/stackir/StackCompiler.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/shedlang/compiler/stackir') diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java index 5746fa34..7a9fc502 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java @@ -246,7 +246,7 @@ public class StackCompiler { context = context.addInstruction(new ReturnInstruction(node.source())); return context; } - + public static Context compileFunctionStatement( TypedFunctionStatementNode node, Context context @@ -257,7 +257,7 @@ public class StackCompiler { case TypedBlockReturnNode blockReturn -> compileBlockReturn(blockReturn, context); - + case TypedExpressionStatementNode expressionStatement -> compileExpressionStatement(expressionStatement, context); @@ -342,6 +342,20 @@ public class StackCompiler { context = context.addShedVariable(boundVariableName); } + for (var importNode : node.imports()) { + var localName = context.shedVariableToLocal(importNode.variableName()); + context = context + .addInstruction(new NamespaceImportInstruction( + importNode.namespaceName(), + importNode.source() + )) + .addInstruction(new LocalStoreInstruction( + localName, + importNode.source() + )); + + } + var statementsAfterHoisting = Iterables.sortedBy(node.body(), statement -> switch (statement) { case TypedAssignNode assign -> 1; -- cgit v1.2.3