Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create lambda handlers #306

Merged
merged 12 commits into from
Jan 20, 2025
Merged

Conversation

SebastianSpyrzewski
Copy link
Collaborator

@SebastianSpyrzewski SebastianSpyrzewski commented Jan 19, 2025

Created lambda handler and made it access correctly variables from closure.

Some TODO's in PrologueEpilogueHandler and FunctionAnalysis that I believe need to be done next week.

src/main/kotlin/cacophony/controlflow/CFGUtils.kt Outdated Show resolved Hide resolved

class FunctionHandlerImpl(
private val function: FunctionDefinition,
private val analyzedFunction: AnalyzedFunction,
// List of parents' handlers ordered from immediate parent.
private val ancestorFunctionHandlers: List<FunctionHandler>,
private val ancestorFunctionHandlers: List<CallableHandler>, // first (or last?) can be Lambda, not Function
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this matter? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, I don't really understand what's this comment for 😄
Does it mean that we have to be careful what we provide in the constructor? Or how we use these handlers? Or is it just explaning why it's CallableHandler and not FunctionHandler.

If it's the last one then I think we don't have to explain it, it feels natural that the interface is as general as it can be.

@SebastianSpyrzewski SebastianSpyrzewski marked this pull request as ready for review January 20, 2025 11:55
@SebastianSpyrzewski SebastianSpyrzewski changed the title Preparation of lambda handlers Create lambda handlers Jan 20, 2025
@SebastianSpyrzewski SebastianSpyrzewski force-pushed the gen-variable-access-for-closures branch from 2edc951 to d411576 Compare January 20, 2025 12:36
@SebastianSpyrzewski SebastianSpyrzewski force-pushed the gen-variable-access-for-closures branch from 302b980 to b92ddbe Compare January 20, 2025 13:39
import kotlin.math.max

abstract class CallableHandlerImpl(
private val analyzedFunction: AnalyzedFunction, // TODO: we need to change it so it also covers lambda expressions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also describe the TODOs here so it's all in one place: #305

@@ -22,7 +24,8 @@ class PrologueEpilogueHandler(
fun generatePrologue(): List<CFGNode> {
val nodes = mutableListOf<CFGNode>()
nodes.add(registerUse(rsp) subeq integer(REGISTER_SIZE))
nodes.add(pushLabel(getStackFrameLocation(handler.getFunctionDeclaration())))
// TODO: how to cover lambdas here?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems like something to think about together, no? #305

Copy link
Owner

@mhorod mhorod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, given that this was a bit more difficult sprint due to the confusion, good work!

@SebastianSpyrzewski SebastianSpyrzewski merged commit 59379c1 into main Jan 20, 2025
1 check passed
@SebastianSpyrzewski SebastianSpyrzewski deleted the gen-variable-access-for-closures branch January 20, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants