Skip to content

Wesl macro #77

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

Merged
merged 21 commits into from
May 27, 2025
Merged

Wesl macro #77

merged 21 commits into from
May 27, 2025

Conversation

k2d222
Copy link
Collaborator

@k2d222 k2d222 commented May 24, 2025

closed #39

The macro allows writing wesl syntax inline in your rust code, which generates the corresponding AST constructor expression. It can interpolate local variables too, which allows code injection.

(this process is called quasiquoting afaict)

Previous art: the quote macro for Rust, yew's html macro, there's one for glsl too. With wgsl it's nice because it mirrors rust's syntax quite nicely.

With this feature I can embed snippets of wesl AST into the code. I was able to move the prelude wgsl file (used for evaluation and validation) to it and I intend to use it for generics. Could be useful for wesl users too, e.g. for generating virtual (runtime) modules.

@k2d222 k2d222 force-pushed the wesl_macro branch 2 times, most recently from 98b0442 to 566b206 Compare May 25, 2025 19:53
@k2d222
Copy link
Collaborator Author

k2d222 commented May 27, 2025

For future reference: the spans of the macro ast nodes count the token indices, not the char indices. It can lead to confusion, but there is no easy way around this until proc_macro Spans get byte_range (rust#54725) (which might not happen any time soon)

@k2d222 k2d222 merged commit 8efb4c1 into main May 27, 2025
13 checks passed
@k2d222 k2d222 deleted the wesl_macro branch May 27, 2025 18:00
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.

wesl! macro to write wesl inline in rust code
1 participant