[Openmcl-devel] help with return values

Pascal J. Bourguignon pjb at informatimago.com
Tue Jan 21 13:52:52 PST 2014


Taoufik Dachraoui <dachraoui.taoufik at gmail.com> writes:

> Hi
>
> I am currently writing a program (a CL compiler) and I found a
> difficulty to
> handle return values efficiently; an example will show what I mean
>
> (comp form) -> returns (values compiled-code return-values)
>
> for example when compiling a progn the return-values is the return of
> the last form in the progn; since I do not know how many values the
> last form returns I am forced to do as follow:
>
> ;;; the real code is not like this it is just a pseudo code to
> explain the issue
> (multiple-value-bind (c v) (comp form)
>   (let ((x (new-var)))
>     (values
>        `(, at c (setq ,x (multiple-value-list ,(car v)))) ;;; return
> compiled code
>        '((values-list ,x))))   ;;; this will be used by the user of
> the form
>
> for example if code is (+ 1 (progn 2 3))
> the compiled code will be :
>    2; (setq x (multiple-value-list 3)); (+ 1 (values-list x))
>
> This works in all cases but it is inefficient because sometimes
> multiple-value-list
> and values-list are not necessary when the last form of progn returns
> exactly one
> value.
>
> Any idea how to handle this more efficiently?

Data flow analysis.


Basically, you consider each return value by itself, to be allocated a
"register", and data flow analysis should be used on all of them
indiscriminately.

Most of the time, the secondary values are not used, which is very soon
detected by the data flow analysis which can then remove the dead-code.



-- 
__Pascal Bourguignon__
http://www.informatimago.com/
"Le mercure monte ?  C'est le moment d'acheter !"




More information about the Openmcl-devel mailing list