[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [DotGNU] treecc help required
From: |
Gopal V |
Subject: |
Re: [DotGNU] treecc help required |
Date: |
Thu, 30 Dec 2004 01:20:44 -0800 (PST) |
Hi,
> One major issue which I faced coming with this
> simple implementation is casting between
> Instruction* and other derived nodes.
> I found that casting between them to be very
> tedious.
The casting is the only way to do it. Even if
you did it in *any* statically typed language in
the world, you would have to put the casts.
Imagine you do it in C# or Java with the following
%node Binary Instruction =
{
Opcode op;
Instruction x;
Instruction y;
}
%node ArithOp Binary
Now the optimize code would look like
Optimize(ArithOp)
{
if ((inst.x is Constant) && (inst.y is Constant))
{
switch(inst.op)
{
case ADD:
return new Constant((inst.x as Constant).value
+ (inst.y as Constant).value));
}
}
return inst;
}
There is no way you can get out of this without using
some kind or other of casts (except if you do this
in Python.. LOL).
I'm sure it doesn't look that different to you :)
> I feel that I am doing a basic mistake in using
> treecc. Would you mind commenting on the way I
> have (mis)used in the attached simple
> implementation.
Seems to be pretty much the way it should be done.
The english speakers might have read that as if you
made the mistake of choosing treecc, rather than just
using it badly.
The advantage of using treecc is that you get
yykindname and yyisa in C , to allow dynamic
"safe" casts and all that :)
Gopal
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail