diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-20 15:30:06 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-20 16:24:32 +0100 |
| commit | 8fb3252df007fb74fcd695908f285915b4facda2 (patch) | |
| tree | f48a362e3bab5b98c6b8e53d3a0fa05f7b1618b1 | |
| parent | bd56a334bc2b9c9670c6d50e55939fb67389317c (diff) | |
Generate closure body
4 files changed, 11 insertions, 3 deletions
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 7243a6ab..d2511387 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -5,8 +5,10 @@ Compilation unit elements: "shed__function__f__0" is-private=true params=(("closurePointer__0" data-ptr)) - locals=() + locals=(("tmp__0" int)) body=( + (int-get "tmp__0" 0) + (return "tmp__0") ) ) diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:freeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:freeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 16868b99..05e26761 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:freeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:freeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -21,6 +21,7 @@ Compilation unit elements: layout=(struct (function-ptr (struct (int int)))) offset=(1 1) ) + (return "local__a") ) ) diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 04007284..2d96c9e3 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -5,7 +5,7 @@ Compilation unit elements: "shed__function__f__0" is-private=true params=(("closurePointer__0" data-ptr) ("local__param1" int) ("local__param2" int) ("local__paramA" int) ("local__paramB" int)) - locals=(("local__a" int) ("local__b" int)) + locals=(("local__a" int) ("local__b" int) ("tmp__0" int) ("tmp__1" int)) body=( ( memory-load @@ -21,6 +21,9 @@ Compilation unit elements: layout=(struct (function-ptr (struct (int int)))) offset=(1 1) ) + (int-add "tmp__0" "local__a" "local__param1") + (int-add "tmp__1" "tmp__0" "local__paramA") + (return "tmp__1") ) ) diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java index 29136b20..fc153522 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java @@ -50,7 +50,7 @@ class PatioCodeGenClosures { List<DefineFunctionInstruction.Param> positionalParams, List<DefineFunctionInstruction.Param> namedParams, FreeVariables freeVariables, - Function<PatioCodeGenContext, PatioCodeGenContext> compileBody, + Function<PatioCodeGenContext, PatioCodeGenContext> generateBody, Source source, PatioCodeGenContext context ) { @@ -97,6 +97,8 @@ class PatioCodeGenClosures { )); } + bodyContext = generateBody.apply(bodyContext); + return bodyContext; }); |
