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

Kotlin codegen always creates new label for variables assignments #174

Open
jenrik opened this issue May 19, 2019 · 1 comment
Open

Kotlin codegen always creates new label for variables assignments #174

jenrik opened this issue May 19, 2019 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@jenrik
Copy link
Member

jenrik commented May 19, 2019

The code generator should only create a new label if it encounters a variable declaration, not when it just sees a variable assignment.

The code in question is here https://github.com/d409f19/cellmata/blob/master/compiler/src/main/kotlin/visitors/codegen.kt#L748:L752

@jenrik jenrik added bug Something isn't working good first issue Good for newcomers labels May 19, 2019
@jenrik
Copy link
Member Author

jenrik commented May 19, 2019

I believe the changing the mentioned code to the following would resolve the issue

val label = if (node.isDeclaration) {
    val newLabel = nextLabel()
    addMapping(node.ident, newLabel)
    newLabel
} else {
    getMappedLabel(node.ident)
}
return "var $label = (${visit(node.expr)})"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant