Tweaks and prints. Mostly works but for some reason vat promises tied to ui fiber??

- Need to figure out why main thread is blocking the vat promises from resolving.
This commit is contained in:
Vivianne 2023-07-16 20:43:40 -07:00
parent 910556a7af
commit 65497fd439
2 changed files with 16 additions and 10 deletions

View File

@ -20,7 +20,9 @@
((board-winner? board peer-mark) 'lost) ((board-winner? board peer-mark) 'lost)
(else 'play))) (else 'play)))
(define (signal-turn) (define (signal-turn)
(format #t "signal-turn start\n")
(syscaller-free-fiber (λ () (put-message state+ (%state)))) (syscaller-free-fiber (λ () (put-message state+ (%state))))
(format #t "signal-turn end\n")
#f) #f)
(define (switch-turn!) (define (switch-turn!)
(let ((new-turn (not ($ %my-turn?)))) (let ((new-turn (not ($ %my-turn?))))
@ -34,7 +36,8 @@
(if (not ($ %my-turn?)) (if (not ($ %my-turn?))
(begin (begin
(board-choose! board peer-mark x y) (board-choose! board peer-mark x y)
(switch-turn!)) (switch-turn!)
(format #t "I, the peer, finish my turn.\n"))
(error "It's my turn!"))] (error "It's my turn!"))]
;; TODO: These need to go somewhere else so the peer can't move or init for us! ;; TODO: These need to go somewhere else so the peer can't move or init for us!
[(try-transition) 'playing] [(try-transition) 'playing]
@ -47,11 +50,14 @@
(format #t "Peer's status: ~a\n" status) (format #t "Peer's status: ~a\n" status)
status) #:promise? #t)] status) #:promise? #t)]
[(my-turn! x y) [(my-turn! x y)
(format #t "start my-turn!\n")
(if ($ %my-turn?) (if ($ %my-turn?)
(begin (begin
(board-assert-vacant board x y) (board-assert-vacant board x y)
(format #t "tell peer about it\n")
(on (<- peer 'peer-turn! x y) (on (<- peer 'peer-turn! x y)
(λ (_) (λ (_)
(format #t "peer promise resolve, then switch and return\n")
(board-choose! board mark x y) (board-choose! board mark x y)
(switch-turn!) (switch-turn!)
(%state)) (%state))

View File

@ -31,13 +31,14 @@
#f)) #f))
(define (%read) (define (%read)
(define line (read-line (current-input-port))) (%prompt)
(if (string-prefix? ",q" line) #f (let ((line (read-line (current-input-port))))
(let ((coords (map string->number (string-tokenize line char-set:digit)))) (if (string-prefix? ",q" line) #f
(if (not (= (length coords) 2)) (let ((coords (map string->number (string-tokenize line char-set:digit))))
(begin (format #t "Must be two numbers, x y; or ,quit to quit. Try again.\n") (if (not (= (length coords) 2))
(%prompt) (%read)) (begin (format #t "Must be two numbers, x y; or ,quit to quit. Try again.\n")
coords)))) (%prompt) (%read))
coords)))))
(define (%eval vat b controller coordinates) (define (%eval vat b controller coordinates)
;; weird? ;; weird?
@ -47,8 +48,7 @@
(λ (state) (%display b state))))) (λ (state) (%display b state)))))
(define (%print b state) (define (%print b state)
(%display b state) (%display b state))
(%prompt))
(define (%prompt) (format #t "Enter your move: ")) (define (%prompt) (format #t "Enter your move: "))