rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.7k stars 175 forks source link

Possible to create AST at compile-time? #814

Open Cerber-Ursi opened 7 months ago

Cerber-Ursi commented 7 months ago

I'm currently trying to use Rhai for one of my personal projects, and hit an interesting question.

This program will essentially do the following:

So this statically-known module, if I understand correctly, can be compiled to AST once and then reused for every source file. But the question is, is it possible to make this AST at build-time, i.e. by calling into the rhai from the build script and emitting something to include_bytes! from? I understand that AST format can be unstable and change from version to version, but since buildscript and the program itself will use the same version, this should not be a problem.

schungx commented 7 months ago

Is this what you want: https://rhai.rs/book/rust/modules/self-contained.html

The import statement is essentially your run function.