bytecode more complex than needed?

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. -- Kartik Vaddadi. Home: www.cse.iitb.ac.in/~kart Blogs: kartik-log.blogspot.com, kartik-rlog.blogspot.com Alternate mail ID: kartik.vad@gmail.com "50% Reservation, 100% Politics" - Protest the Indian government's decision to increase reservation in private educational institutions (yfemumbai.blogspot.com)

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.
participants (2)
-
Kartik Vaddadi
-
Tom Shackell