-
Notifications
You must be signed in to change notification settings - Fork 100
Construct external Rust types with named fields #589
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
Changes from 3 commits
5d7fe00
47c47a9
4fde80e
f55572a
f394862
de7a594
bcf6baa
0d5e20d
960eb50
86ee513
4f73981
5902737
b8ac03b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1957,9 +1957,38 @@ fn expr_object<'hir>( | |
) -> compile::Result<Asm<'hir>> { | ||
let guard = cx.scopes.child(span)?; | ||
|
||
for assign in hir.assignments { | ||
let mut order = Vec::with_capacity(hir.assignments.len()); | ||
|
||
for assign in hir.assignments.iter() { | ||
expr(cx, &assign.assign, Needs::Value)?.apply(cx)?; | ||
cx.scopes.alloc(&span)?; | ||
|
||
let position = assign.position.ok_or(compile::Error::msg( | ||
span, | ||
format!("missing position for field assignment {}", assign.key.1), | ||
))?; | ||
udoprog marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
order.push(position); | ||
} | ||
|
||
for stack_position in 0..hir.assignments.len() { | ||
loop { | ||
let desired_position = order[stack_position]; | ||
|
||
if stack_position == desired_position { | ||
break; | ||
} | ||
|
||
order.swap(stack_position, desired_position); | ||
|
||
cx.asm.push( | ||
Inst::Swap { | ||
a: stack_position, | ||
b: desired_position, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think these will have to be offset from the base of stack construction since the stack might contain other data before this point? That is, based of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I was going to ask you about this. Currently this is using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Relative to the stack frame seems fine and easy to reason about. Unless you can come up with some other reason. |
||
}, | ||
span, | ||
); | ||
} | ||
} | ||
|
||
let slot = | ||
|
@@ -1976,6 +2005,9 @@ fn expr_object<'hir>( | |
hir::ExprObjectKind::StructVariant { hash } => { | ||
cx.asm.push(Inst::StructVariant { hash, slot }, span); | ||
} | ||
hir::ExprObjectKind::Constructor { hash, args } => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't a great name, IMO. Any suggestions? Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Including "External" seems good, so 👍. Not important to be perfect since it's an internal variant and can easily be renamed. |
||
cx.asm.push(Inst::Call { hash, args }, span); | ||
} | ||
hir::ExprObjectKind::Anonymous => { | ||
cx.asm.push(Inst::Object { slot }, span); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.