Work on asynchronous version of execute
This commit is contained in:
parent
45ba1c924a
commit
a380b3d421
3 changed files with 1198 additions and 16 deletions
1182
#gui.rkt#1#
Normal file
1182
#gui.rkt#1#
Normal file
File diff suppressed because it is too large
Load diff
2
gui.rkt
2
gui.rkt
|
@ -94,7 +94,7 @@
|
|||
[else 'comment]))
|
||||
(values 1str bf-token #f (+ pos) (+ pos 1))]))
|
||||
|
||||
; Syntax highlighting for brainf*ck[(symbol=? token 'loop) "Loop"]
|
||||
; Syntax highlighting for brainf*ck
|
||||
(send editor start-colorer bf-token->bf-style bf-lexer '())
|
||||
|
||||
; Define basic style for instructions (+ - , .)
|
||||
|
|
|
@ -313,23 +313,23 @@
|
|||
(prog-state '(1) 0 1 "" "[++--]++--+-[]" 5))
|
||||
(prog-state '(1) 0 1 "" "[++--]++--+-[]" 1))
|
||||
|
||||
; execute: ProgState -> ProgState
|
||||
; Given an initial ProgState state, returns the final ProgState state executing the
|
||||
; program.
|
||||
(define (execute w)
|
||||
; execute: ProgState ((ProgState) -> Any) -> ProgState
|
||||
; Given an initial ProgState state, calls done when the final ProgState is ready
|
||||
; to execute the program.
|
||||
(define (execute w done)
|
||||
(local [(define program-len (string-length (prog-state-program w)))]
|
||||
(cond [(>= (prog-state-ip w) program-len) w]
|
||||
(cond [(>= (prog-state-ip w) program-len) (done w)]
|
||||
[else
|
||||
(define inst (char-at (prog-state-program w) (prog-state-ip w)))
|
||||
(cond [(string=? inst ",") (exec-in w (lambd]
|
||||
[else
|
||||
(local [(define inst
|
||||
(char-at (prog-state-program w) (prog-state-ip w)))]
|
||||
(execute (cond [(string=? inst "+") (exec-add1 w)]
|
||||
[(string=? inst "-") (exec-sub1 w)]
|
||||
[(string=? inst "<") (exec-tape-left w)]
|
||||
[(string=? inst ">") (exec-tape-right w)]
|
||||
[(string=? inst "[") (exec-loop-start w)]
|
||||
[(string=? inst "]") (exec-loop-end w)]
|
||||
[(string=? inst ".") (exec-out w)]
|
||||
[(string=? inst ",") #f])))])))
|
||||
[(string=? inst ".") (exec-out w)]) done)])])))
|
||||
|
||||
; Tests for execute
|
||||
(check-expect (execute (prog-state (list 0) 0 3 "" "" 0))
|
||||
|
|
Loading…
Reference in a new issue