Simn / genjvm

13 stars 1 forks source link

API patches (like String methods) #37

Closed Simn closed 5 years ago

Simn commented 5 years ago

Ideally, we want to support both "foo".substr and ("foo" : Dynamic).substr. There are several options for the first one, but the second one is a bit harder.

An idea would be to collect all these methods at compile-time and create a map from the accessed field to the implementation field. Something along the lines of:

["String" => [ "substr" => ["StringExt", "substr"], "substring" => ["StringExt", "substr"]]]

The dynamic lookup can then (either eagerly or on failure) index into that map with the type and field name, and rewrite the field accordingly.

This could be done explicitly through some @:jvm.reroute("StringExt", "substr") metadata on the field, or we do it implicitly for all extern fields that have expressions.

Simn commented 5 years ago

extern fields that have expressions

Actually, I think we recently disallowed that in Haxe...

Simn commented 5 years ago

We're hardcoding this for now, which I think is fair enough because there are only a few cases here (String and Math).