Skip to content
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

Rust - Emit attribute support for string templates #2875

Merged
merged 1 commit into from
May 6, 2022

Conversation

alexswan10k
Copy link
Contributor

@alexswan10k alexswan10k commented May 6, 2022

This adds support for full substitution syntax, allowing better bindings to be created to native Rust libs.

I know we sort of agreed not to do this as it modifies the original Rust AST, which is a carbon copy of the real AST from the compiler (and thus runs the risk of diverging). That being said, It seems the only realistic alternative is to introduce a full Rust AST Parser, which seems like a massive undertaking and adds significant bloat to Fable.

At least this way we can move forward.

I have added a few basic tests to prove you can call into some std libs such as f64 and Vec by value or by reference, but there are still quite a few caveats to iron out. I have assumed everything entering a template is passed by value, as I think this is the most sensible default. If you want to pass by reference you can just prefix with & like normal Rust. This might need some refinement around function parameters, which will be implicitly by-ref, and need to be dereferenced with *.

Also added a MutDeref to MutCell. It occurred to me recently that Deref and MutDeref might well be a rather convenient escape hatch to deal with some of the complex unwrapping problems we have struggled with for classes etc down the road. One to revisit perhaps. These do need to be imported to work though, but it may clean up some dereferencing fluff.

@ncave ncave merged commit 83e53a7 into fable-compiler:beyond May 6, 2022
ncave added a commit that referenced this pull request May 18, 2022
Co-authored-by: Alex Swan <1506553+alexswan10k@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants