Hello,
I'd like to implement a programming language inside Rust. I already know quite a bit about syntax extension, although my knowledge is a bit outdated...
For illustration purposes, imagine you implement a small functional language inside Rust with a function-like procedural macro, e.g.,
// In file1.rs
functional!(
fun add x y = x + y
)
// In file2.rs
functional!(
fun add2 x y = 2 * (add x y)
)
(Note that I don't want to implement a functional language inside Rust, that is just for illustration).
I believe it is not really a problem to call add
from file2.rs
as long as we import the content of file1 in file2.
My question is: In my functional programming language compiler, how can I implement an interprocedural analysis of the code? That is, viewing all the macros "functional!" in the Rust crate as a whole sub-program that I can analyze.
Furthermore, what about inter-crates analysis?
I got only two ideas so far:
- Rely on
plugins
and lints to perform the code analysis of the macros, andproc_macro
to generate the code. - A rather extreme way: Forget about proc_macro and plugins, and write the compiler on top of Rust (that is, generate the Rust code before calling the Rust compiler).
Any advice? Any new development in procedural macros that I missed?
Many thanks for any help, and merry Christmas!