diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-28 15:44:28 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-28 15:44:28 +0100 |
| commit | ecb878e11effdfd91ed1c29f18913e7074a527e4 (patch) | |
| tree | fd368fdfa4940544492de9351fcd6d623f338fa1 /src/main/java | |
| parent | 12bc0b647eb6276a93c134e35c5babc4efc01d93 (diff) | |
Hoist structs
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/stackir/StackCompiler.java | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java index dc171e00..cca640b4 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java @@ -5,6 +5,7 @@ import org.shedlang.compiler.ShedBuiltins; import org.shedlang.compiler.ast.typed.*; import org.shedlang.compiler.stackir.instructions.*; import org.shedlang.compiler.types.StructType; +import org.shedlang.compiler.util.Iterables; import org.shedlang.compiler.util.P; import java.util.List; @@ -337,7 +338,17 @@ public class StackCompiler { context = context.addShedVariable(boundVariableName); } - for (var statement : node.body()) { + var statementsAfterHoisting = Iterables.sortedBy(node.body(), statement -> switch (statement) { + case TypedAssignNode assign -> + 1; + + case TypedFunctionDefinitionNode functionDefinition -> + 1; + + case TypedStructDefinitionNode structDefinition -> + 0; + }); + for (var statement : statementsAfterHoisting) { context = compileNamespaceStatement(statement, context); } |
