-
-
Notifications
You must be signed in to change notification settings - Fork 656
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
[WiP] Adding keyValueIterator to Array #7422
[WiP] Adding keyValueIterator to Array #7422
Conversation
Oooh, I like where this is going! I was thinking that we should open |
That would be nice, especially since many target have different naming/style convention. Btw, I assume that Array handling in cpp is done in hxcpp. But what about the hl and flash target ? |
Check the Boot.hx class for flash. And yes, both hxcpp and hl are going to need updates to their native code. |
Just wanted to make sure : can we accurately make sure that the code |
@elnabo I can't make a PR to your fork, so here is the commit wich, I guess, illustrates what @Simn means with |
@RealyUniqueName Thanks for the commit. Dunno why it's not possible to PR the fork. However for the |
I'm also unsure how the |
We can have this in @:pure @:runtime inline function keyValueIterator() : ArrayKeyValueIterator<T> {
return new ArrayKeyValueIterator(this);
} I just checked, and it works for cpp, which also does not have |
That depends on how well we dodge #7379, which is why I would like to specify ArrayKeyValueIterator instead of KeyValueIterator (the typedef) like in @RealyUniqueName's commit. |
Yeah, I just tested and it seems to works flawlessly on all targets. As there seems to be no target specific key/value iterator. It might be best to simply put it in Array. Unless there is a good reason not to, I'm going to change to that. Maps are going to be different however. |
Yes, maps worry me a bit because they are surely gonna hit #7379... |
I think we should focus on Array in this PR and then merge it. Otherwise it's gonna be delayed by the other types. |
84f3805
to
95d7ee7
Compare
Using the provided commit, the |
Still, need to implement it in the generators of eval, cpp, hl, and flash. Otherwise it won't be accessible through the structure or dynamic field access. |
E.g. static var dyn:Dynamic = [1, 2, 3, 4];
static var struct:{function keyValueIterator():KeyValueIterator<Int,Int>} = [1, 2, 3, 4];
static function test() {
trace(dyn.keyValueIterator()); //exception
for(key => value in struct) { //exception
}
} |
I'm unsure I have the understanding to adapt all generators for this. |
Let's wait for @ncannasse @Simn @hughsando |
You can add the keyValueIterator field like you did before, but then just make it construct an instance of ArrayKeyValueIterator. Check out the createInstance implementation for a reference. Or I can look into it tomorrow. |
I don't have time to test it right now, but something like this should work for eval: let keyValueIterator = vifun0 (fun vthis ->
let ctx = get_ctx() in
let path = key_haxe_iterators_array_key_value_iterator in
let vit = encode_instance path in
let fnew = get_instance_constructor ctx path null_pos in
ignore(call_value_on vit (Lazy.force fnew) [vthis]);
vit
) |
Tried to implement it with
But I get |
@Simn I tried the same as you, but my example was different. Got the same errors with your commit. var a:Dynamic = ["a", "b", "c", "d","e"];
trace(a.keyValueIterator); // #closure
var kvi = a.keyValueIterator();
trace(kvi.hasNext()); // [0] Instance prototype not found: haxe.iterators.ArrayKeyValueIterator
trace(a.keyValueIterator().hasNext()); // [0] Instance prototype not found: haxe.iterators.ArrayKeyValueIterator If I specify the type of |
I have worked on this today and just updated the initial post. The failing targets are HL, hxcpp and lua. HLFails with LuaCI fails with C++Requires a patch to hxcpp to support keyValueIterator on Array. Not sure if anything else needs fixing here. |
Sadly, I'm moving this to 4.1 because there are still some problems to sort out. The HL issue in particular worries me quite a bit. |
I've disabled test of anon/dynamic access to |
@elnabo If you're still around, please update the branch. @Aurel300 Any chance you could look into HaxeFoundation/hxcpp#871? I think that's the last part that's missing here. |
It should be up to date now. |
See #7395
Array
Edit: Limit to Array