Chores needed for stepper functionality
This commit is contained in:
parent
68f7133999
commit
d2064f326c
2 changed files with 35 additions and 27 deletions
12
gui.rkt
12
gui.rkt
|
@ -64,12 +64,18 @@
|
|||
; run the program
|
||||
(execute-content
|
||||
(lambda (ps)
|
||||
(update-state-gui ps)
|
||||
(send RUN-OUTPUT set-field-background end-col))))
|
||||
|
||||
; update-state-gui: ProgState -> _
|
||||
; Given a prog-state, updates the data tape inspector and the output window with
|
||||
; the contents of that prog-state.
|
||||
(define (update-state-gui ps)
|
||||
(define out (prog-state-output ps))
|
||||
; update data tape inspector
|
||||
(make-tape-cells ps)
|
||||
; set output and change color to ended
|
||||
(send RUN-OUTPUT set-value out)
|
||||
(send RUN-OUTPUT set-field-background end-col))))
|
||||
(send RUN-OUTPUT set-value out))
|
||||
|
||||
; Definition of the run button widget
|
||||
(define RUN-BTN (new button% [parent F]
|
||||
|
@ -218,7 +224,7 @@
|
|||
(define INPUT-DONE-BTN (new button%
|
||||
[parent input-panel]
|
||||
[label "Confirm"]
|
||||
[callback (lambda (btn ev) (input-done-cb btn ev))]))
|
||||
[callback (lambda (b ev) (input-done-cb b ev))]))
|
||||
|
||||
; The run output text object
|
||||
(define RUN-OUTPUT (new text-field%
|
||||
|
|
|
@ -8,14 +8,8 @@
|
|||
racket/struct
|
||||
rackunit)
|
||||
|
||||
(provide prog-state
|
||||
prog-state?
|
||||
prog-state-tape
|
||||
prog-state-tape-len
|
||||
prog-state-dp
|
||||
prog-state-output
|
||||
prog-state-program
|
||||
prog-state-ip
|
||||
(provide (struct-out prog-state)
|
||||
execute-instr
|
||||
execute
|
||||
string->program
|
||||
program->prog-state)
|
||||
|
@ -379,11 +373,11 @@
|
|||
(lambda (done) (done 50))
|
||||
(lambda (w) (check-equal? w (prog-state (list 50) 0 1 "," "" 1 #f)))))
|
||||
|
||||
; execute: ProgState (ProgState -> _) ((Byte -> _) -> _) -> _
|
||||
; Given an initial ProgState state,
|
||||
; calls done when the final ProgState has been
|
||||
; computed by executing the program
|
||||
(define (execute prog done get-input)
|
||||
; execute-instr: ProgState (ProgState -> _) ((Byte -> _) -> _) -> _
|
||||
; Given an initial ProgState state, an async function to get input and a "done"
|
||||
; callback, calls done with the ProgState updated after executing one
|
||||
; instruction.
|
||||
(define (execute-instr prog done get-input)
|
||||
|
||||
; execute-sync: Char ProgState -> ProgState
|
||||
; Given a synchronous instruction as a Char and the current ProgState,
|
||||
|
@ -397,6 +391,20 @@
|
|||
[(char=? inst #\]) (exec-loop-end w)]
|
||||
[(char=? inst #\.) (exec-out w)]))
|
||||
|
||||
; Fetch current instruction
|
||||
(define inst (string-ref (prog-state-program prog) (prog-state-ip prog)))
|
||||
|
||||
; Execute asynchr. if ",", otherwise call callback with results of
|
||||
; execute-sync
|
||||
(cond [(char=? inst #\,) (exec-in prog get-input done)]
|
||||
[else (done (execute-sync inst prog))]))
|
||||
|
||||
; execute: ProgState (ProgState -> _) ((Byte -> _) -> _) -> _
|
||||
; Given an initial ProgState state,
|
||||
; 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)))
|
||||
|
||||
|
@ -406,13 +414,7 @@
|
|||
; when the final ProgState is ready.
|
||||
(define (execute-help w)
|
||||
(cond [(>= (prog-state-ip w) program-len) (done w)]
|
||||
[else
|
||||
; Fetch current instruction
|
||||
(define inst (string-ref (prog-state-program w) (prog-state-ip w)))
|
||||
(cond [(char=? inst #\,)
|
||||
(exec-in w get-input
|
||||
(lambda (ps) (execute ps done get-input)))]
|
||||
[else (execute (execute-sync inst w) done get-input)])]))
|
||||
[else (execute-instr w execute-help get-input)]))
|
||||
|
||||
(execute-help prog))
|
||||
|
||||
|
|
Loading…
Reference in a new issue