Meta Programming - Whiley/WhileyCompiler GitHub Wiki
This is a general discussion page about adding meta-programming support to Whiley. For example, C++ provides support for meta-programming via templates, whilst Rust provides support via macros. Whiley has a proposal now for extending the language with templates (see https://github.com/Whiley/WhileyCompiler/issues/540). Some pointers:
- C++: https://en.wikipedia.org/wiki/Template_metaprogramming
- Rust: https://danielkeep.github.io/quick-intro-to-macros.html
Use Cases
What uses cases do we want to support for meta-programming?
From Issue #740
In real world programming scenarios one often ends up writing scripts that turn data-files into code. Often one also have to update multiple locations with the same data, manually.
It would be very useful to have a feature where the programmer could specify a "lazy" transform from XML/JSON/tab-separated-file to Whiley.
The goal is to make the data available in Whiley-code through some query mechanism, a transform into constants or some other "injection" method.
In Rust you can do this using Macros:
http://stackoverflow.com/questions/32956050/how-to-create-a-static-string-at-compile-time
I have found some situations where this is useful. For example, in creating a Z80 emulator it's useful to include the boot ROM as a compile-time constant from a file.