diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-20 11:51:55 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-20 13:43:18 +0100 |
| commit | 2c9f1042aaf2b1c6c666af2ecd853d076484cd4b (patch) | |
| tree | b0711c20ad51363723f94350f78c26cadd6fab86 /src/main/java | |
| parent | 07a2003ac64b0ac7f4a98eefb8f45f1da2133e3f (diff) | |
Add data pointer type
Diffstat (limited to 'src/main/java')
6 files changed, 15 insertions, 3 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java index d31e92e5..58280925 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java @@ -72,8 +72,7 @@ public class PatioCodeGen { var receiverResult = context.allocateLocal( PatioCodeGenLocalSpace.RECEIVER, - // TODO: should be pointer type - PatioCodeGenTypes.VALUE_TYPE + PatioCodeGenClosures.CLOSURE_TYPE ); var receiver = receiverResult.value(); context = receiverResult.context(); diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java index 1daa9a42..048d235d 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java @@ -4,6 +4,7 @@ import org.shedlang.compiler.ast.typed.FreeVariables; import org.shedlang.compiler.patio.ast.instructions.PatioCallPointer; import org.shedlang.compiler.patio.ast.PatioLocalRef; import org.shedlang.compiler.patio.ast.instructions.PatioMemoryLoad; +import org.shedlang.compiler.patio.ast.types.PatioType; import org.shedlang.compiler.patio.ast.types.PatioTypes; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; @@ -16,6 +17,8 @@ import java.util.function.Function; import static org.shedlang.compiler.util.Iterables.sortedBy; class PatioCodeGenClosures { + public static final PatioType CLOSURE_TYPE = PatioTypes.DATA_POINTER; + private PatioCodeGenClosures() {} private static final int FUNCTION_POINTER_OFFSET = 0; diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java index e170cfb7..27dc2045 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java @@ -1,6 +1,7 @@ package org.shedlang.compiler.patio.ast; import org.shedlang.compiler.patio.ast.instructions.*; +import org.shedlang.compiler.patio.ast.types.PatioDataPointerType; import org.shedlang.compiler.patio.ast.types.PatioFunctionPointerType; import org.shedlang.compiler.patio.ast.types.PatioIntType; import org.shedlang.compiler.patio.ast.types.PatioType; @@ -133,6 +134,9 @@ public class PatioSerializer { private static Tree typeToTree(PatioType type) { return switch (type) { + case PatioDataPointerType dataPointerType -> + treeIdentifier("data-ptr"); + case PatioFunctionPointerType functionPointerType -> treeIdentifier("function-ptr"); diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataPointerType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataPointerType.java new file mode 100644 index 00000000..d16d0f3a --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioDataPointerType.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.ast.types; + +public record PatioDataPointerType() implements PatioType { + public static final PatioDataPointerType INSTANCE = new PatioDataPointerType(); +} diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java index 71c6ed78..37b7ec4c 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioType.java @@ -1,4 +1,4 @@ package org.shedlang.compiler.patio.ast.types; -public sealed interface PatioType permits PatioFunctionPointerType, PatioIntType { +public sealed interface PatioType permits PatioDataPointerType, PatioFunctionPointerType, PatioIntType { } diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java index d0d65eba..804bf894 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioTypes.java @@ -4,6 +4,7 @@ public class PatioTypes { private PatioTypes() { } + public static final PatioDataPointerType DATA_POINTER = PatioDataPointerType.INSTANCE; public static final PatioFunctionPointerType FUNCTION_POINTER = PatioFunctionPointerType.INSTANCE; public static final PatioIntType INT = PatioIntType.INSTANCE; } |
