[Petal] compiled expressions
Fergal Daly
fergal at esatclear.ie
Wed Jun 11 21:29:49 BST 2003
Hi,
I've got fully compiled expressions and all tests passing. To play with it,
apply the patches from earlier today then install the 2 modules from
http://www.fergaldaly.com/computer/Text/
Doing a use Petal::Teng, it sets
$Petal::CodeGenerator = "Petal::Teng::CodeGenerator"
Advantages:
* triple speed for my sample template, everything is compiled down to Perl,
nothing is parsed or interpretted at runtime
* new syntaxes allowed
this/method person/name
which will do roughly
$hash->{this}->method($hash->person->{name})
and
this{key}[5]
which translates to
$hash->{this}->{key}->[5]
which is much faster than using / if you know the types of your variables in
advance.
Problems:
* the generated code is a bit ugly due to no indentation
* modifiers are handled by reverting to doing a $hash->get("modifer:blah") -
this is unavoidable until modifiers know about compiled expressions
* the parser was originally built for TALES so there may be some places where
Petales differs that I have yet to find.
* you may get warnings about undefined values when you access undefined values
in the hash. Petal used to suppress these warnings. This is particularly
noticeable when running test 031 as it accesses a lot of undef values.
Apart from that, everything should work (although it is still experimental),
if it doesn't please let me know,
F
More information about the Petal
mailing list