zetzit / zz

πŸΊπŸ™ ZetZ a zymbolic verifier and tranzpiler to bare metal C
MIT License
1.6k stars 52 forks source link

procedural macros #40

Closed jwerle closed 4 years ago

jwerle commented 4 years ago

Hello @aep,

What are your thoughts on not inserting a semicolon at the end of a macro evaluation?

For example:

macro string() {
  "hello"
}

printf("%s\n", string);

results in a compile error because a semicolon is inserted at the end of "hello"

aep commented 4 years ago

that's intentional for macro hygiene. However, it also makes macros less useful.

My intention is actually to replace macros with something similar to what rust does: full AST manipulation. i.e. a macro should take an AST and return an AST, which would absolutely allow constructing a string like that.

jwerle commented 4 years ago

Yeah that makes sense. That sounds great about the macro improvement. I am looking forward to it!

aep commented 4 years ago

@jwerle have a look at

https://github.com/aep/zz/pull/41/files#diff-37d3d2e9ec9ee1d59e668dda9af632b3

macros are now arbitrary zz code that gets executed on the host. it can in turn return arbitrary zz code on stdout, which is evaluated in the context of the macro invocation