From 70882baa0eb2cecf83089ffcdf540976186c5e67 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 20 Jul 2023 15:20:11 +0100 Subject: Convert closure value to closure pointer before call --- ...ng.compiler.testing.snapshots.Snapshotter)].expected | 8 +++++--- ...ng.compiler.testing.snapshots.Snapshotter)].expected | 8 +++++--- .../java/org/shedlang/compiler/patio/PatioCodeGen.java | 2 +- .../shedlang/compiler/patio/PatioCodeGenClosures.java | 17 +++++++++++++++-- 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(); - args.add(closure); + args.add(closurePointer); args.addAll(positionalArgs); -- cgit v1.2.3