diff --git a/interpreter.rkt b/interpreter.rkt index 31155b2..b2c3d3b 100644 --- a/interpreter.rkt +++ b/interpreter.rkt @@ -407,19 +407,17 @@ ; calls done when the final ProgState has been ; computed by executing the program (define (execute prog done get-input) - - ; The program length in characters - (define program-len (string-length (prog-state-program prog))) - ; execute-help: ProgState -> _ + ; execute-help: ProgState ProgState -> _ ; Helper function for `execute`. - ; Given an initial ProgState state, calls done - ; when the final ProgState is ready. - (define (execute-help w) - (cond [(>= (prog-state-ip w) program-len) (done w)] - [else (execute-instr w execute-help get-input)])) + ; Given an initial ProgState state, and the previous state, + ; calls done when the final ProgState is ready. + (define (execute-help w prev) + (cond [(eq? w #f) (done prev)] + [else (execute-instr w (lambda (new) (execute-help new w)) + get-input)])) - (execute-help prog)) + (execute-instr prog (lambda (new) (execute-help new prog)) get-input)) ; Tests for execute (test-begin