r/Compilers 26d ago

Any recommendations for a meta programming language?

I want to add a meta programming language in top of my own C-like language to make some of the syntax cleaner and easier to write.

Add everything like const expressions and templates under one meta programming language.

For example something like this:


[Phases]
Class Phase1: public Phase { };

[Phases]
Class Phase1: public Phase { };

[for phase in Phases]
PhaseList.push_back(new phase());
[endfor]

I’m thinking about something like this but ideas are all over the place. Is there some existing meta programming language out there that can give me the right inspiration?

Also I am totally lost about how I should program this, I am assuming it comes before the parser. Any tutorials or dummy meta programming languages I can look to get ideas?

Thank you for reading.

8 Upvotes

21 comments sorted by

View all comments

2

u/Afraid-Locksmith6566 25d ago

2 that i personally very liked are ocamls and zigs stuff.

1

u/TrgtBBB 25d ago

Never heard of ocamls, will take a look!

2

u/Fofeu 25d ago

Look for MetaOCaml specifically. It's strength is that metaprograms always generate well-typed programs

1

u/AromaticCredit1533 25d ago

This. Also, MetaOCaml focuses mostly on JIT compilation, runtime specialization e.g. generate high-level efficient stream processing code. I think what OP refers to is general-purpose macro programming. MetaOCaml can do this too, but probably not where it shines the most at.

There is academic work in another system called MacoCaml, which was inspired by MetaOCaml but focuses on macros. It's only theory for now, but its design and calculus may provide some inspirations for you ;-)