Made execute more efficiently
This commit is contained in:
parent
8a1af32dcb
commit
0034de018b
1 changed files with 8 additions and 10 deletions
|
@ -407,19 +407,17 @@
|
||||||
; calls done when the final ProgState has been
|
; calls done when the final ProgState has been
|
||||||
; computed by executing the program
|
; computed by executing the program
|
||||||
(define (execute prog done get-input)
|
(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`.
|
; Helper function for `execute`.
|
||||||
; Given an initial ProgState state, calls done
|
; Given an initial ProgState state, and the previous state,
|
||||||
; when the final ProgState is ready.
|
; calls done when the final ProgState is ready.
|
||||||
(define (execute-help w)
|
(define (execute-help w prev)
|
||||||
(cond [(>= (prog-state-ip w) program-len) (done w)]
|
(cond [(eq? w #f) (done prev)]
|
||||||
[else (execute-instr w execute-help get-input)]))
|
[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
|
; Tests for execute
|
||||||
(test-begin
|
(test-begin
|
||||||
|
|
Loading…
Reference in a new issue