-
-
Notifications
You must be signed in to change notification settings - Fork 891
avm2: Add #[native]
macro to allow defining methods with native types
#7895
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
base: master
Are you sure you want to change the base?
Conversation
d2b0087
to
6c650d2
Compare
I wonder why not implement this instead in |
FWIW I agree; "rust-dependent" paths could be handled by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I'm AFK this weekend so am not able to test this deeply, but it looks fine at a glance, so please feel free to merge if you feel its ready -- otherwise I'll get to it on Monday.
Re: redundant checks in extract_from_vm
, I think this will be cleaned up when we make a smarter Value
type (union, tagged pointer, NaN-boxed, whatever), which will let us easily do the get_unchecked
equivalent inside extract_from_vm
. In the meantime, maybe std::hint::unreachable_unchecked()
could let us extract the enum variants in a branchless fashion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has been sitting on the PR queue for far too long; mind giving it one more rebase/merge resolution cycle?
Sorry that I didn't merge this way back! I agree, assuming this is still useful, let's rebase this. |
76322ef
to
db87295
Compare
@Herschel @kmeisthax rebased |
One thing I'm worried about is whether or not "extracting" the type directly is the right approach. From my perspective, it makes more sense to coerce the value to the specified type instead. For example, currently if I have a parameter like |
Note that Number/int/uint are tricky in general. Just check out |
I believe we already do those coercions (based on the type declared in the signature) in the Activation code that sets up a method call. |
More specifically, for numbers, (even if Ruffle doesn't do it perfectly in line with FP, eventually we should), this is still awkward:
So even if you want an |
49d4e76
to
e6d0325
Compare
@Aaron1011 wanna give it one last rebase and see if we can finally land this? |
6db3d2e
to
0dffde1
Compare
This allows you to define a native method like: ```rust fn my_method(activation: &mut Activation, this: DisplayObject<'gc>, arg: bool) ``` instead of needing to use `Option<Object<'gc>>` and `&[Value<'gc>]` and manual coercions. See the doc comments for more details.
0dffde1
to
6f3c682
Compare
I think the vast majority of native methods will always be coercing to some internal type like Twips, so this won't come up very often. When it does, the native method can just use |
This allows you to define a native method like:
instead of needing to use
Option<Object<'gc>>
and&[Value<'gc>]
and manual coercions.
See the doc comments for more details.