-
Notifications
You must be signed in to change notification settings - Fork 2
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
Make bridge variables respect scopes better #1
Comments
On further thought (and trying to fix it), I've realized that problem 1 in the OP can't be solved by a macro (so, for the purposes of this crate, it can't be solved). That's alright, since it's an odd way to use The second one, however, is definitely possible. We just need to keep track of every time we enter a new scope. And, come to think of it, we should be doing that anyway! If we don't, this won't compile: rusty_asm! {
if condition { // The current parser sees this as one statement and glosses over it,
asm { // never seeing the `asm` block.
"cli
hlt"
}
}
} |
Because of how Syn works, it's actually really hard to parse the internals of just any arbitrary block. I have an idea for how to extend Syn to allow it, but it's complicated and not backwards-compatible. For now, there is a workaround, which I've added to the documentation: whenever an inner block prevents bridge variables or |
New idea: We don't need to confirm that everything parses correctly--we only need to find
Unfortunately, this change will require a significant restructuring of the code. |
Also, we only need to look for |
Implemented. I ended up just looking for every keyword everywhere, except between |
Currently,
rusty_asm!
assumes that bridge variables will always be defined in the same scope as where they're used. This assumption leads to incorrect parsing in two kinds of scenarios:A
rusty_asm!
block inside anotherrusty_asm!
block. The inner block should have access to all of the bridge variables defined so far by the outer block (since they're still in scope, according to Rust), but currently, attempting to use them in ASM in that situation fails.This is fixable by making
rusty_asm_internal!
, which would be exactly like the currentrusty_asm!
except that it would expect a list of inputs, outputs, and clobbers before its statements.rusty_asm!
would callrusty_asm_internal!
with an empty list, andrusty_asm_internal!
would translate all interior calls torusty_asm!
into calls torusty_asm_internal!
.asm!
, but it is dangerous if that variable was shadowing another that has differentin
/out
semantics. This example, for instance, tells the compiler thatThe text was updated successfully, but these errors were encountered: