Metacza Compiles to C++ Template Meta Language
Synopsis |
※ |
The Template Meta Compiler with Zero Apprehension
Metacza compiles a functional language to C++ Template Meta Language. It can be used to ease Template Meta Programming in C++.
The C++ Template Meta Language (C++-TML) is surprisingly powerful. It is actually a higher order purely functional language with multiple dispatch. All these features are supported by Metacza. Metacza also contains features for seamless integration into C++ projects, with or without the Boost.MPL library. Metacza allows the use of different namespaces and passes through pre-processor directives unchanged so that header files for C++ can be generated directly.
One of Metacza's design goals is to have only a shallow layer on top of C++ for two reasons:
- to have a seamless integration, i.e., the generated code should be usable from C++ when manually using C++ templates, and
- in order to keep the compiler small and simple so that it can easily understood what is going on.
Metacza is simple enough to only look at single statements, and the goal is to never need a native include mechanism so that each file can be translated individually. The difficult work is passed on to the C++ compiler.
Metacza documentation: [ introduction | syntax | examples ]
Example |
※ |
Input: Metacza | Output: C++ |
---|---|
fib(n) = fib(n-1) + fib(n-2); fib(0) = 0; fib(1) = 1; |
template<typename n> struct fib { typedef typename plus< typename fib< typename minus< n, int_<1> >::type >::type, typename fib< typename minus< n, int_<2> >::type >::type >::type type; }; template<> struct fib< int_<0> > { typedef int_<0> type; }; template<> struct fib< int_<1> > { typedef int_<1> type; }; |
Note that this example is slightly simplified. If you want to try it out, use this example.
Bugs |
※ |
- print() does not always work (but it does not always work in Boost either: in some cases g++ just does not produce the warning needed to print a type). No solution yet, no method known to always produce a warning.
- Boost style tag dispatch does not work yet, as Metacza currently requires an additional ::type to return the wrapped lambda function, while in Boost, it is accessible directly. You can write an extension in unintuitive syntax, but you cannot call tag dispatched functions. This will be done in the future.
Changes |
※ |
-
Version 3 (Stable; Feature Release)
※ - Bug Fix: false and true where broken, because they did not occur in the test file, and untested stuff is always broken...
-
Bug Fix/Feature: in Boost, operators return integral_c even if input type was int_. This caused pattern matches to fail because integral_c<int,10> is not the same type as int_<10>. For this reason, Metacza now always generates integer constants as integral_c<long long,...>. This is not perfect, I know. (But neither is Boost.MPL's system if integers, in my opinion.)
- Bug fix: #endif and some other preprocessor directives needed two CRs to work properly. This is hopefully fixed now.
- Bug fix: Layout rule did not reset reference column after closing a block.
- Feature: arguments in the first line of Metacza files are parsed much more similarly to what a Bourne shell does.
- Feature: in prototypes or prototypical function definitions, arguments may have default values.
- Feature: assert() may be used without an explicit text message. A generic assertion failure message will be generated in this case.
- Feature: Raw C++ code can now be used as a special kind of statement. See this example for a demonstration.
- Feature: UTF-16 support is implemented.
- Feature: Double underbar (__) is allowed in identifiers (Metacza should not artificially restrict the user.)
- Feature: Some classifications may now be embedded in the parameter list, instead of being placed in a 'let' block.
- Feature: bitnot_ is translated to bitxor_ for Boost as Boost.MPL has no bit negation for some unknown reason. The translation is not perfect: it should create an int of the same type as the argument to bitnot_ to be correct. Hopefully one day Boost will be extended and this hack can be removed.
- Documentation: Add example for extending tag dispatched functions in Boost.
-
Version 2 (Stable; Bug Fix)
※ - Bug fix: string.h is now always built (this broke non-test installations)
- Bug fix: #pragma was not recognised
- Clean Up: Don't use __ anymore in generated auxiliary identifiers
-
Version 1 (Stable; Initial)
※ - Initial release.
License |
※ |
Metacza is distributed under the GNU General Public License, Version 3.