diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-20 11:47:35 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-20 11:47:35 +0100 |
| commit | 07a2003ac64b0ac7f4a98eefb8f45f1da2133e3f (patch) | |
| tree | a512157ae5a75a6ba142715660eb2d0907d9cbdb /src/main/java | |
| parent | 55ecd2ff710377c48cbc620be02db32cfcdc29c6 (diff) | |
Add separate function pointer type
Diffstat (limited to 'src/main/java')
5 files changed, 13 insertions, 4 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java index 451c4d5e..1daa9a42 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java @@ -53,8 +53,7 @@ class PatioCodeGenClosures { ) { var functionPointerResult = context.allocateLocal( PatioCodeGenLocalSpace.CALL_FUNCTION_POINTER, - // TODO: should be function pointer - PatioTypes.INT + PatioTypes.FUNCTION_POINTER ); var functionPointer = functionPointerResult.value(); context = functionPointerResult.context(); 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 f5a90775..e170cfb7 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.PatioFunctionPointerType; import org.shedlang.compiler.patio.ast.types.PatioIntType; import org.shedlang.compiler.patio.ast.types.PatioType; import org.shedlang.compiler.treetext.Tree; @@ -36,7 +37,7 @@ public class PatioSerializer { serializeTree(tree, builder, 0); } - public static void serializeType(PatioIntType type, StringBuilder builder) { + public static void serializeType(PatioType type, StringBuilder builder) { var tree = typeToTree(type); serializeTree(tree, builder, 0); } @@ -132,6 +133,9 @@ public class PatioSerializer { private static Tree typeToTree(PatioType type) { return switch (type) { + case PatioFunctionPointerType functionPointerType -> + treeIdentifier("function-ptr"); + case PatioIntType intType -> treeIdentifier("int"); }; diff --git a/src/main/java/org/shedlang/compiler/patio/ast/types/PatioFunctionPointerType.java b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioFunctionPointerType.java new file mode 100644 index 00000000..86f0ac51 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/ast/types/PatioFunctionPointerType.java @@ -0,0 +1,5 @@ +package org.shedlang.compiler.patio.ast.types; + +public record PatioFunctionPointerType() implements PatioType { + public static final PatioFunctionPointerType INSTANCE = new PatioFunctionPointerType(); +} 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 54c892b4..71c6ed78 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 PatioIntType { +public sealed interface PatioType permits 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 6830e0fa..d0d65eba 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,5 +4,6 @@ public class PatioTypes { private PatioTypes() { } + public static final PatioFunctionPointerType FUNCTION_POINTER = PatioFunctionPointerType.INSTANCE; public static final PatioIntType INT = PatioIntType.INSTANCE; } |
