From 40b380d258548a83a4adca9352e97eaae41a4342 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 20 Jul 2023 23:45:15 +0100 Subject: Mark namespace as inited in init function --- .../compiler/patio/PatioCodeGenLocalSpace.java | 1 + .../compiler/patio/PatioCodeGenNamespaces.java | 34 ++++++++++++++++++++-- .../patio/ast/instructions/PatioMemoryStore.java | 3 +- 3 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src/main/java') 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 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 offset, - PatioLocalRef value, + PatioOperand value, Source source ) implements PatioInstruction { } -- cgit v1.2.3