From 4a60a852e7568497b75344639ee9ecdc460fe094 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Thu, 10 Mar 2011 14:52:36 -0500 Subject: [PATCH] fixed bug in juggle-operands: I was computing n much too early. --- compile.rkt | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/compile.rkt b/compile.rkt index 2a38518..05beb74 100644 --- a/compile.rkt +++ b/compile.rkt @@ -348,15 +348,13 @@ ;; Installs the operators. At the end of this, ;; the procedure lives in 'proc, and the operands on the environment stack. (define (juggle-operands operand-codes) - (let: ([n : Natural - ;; defensive coding: the operand codes should be nonempty. - (ensure-natural (sub1 (length operand-codes)))]) - (let: loop : InstructionSequence ([ops : (Listof InstructionSequence) operand-codes]) - (cond - ;; If there are no operands, no need to juggle. - [(null? ops) - (make-instruction-sequence empty)] - [(null? (rest ops)) + (let: loop : InstructionSequence ([ops : (Listof InstructionSequence) operand-codes]) + (cond + ;; If there are no operands, no need to juggle. + [(null? ops) + (make-instruction-sequence empty)] + [(null? (rest ops)) + (let: ([n : Natural (ensure-natural (sub1 (length operand-codes)))]) ;; The last operand needs to be handled specially: it currently lives in ;; val. We move the procedure at env[n] over to proc, and move the ;; last operand at 'val into env[n]. @@ -366,11 +364,11 @@ `(,(make-AssignImmediateStatement 'proc (make-EnvLexicalReference n)) ,(make-AssignImmediateStatement (make-EnvLexicalReference n) - (make-Reg 'val)))))] - [else - ;; Otherwise, add instructions to juggle the operator and operands in the stack. - (append-instruction-sequences (car ops) - (loop (rest ops)))])))) + (make-Reg 'val))))))] + [else + ;; Otherwise, add instructions to juggle the operator and operands in the stack. + (append-instruction-sequences (car ops) + (loop (rest ops)))])))