-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07a11a0
commit ebfe286
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
;; Solution from: http://community.schemewiki.org/?sicp-ex-5.36 | ||
|
||
;; right to left, this is because in construct-arglist, compiler first reverse operand-code, then evaluate the parameters from left to right. | ||
;; To change the order, we can first evaluate the operands from left to right to get the arglist from right to left, then reverse the arglist. | ||
|
||
(define (construct-arglist operand-codes) | ||
(let ((operand-codes operand-codes)) | ||
(if (null? operand-codes) | ||
(make-instruction-sequence '() '(argl) | ||
`((assign argl (const ())))) | ||
(let ((code-to-get-last-arg | ||
(append-instruction-sequences | ||
(car operand-codes) | ||
(make-instruction-sequence '(val) '(argl) | ||
`((assign argl (op list) (reg val))))))) | ||
(if (null? (cdr operand-codes)) | ||
code-to-get-last-arg | ||
(tack-on-instruction-sequence | ||
(preserving '(env) | ||
code-to-get-last-arg | ||
(code-to-get-rest-args | ||
(cdr operand-codes))) | ||
(make-instruction-sequence '() '() | ||
'((assign argl (op reverse) (reg argl)))))))))) |