[Yhc] bytecode more complex than needed?
Tom Shackell
shackell at cs.york.ac.uk
Wed Sep 27 16:16:45 EDT 2006
Indeed it could :-)
It's almost certainly like that because a let got introduced into calc
by an earlier stage of the compiler. In fact any code involving a
let-introduced variable that isn't used in more than once place could be
simplified by substituting the variable for it's definition. For
example:
let x = foo 10
in bar x
will generate less instructions as:
bar (foo 10)
But since it doesn't save a huge amount I deemed it not worth the effort
needed to detect unshared let introduced variables and remove them :-)
Thanks
Tom
On Thu, 2006-09-28 at 01:38 +0530, Kartik Vaddadi wrote:
> Hello,
> I compiled the following program using yhc:
> > main = print (calc 3)
> > calc x = munge x 6
> > munge x y = x
>
> The bytecode for calc starts with:
>
> NEED_HEAP_1
> PUSH_CONST_0
> PUSH_CONST_1
> PUSH_ZAP_1
>
> Couldn't this be simplified to:
> NEED_HEAP_1
> PUSH_CONST_1
> PUSH_CONST_0
>
> Thanks.
>
More information about the Yhc
mailing list