savo.la
2011-10-05
Prepare
Every once in a while I promise myself not to hack on build systems anymore. Luckily this project is only loosely related to C/C++ building. It generalizes the source code preprocessor I talked about in my last post.
The Python snippets in the template files may declare globally accessible
classes and functions. Only symbols which start with an uppercase letter are
exported. They may be called by producer templates which collect data and
consumer templates which use that data. Inter-template dependencies are
automatically determined by analyzing symbol declarations and references.
Additionally, the producer/consumer functions have to be tagged with
@producer/@consumer decorators so that
data-collecting templates can be evaluated before the data-using ones.
Silly example
/* type.hy */
{{{
types = []
@producer
def Struct(name):
global types
types.append(name)
echo("struct {name}")
@consumer
def Types():
global types
return types
}}}
/* type.cy */
void dump_types(void)
{
printf("Types:{{{ for name in Types(): echo(' {name}') }}}\n");
}
/* point.hy */
{{{ Struct("point") }}} {
int x;
int y;
};