If you want ability to control code synthesis process it should be
done explicitly. Code synthesis and compilation should be separated.
Code transformation and rule checking should be done as script to have
control over code generation before and after compilation stage.
But pushing all into compiler will result only in complexity grow.
If you want code transformation you need a representation like an AST (abstract syntax tree) or similar to work on, which would add way more complexity than adding simple constant propagation to a one-pass compiler like Lua's compiler. Once you do all that you end up with what's essentially a Lisp implementation under the hood. It'll compile slower, and use more memory.