From 8fb3252df007fb74fcd695908f285915b4facda2 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 20 Jul 2023 15:30:06 +0100 Subject: Generate closure body --- ...on(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected | 4 +++- ...nt(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected | 1 + ...ed(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected | 5 ++++- src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java | 4 +++- 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 positionalParams, List namedParams, FreeVariables freeVariables, - Function compileBody, + Function generateBody, Source source, PatioCodeGenContext context ) { @@ -97,6 +97,8 @@ class PatioCodeGenClosures { )); } + bodyContext = generateBody.apply(bodyContext); + return bodyContext; }); -- cgit v1.2.3