aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-16 14:24:28 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-16 14:24:28 +0000
commit9458a3b5676bc78eac5807a878b9d8536035d6e2 (patch)
treef8b7f17f7253f92ebf3e5ee18df17e51f36b8a34 /src/main/java
parent355a31d207a28d66a03351498fefe33b4c358c95 (diff)
Make closures GC objects
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
index 333f3d68..c5a0096d 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
@@ -1,6 +1,5 @@
package org.shedlang.compiler.patio;
-import org.pcollections.PVector;
import org.shedlang.compiler.ast.typed.FreeVariable;
import org.shedlang.compiler.ast.typed.FreeVariables;
import org.shedlang.compiler.patio.ast.PatioVisibility;
@@ -8,7 +7,10 @@ import org.shedlang.compiler.patio.ast.instructions.*;
import org.shedlang.compiler.patio.ast.operands.PatioFunctionPtr;
import org.shedlang.compiler.patio.ast.operands.PatioLocalRef;
import org.shedlang.compiler.patio.ast.operands.PatioOperand;
-import org.shedlang.compiler.patio.ast.types.*;
+import org.shedlang.compiler.patio.ast.types.PatioDataLayout;
+import org.shedlang.compiler.patio.ast.types.PatioDataLayouts;
+import org.shedlang.compiler.patio.ast.types.PatioType;
+import org.shedlang.compiler.patio.ast.types.PatioTypes;
import org.shedlang.compiler.shid.instructions.ShidDefineFunction;
import org.shedlang.compiler.sources.Source;
import org.shedlang.compiler.util.P;
@@ -27,18 +29,10 @@ class PatioCodeGenClosures {
private PatioCodeGenClosures() {}
- static final List<Integer> FUNCTION_POINTER_OFFSET = List.of(0);
-
- static List<Integer> additionalOffset(List<Integer> offset) {
- return P.vector(1).plusAll(offset);
- }
-
- static final PVector<Integer> FREE_VARIABLES_OFFSET = P.vector(2);
-
private static PatioDataLayout closureDataLayoutForCall() {
- return new PatioDataLayoutStruct(List.of(
+ return PatioCodeGenGc.gcObjectDataLayout(PatioDataLayouts.struct(List.of(
PatioDataLayouts.FUNCTION_POINTER
- ));
+ )));
}
static PatioDataLayout closureDataLayout(
@@ -46,7 +40,7 @@ class PatioCodeGenClosures {
FreeVariables freeVariables,
PatioCodeGenContext context
) {
- return PatioDataLayouts.struct(List.of(
+ return PatioCodeGenGc.gcObjectDataLayout(PatioDataLayouts.struct(List.of(
PatioDataLayouts.FUNCTION_POINTER,
additional,
PatioDataLayouts.struct(
@@ -56,13 +50,20 @@ class PatioCodeGenClosures {
))
.toList()
)
- ));
+ )));
+ }
+
+ static final List<Integer> FUNCTION_POINTER_OFFSET
+ = PatioCodeGenGc.gcObjectOffset(List.of(0));
+
+ static List<Integer> additionalOffset(List<Integer> offset) {
+ return PatioCodeGenGc.gcObjectOffset(P.vector(1).plusAll(offset));
}
private static List<Integer> freeVariableOffset(
FreeVariable freeVariable
) {
- return FREE_VARIABLES_OFFSET.plus(freeVariable.index());
+ return PatioCodeGenGc.gcObjectOffset(List.of(2, freeVariable.index()));
}
static PatioCodeGenContext defineParams(