diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-20 23:45:15 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-20 23:47:36 +0100 |
| commit | 40b380d258548a83a4adca9352e97eaae41a4342 (patch) | |
| tree | 41687bbba4307d1dfe906dbd585eda43cff31400 /src/main/java | |
| parent | 0ad8010046cd7ba59d145731427897867387b575 (diff) | |
Mark namespace as inited in init function
Diffstat (limited to 'src/main/java')
3 files changed, 34 insertions, 4 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java index d719cf22..e487014e 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java @@ -7,6 +7,7 @@ public enum PatioCodeGenLocalSpace { CLOSURE("closure"), CLOSURE_POINTER("closurePointer"), CLOSURE_FUNCTION_POINTER("closureFunctionPointer"), + NAMESPACE_IS_INITED_POINTER("namespaceIsInitedPointer"), LOCAL("local"), RECEIVER("receiver"), TEMPORARY("tmp"); diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java index 4d41f344..57ec3ded 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java @@ -1,5 +1,8 @@ package org.shedlang.compiler.patio; +import org.shedlang.compiler.patio.ast.instructions.PatioDataPtrGet; +import org.shedlang.compiler.patio.ast.instructions.PatioMemoryStore; +import org.shedlang.compiler.patio.ast.operands.PatioBool; import org.shedlang.compiler.patio.ast.types.PatioDataLayout; import org.shedlang.compiler.patio.ast.types.PatioTypes; import org.shedlang.compiler.sources.Sources; @@ -7,6 +10,7 @@ import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.NamespaceTypeInfo; import org.shedlang.compiler.util.Lists; +import java.util.List; import java.util.function.Function; public class PatioCodeGenNamespaces { @@ -17,7 +21,7 @@ public class PatioCodeGenNamespaces { Function<PatioCodeGenContext, PatioCodeGenContext> generateInitBody, PatioCodeGenContext context ) { - // TODO: proper source + // TODO: proper source. Probably wrap up stack namespace in a data structure with a source? var source = Sources.NULL; var namespaceTypeInfo = context.namespaceTypeInfo(namespaceName); @@ -40,8 +44,32 @@ public class PatioCodeGenNamespaces { false, PatioTypes.VOID, source, - initContext -> - generateInitBody.apply(initContext) + initContext -> { + initContext = generateInitBody.apply(initContext); + + var isInitedPointerResult = initContext.allocateLocal( + PatioCodeGenLocalSpace.NAMESPACE_IS_INITED_POINTER, + PatioTypes.DATA_POINTER + ); + var isInitedPointer = isInitedPointerResult.value(); + initContext = isInitedPointerResult.context(); + + initContext = initContext.addInstruction(new PatioDataPtrGet( + isInitedPointer, + globalNameNamespaceIsInited(namespaceName), + source + )); + + initContext = initContext.addInstruction(new PatioMemoryStore( + isInitedPointer, + PatioTypes.scalar(PatioTypes.BOOL), + List.of(), + new PatioBool(true), + source + )); + + return initContext; + } ); return context; diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java index 9abc16da..56877109 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java @@ -1,6 +1,7 @@ package org.shedlang.compiler.patio.ast.instructions; import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; +import org.shedlang.compiler.patio.ast.operands.PatioOperand; import org.shedlang.compiler.patio.ast.types.PatioDataLayout; import org.shedlang.compiler.sources.Source; @@ -13,7 +14,7 @@ public record PatioMemoryStore( PatioLocalRef pointer, PatioDataLayout layout, List<Integer> offset, - PatioLocalRef value, + PatioOperand value, Source source ) implements PatioInstruction { } |
