Optimizer

Scott Miller <[email protected]>
Newsgroups gmane.comp.java.sisc.devel
Message-ID <[email protected]>
[email protected] wrote:

>>(define (f a b) (+ a (* b 2)))
>>    
>>
>>(procedure-body f) => (lambda (a b) (+ a (* b 2)))
>>    
>>
>Your best bet is to modify the optimizer, or create your own, that emits 
>the following code:
>
>(define lhs (lambda formals body)) =>
>(define lhs (let ([tmp (lambda formals xbody)])
>              (procedure-property tmp 'body 'xbody)
>              tmp))
>
After talking with Matthias on #sisc I understand this much better but I 
still have a long way to go, I think.

1. You suggest that I write a case for the match in |opt| that handles 
"(define lhs (lambda formals body))"?
Yes, and it should probably call opt:lambda to optimize the lambda thats 
there so you don't loose out on optimizations.

2. Where did xbody come from? 
Typo because I was writing a rough impl.  More like:

  ((define ,lhs (lambda ,formals ,body))
   (let ([new-lambda (opt:lambda formals body state)])
     `(define ,lhs ,((lambda (tmp)
	              (begin
                        (set-procedure-property! tmp 'body ,body)
                        tmp))
                     ,new-lambda))))

3. Did you mean that handler should use |set-procedure-property| ?  
Otherwise, how is the property set?
Right, my bad.
4. What's the match expression? "((define ,lhs ,[lambda formals body])" ?

In the match cases, ,var means match anything an assign it to the 
variable "var".  ,[var] means recurse on the expression (ie if your in 
opt, call (opt var), and bind the results to "var".  ,[var1 var2] is the 
same, but expects multiple return values, assigning the first to var1 
and the second to var2.

5. Do I need a separate case for "(define (foo bar) (shoo bar))" ?  I 
need to have the 'body property on those too.

No, the syntax expander has already converted everything to simple 
expressions.

6. Do I need to modify both |opt| and |scan|?
No.  Scan is responsible for collecting information about lexical 
variables, variables that are set!'ed, etc.  This information is 
passed to opt does the actual transformations.

	Scott
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+pBq8r9IW4v3mHtQRAjSiAKCOGRuFwH/2tEox19777M52guSSXQCeIW2+
BMydRibDasV1npJknSgplv8=
=j5M+
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.