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

vm: move ExpandToAst logic into own instruction #281

Merged
merged 1 commit into from
Apr 17, 2022

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Apr 17, 2022

The logic for template expansion as needed by the mExpandToAst magic
(used by quote) is now implemented as a separate instruction instead
of as part of IndCallAsgn. This makes the role of template expansion
less confusing ("why are templates 'called' inside the VM?", "weren't
they expanded already?") and also allows for a different instruction
argument make-up. The latter is required for both a future overhaul
of macro expansion and the refactored VM.

User-facing behaviour stays the same

Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

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

Make makes more sense that it works this way.

One question about the statement list handling, style bit if you're in there.

compiler/vm/vm.nim Outdated Show resolved Hide resolved
templCall.add(node)

var a = evalTemplate(templCall, prc, genSymOwner, c.config, c.cache, c.templInstCounter, c.idgen)
if a.kind == nkStmtList and a.len == 1: a = a[0]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if a.kind == nkStmtList and a.len == 1: a = a[0]
if a.kind == nkStmtList and a.len == 1: # flatten if a single statement
a = a[0]

Also, reading this code, what if it's empty? Should this be an nkEmpty then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know. In order to preserve the previous behaviour, I left this as is

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, let's stick with it for now, it does feel like a bug waiting to happen. 😬

@zerbina zerbina force-pushed the vm-expand-to-ast branch 2 times, most recently from b747342 to 9d8abbd Compare April 17, 2022 21:42
Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

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

Bors r+

The logic for template expansion as needed by the `mExpandToAst` magic
(used by `quote`) is now implemented as a separate instruction instead
of as part of `IndCallAsgn`. This makes the role of template expansion
less confusing ("why are templates 'called' inside the VM?", "weren't
they expanded already?") and also allows for a different instruction
argument make-up. The latter is required by both a future overhaul
of macro expansion and the refactored VM.

User-facing behaviour stays the same
@bors
Copy link
Contributor

bors bot commented Apr 17, 2022

Build succeeded:

@bors bors bot merged commit 7603ef3 into nim-works:devel Apr 17, 2022
@zerbina zerbina deleted the vm-expand-to-ast branch April 21, 2022 11:10
@haxscramper haxscramper added this to the VM backend refactoring milestone Nov 21, 2022
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.

3 participants