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

Metaprogramming and AST manipulation from Codon #643

Open
Clonkk opened this issue Mar 21, 2025 · 2 comments
Open

Metaprogramming and AST manipulation from Codon #643

Clonkk opened this issue Mar 21, 2025 · 2 comments

Comments

@Clonkk
Copy link

Clonkk commented Mar 21, 2025

Is there a way to build AST directly from Codon and resolve it at compile time (essentially metaprogramming / macros) ?

@arshajii
Copy link
Contributor

Hi @Clonkk -- can you please give an example of what you'd like to do? While we don't (yet) have a way to access the AST directly from Codon, there are ways to get information about types etc. programmatically that, in combination with other features like decorators, can often accommodate "reflection-style" use cases.

@Clonkk
Copy link
Author

Clonkk commented Mar 24, 2025

I have 2 use-case essentially;

"standard" metaprogramming

Generating multiple functions at compile-time, reducing boiler plate code, implementing templates (code injection) are typical use-case.

Always practical to have on hand but I don't have an actual need for it.

Writing interpreters

Validating and interpreting AST at run-time.

Mapping some external AST onto Codon AST and check the Codon AST is correct or extract an error message.

Codon AST can generate LLVM IR. GraalVM IR + LLI can interpret it; this would make it possible to extend Codon to be both a JIT language and a statically compiled language.

Alternative to above use-case

Since Codon is largely inspired by Python, a typed Codon implementation of the Python AST module to be able to generate, validate and execute Python AST at Codon run-time would work just as well (would probably be slower and much more limiter).

The end goal being able to validate and execute a JIT compiled expression in a statically compiled binary

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

No branches or pull requests

2 participants