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

Changing "add" and "delete" to be expressions rather than statements #3743

Merged
merged 5 commits into from
May 29, 2024

Conversation

vpax
Copy link
Contributor

@vpax vpax commented May 16, 2024

In #3684 we discussed (among other things) possible syntax for operations associated with a new list container type. The front-runner for popping elements from either the front or the back of a list is using delete (delete L[0] for the front and delete L[-1] for the back). Since a very common operation would be pop-list-element-and-do-something-with-it, it would be helpful if one could write elem = delete L[0], for example, to pop the front of L and return it in elem. However, to do that delete needs to be an AST expression node. Currently, it's an AST statement node, and those don't have values associated with them.

This PR lays the groundwork for such a change. It changes delete AST nodes to be expressions that (potentially) return values. For symmetry, because it would be a bit weird to do otherwise, it also likewise changes add AST nodes.

The question is then what values should these expressions return? This PR kicks that can down the road: they currently behave as "void" types that don't return anything.

While the change is conceptually simple (and backward compatible), it winds up moving a bunch of code from various Stmt files into Expr files, along with small accompanying tweaks, so quite a bit gets touched even though nothing deep is going on.

I've also included two other minor changes. One of these is a bug fix to prevent bad initializers from leading to crashes in some circumstances. The other is to change expressions that render as words to include a space separating that word from their operand. This last (isolated to a separate commit) leads to a bunch of BTest changes that look voluminous but are in fact trivial.

@vpax vpax added Area: Scripting Area: Script Optimization Compiling of Scripts to ZAM/C++ labels May 16, 2024
src/Expr.cc Show resolved Hide resolved
src/Expr.h Show resolved Hide resolved
src/script_opt/ZAM/Expr.cc Show resolved Hide resolved
Copy link
Contributor

@timwoj timwoj left a comment

Choose a reason for hiding this comment

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

Squashed and rebased. I'll merge it after it gets through CI.

@timwoj timwoj merged commit c04e503 into master May 29, 2024
29 of 30 checks passed
@timwoj timwoj deleted the topic/vern/add-del-expr branch May 29, 2024 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Script Optimization Compiling of Scripts to ZAM/C++ Area: Scripting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants