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

Possible to create AST at compile-time? #814

Open
Cerber-Ursi opened this issue Jan 14, 2024 · 1 comment
Open

Possible to create AST at compile-time? #814

Cerber-Ursi opened this issue Jan 14, 2024 · 1 comment
Labels

Comments

@Cerber-Ursi
Copy link

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:

  • Build a statically-known module, with a bunch of native functions. One of these functions is essentially "run a source file with this module prepended".
  • Run this function on the source file provided by the user.
  • This source file can contain other calls to the same function, therefore executing other source files with the same context.
  • Continue until the whole files tree is walked.

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
Copy link
Collaborator

schungx commented Jan 15, 2024

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

The import statement is essentially your run function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants