aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-20 14:17:58 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-20 14:17:58 +0100
commitb48edd39f96c9f3f0917fb4000d10f0a78920b7d (patch)
tree45384091b0775f47086b3db19aab56845ea6885c /src/main/java
parent36540510fff921b46642c6a01b0e566d540b4076 (diff)
Store function pointer in closure
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java25
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java1
2 files changed, 23 insertions, 3 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
index b3cace14..e8d991d2 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
@@ -1,10 +1,8 @@
package org.shedlang.compiler.patio;
import org.shedlang.compiler.ast.typed.FreeVariables;
-import org.shedlang.compiler.patio.ast.instructions.PatioAlloc;
-import org.shedlang.compiler.patio.ast.instructions.PatioCallPointer;
+import org.shedlang.compiler.patio.ast.instructions.*;
import org.shedlang.compiler.patio.ast.PatioLocalRef;
-import org.shedlang.compiler.patio.ast.instructions.PatioMemoryLoad;
import org.shedlang.compiler.patio.ast.types.PatioDataLayout;
import org.shedlang.compiler.patio.ast.types.PatioStruct;
import org.shedlang.compiler.patio.ast.types.PatioType;
@@ -71,6 +69,27 @@ class PatioCodeGenClosures {
context = context.addInstruction(new PatioAlloc(closure, layout, source));
+ var functionPointerResult = context.allocateLocal(
+ PatioCodeGenLocalSpace.CLOSURE_FUNCTION_POINTER,
+ PatioTypes.FUNCTION_POINTER
+ );
+ var functionPointer = functionPointerResult.value();
+ context = functionPointerResult.context();
+
+ context = context.addInstruction(new PatioFunctionPointerGet(
+ functionPointer,
+ fullName,
+ source
+ ));
+
+ context = context.addInstruction(new PatioMemoryStore(
+ closure,
+ layout,
+ FUNCTION_POINTER_OFFSET,
+ functionPointer,
+ source
+ ));
+
return context;
}
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java
index 89fd69c6..d3827cb7 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java
@@ -5,6 +5,7 @@ public enum PatioCodeGenLocalSpace {
CALL_ARG_NAMED("callArgNamed"),
CALL_FUNCTION_POINTER("callFunctionPointer"),
CLOSURE("closure"),
+ CLOSURE_FUNCTION_POINTER("closureFunctionPointer"),
LOCAL("local"),
RECEIVER("receiver"),
TEMPORARY("tmp");