<div dir="ltr">Hi<div><br></div><div>I am currently writing a program (a CL compiler) and I found a difficulty to</div><div>handle return values efficiently; an example will show what I mean</div><div><br></div><div>(comp form) -> returns (values compiled-code return-values)</div>
<div><br></div><div>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:</div><div><br></div>
<div>;;; the real code is not like this it is just a pseudo code to explain the issue</div><div>(multiple-value-bind (c v) (comp form)</div><div> (let ((x (new-var)))</div><div> (values</div><div> `(,@c (setq ,x (multiple-value-list ,(car v)))) ;;; return compiled code</div>
<div> '((values-list ,x)))) ;;; this will be used by the user of the form</div><div><br></div><div>for example if code is (+ 1 (progn 2 3))</div><div>the compiled code will be :</div><div> 2; (setq x (multiple-value-list 3)); (+ 1 (values-list x))</div>
<div><br></div><div>This works in all cases but it is inefficient because sometimes multiple-value-list</div><div>and values-list are not necessary when the last form of progn returns exactly one</div><div>value.</div><div>
<br></div><div>Any idea how to handle this more efficiently?</div><div><br></div><div>Kind regards</div><div>Taoufik</div><div><br></div></div>