program for building the program
Gzp
galap at freemail.hu
Tue Dec 1 00:31:33 PST 2009
Just some ideas without any proposal. Some time back on the university
we've learned of 2 layered languages( not sure of the name) from formal
semantics. It occurred to me all this CTFE, template, mixin things are
just an implementation of the mentioned semantics.
So to designing template(generic) code, a simplified language should be
created that generates the actual source. So the border b/n the two
language can be made more explicit and fewer questions arose.
The semantic is an adhoc, only the idea is important, to
specify the language for creating codes:
// block to generate the code
!template MyTemplate(T) {
!for i in ["*","+","-"]
{
!if( T is builin type )
{
!// performs the !i operation on a and b
T op!i (T a T b) { return a !i b }
}
!else
{
T op!i (T a T b) { return a.op!i( b ) }
}
// error as when the generator is invoked, a single if is generated
without a block
//if( true )
//writeln("aaa");
}
}
// invoking the code genertor
MyTemplate!(int)
MyTemplate!(BigInt)
Maybe it's treated like this and has the same view in the head of
everybody, but for me it was not stated like this before.
The compiler also should provide readably output of the generated code.
ex. generated documentation of the generated code (see the !// comment
in the sample)
Regards, Gzp
More information about the Digitalmars-d
mailing list