aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-20 15:20:11 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-20 15:20:11 +0100
commit70882baa0eb2cecf83089ffcdf540976186c5e67 (patch)
tree5c066598cfb618b92d5dab646e9c21378452d185
parentb3276afec7498c7ec6e100d7367e748fdf0a3923 (diff)
Convert closure value to closure pointer before call
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenCallTests]/[method:canCallFunctionWithArgs(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected8
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenCallTests]/[method:canCallFunctionWithNoArgs(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected8
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java2
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java17
4 files changed, 26 insertions, 9 deletions
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenCallTests]/[method:canCallFunctionWithArgs(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenCallTests]/[method:canCallFunctionWithArgs(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index b4e0185a..50a72cee 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenCallTests]/[method:canCallFunctionWithArgs(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenCallTests]/[method:canCallFunctionWithArgs(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -6,8 +6,9 @@ Locals:
* ("callArgNamed__b__0" int)
* ("callArgPositional__1__0" int)
* ("callArgPositional__0__0" int)
- * ("receiver__0" data-ptr)
+ * ("receiver__0" int)
* ("tmp__0" int)
+ * ("closurePointer__0" data-ptr)
* ("callFunctionPointer__0" function-ptr)
Args:
@@ -20,14 +21,15 @@ Instructions:
(local-copy "callArgPositional__1__0" "pos2")
(local-copy "callArgPositional__0__0" "pos1")
(local-copy "receiver__0" "receiver")
+ (int-to-data-ptr "closurePointer__0" "receiver__0")
(
memory-load
"callFunctionPointer__0"
- pointer="receiver__0"
+ pointer="closurePointer__0"
layout=(struct (function-ptr))
offset=(0)
)
- (call-pointer "tmp__0" "callFunctionPointer__0" ("receiver__0" "callArgPositional__0__0" "callArgPositional__1__0" "callArgNamed__a__0" "callArgNamed__b__0"))
+ (call-pointer "tmp__0" "callFunctionPointer__0" ("closurePointer__0" "callArgPositional__0__0" "callArgPositional__1__0" "callArgNamed__a__0" "callArgNamed__b__0"))
)
Temporary stack:
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenCallTests]/[method:canCallFunctionWithNoArgs(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenCallTests]/[method:canCallFunctionWithNoArgs(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 821b41ee..d57de017 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenCallTests]/[method:canCallFunctionWithNoArgs(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenCallTests]/[method:canCallFunctionWithNoArgs(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -2,8 +2,9 @@ Compilation unit elements:
Locals:
- * ("receiver__0" data-ptr)
+ * ("receiver__0" int)
* ("tmp__0" int)
+ * ("closurePointer__0" data-ptr)
* ("callFunctionPointer__0" function-ptr)
Args:
@@ -12,14 +13,15 @@ Instructions:
(
(local-copy "receiver__0" "receiver")
+ (int-to-data-ptr "closurePointer__0" "receiver__0")
(
memory-load
"callFunctionPointer__0"
- pointer="receiver__0"
+ pointer="closurePointer__0"
layout=(struct (function-ptr))
offset=(0)
)
- (call-pointer "tmp__0" "callFunctionPointer__0" ("receiver__0"))
+ (call-pointer "tmp__0" "callFunctionPointer__0" ("closurePointer__0"))
)
Temporary stack:
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
index ffa8a74e..db00aea8 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
@@ -72,7 +72,7 @@ public class PatioCodeGen {
var receiverResult = context.allocateLocal(
PatioCodeGenLocalSpace.RECEIVER,
- PatioCodeGenClosures.CLOSURE_POINTER_TYPE
+ PatioCodeGenTypes.VALUE_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 9f9487b2..29136b20 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
@@ -157,6 +157,19 @@ class PatioCodeGenClosures {
Source source,
PatioCodeGenContext context
) {
+ var closurePointerResult = context.allocateLocal(
+ PatioCodeGenLocalSpace.CLOSURE_POINTER,
+ CLOSURE_POINTER_TYPE
+ );
+ var closurePointer = closurePointerResult.value();
+ context = closurePointerResult.context();
+
+ context = context.addInstruction(new PatioIntToDataPtr(
+ closurePointer,
+ closure,
+ source
+ ));
+
var functionPointerResult = context.allocateLocal(
PatioCodeGenLocalSpace.CALL_FUNCTION_POINTER,
PatioTypes.FUNCTION_POINTER
@@ -166,7 +179,7 @@ class PatioCodeGenClosures {
context = context.addInstruction(new PatioMemoryLoad(
functionPointer,
- closure,
+ closurePointer,
closureDataLayoutForCall(),
FUNCTION_POINTER_OFFSET,
source
@@ -174,7 +187,7 @@ class PatioCodeGenClosures {
var args = new ArrayList<PatioLocalRef>();
- args.add(closure);
+ args.add(closurePointer);
args.addAll(positionalArgs);