Rename kill to quit

This commit is contained in:
Tony Garnock-Jones 2012-08-13 16:49:24 -04:00
parent eeda88d62a
commit 412ac6496b
11 changed files with 41 additions and 41 deletions

View File

@ -38,7 +38,7 @@
(cin (tcp-credit 1)) (cin (tcp-credit 1))
(role out-t) (role out-t)
(role in-t (role in-t
#:on-absence (kill) #:on-absence (quit)
[(tcp-channel _ _ (? bytes? line)) [(tcp-channel _ _ (? bytes? line))
(list (at-meta-level (list (at-meta-level
(cin (tcp-credit 1))) (cin (tcp-credit 1)))

View File

@ -33,7 +33,7 @@
(cin (tcp-credit 1)) (cin (tcp-credit 1))
(role out-topic) (role out-topic)
(role in-topic (role in-topic
#:on-absence (kill) #:on-absence (quit)
[(tcp-channel _ _ (? bytes? line)) [(tcp-channel _ _ (? bytes? line))
(list (at-meta-level (cin (tcp-credit 1))) (list (at-meta-level (cin (tcp-credit 1)))
(send-message `(,connection-id says ,line)))])))) (send-message `(,connection-id says ,line)))]))))

View File

@ -27,7 +27,7 @@
(error 'example-process "Oh noes!") (error 'example-process "Oh noes!")
(begin (write `(awoke after ,delay milliseconds)) (begin (write `(awoke after ,delay milliseconds))
(newline) (newline)
(transition state (kill))))))) (transition state (quit)))))))
(define spy (define spy
(lambda (spy-pid) (lambda (spy-pid)
@ -46,4 +46,4 @@
(spawn spy) (spawn spy)
(spawn (lambda (pid) (example-process 1000))) (spawn (lambda (pid) (example-process 1000)))
(spawn (lambda (pid) (example-process 2000))) (spawn (lambda (pid) (example-process 2000)))
(kill)))) (quit))))

View File

@ -15,7 +15,7 @@
(list (send-tcp-credit remote-addr local-addr 16) (list (send-tcp-credit remote-addr local-addr 16)
(send-message (tcp-channel local-addr remote-addr bs)))] (send-message (tcp-channel local-addr remote-addr bs)))]
[(tcp-channel remote _ (? eof-object?)) [(tcp-channel remote _ (? eof-object?))
(kill)])) (quit)]))
(transition 'no-state (transition 'no-state
(send-tcp-credit remote-addr local-addr 16) (send-tcp-credit remote-addr local-addr 16)

View File

@ -10,7 +10,7 @@
(define ((connection-handler local-addr remote-addr) self-pid) (define ((connection-handler local-addr remote-addr) self-pid)
(transition 'no-state (transition 'no-state
(role (topic-publisher (tcp-channel local-addr remote-addr (wild))) (role (topic-publisher (tcp-channel local-addr remote-addr (wild)))
[(tcp-channel _ _ (tcp-credit _)) (kill)]) [(tcp-channel _ _ (tcp-credit _)) (quit)])
(send-message (tcp-channel local-addr remote-addr (send-message (tcp-channel local-addr remote-addr
(string->bytes/utf-8 (string->bytes/utf-8
(format "~a\n" (current-inexact-milliseconds))))))) (format "~a\n" (current-inexact-milliseconds)))))))

View File

@ -17,7 +17,7 @@
(send-message (send-message
(tcp-channel local-addr remote-addr (bytes-append #"You said: " line #"\n"))))] (tcp-channel local-addr remote-addr (bytes-append #"You said: " line #"\n"))))]
[(tcp-channel remote _ (? eof-object?)) [(tcp-channel remote _ (? eof-object?))
(kill)]))) (quit)])))
(define (listener local-addr) (define (listener local-addr)
(transition 'no-state (transition 'no-state

View File

@ -142,11 +142,11 @@
(if (ground? remote-addr) (if (ground? remote-addr)
(transition state) (transition state)
(transition 'listener-is-closed (transition 'listener-is-closed
(kill) (quit)
(when (eq? state 'listener-is-running) (when (eq? state 'listener-is-running)
(spawn (lambda (dummy-pid) (spawn (lambda (dummy-pid)
(tcp:tcp-close listener) (tcp:tcp-close listener)
(transition 'dummy (kill))) (transition 'dummy (quit)))
#:debug-name (list 'tcp-listener-closer local-addr)))))])) #:debug-name (list 'tcp-listener-closer local-addr)))))]))
(role (topic-subscriber (cons (tcp:tcp-accept-evt listener) (wild))) (role (topic-subscriber (cons (tcp:tcp-accept-evt listener) (wild)))
#:state state #:state state
@ -171,14 +171,14 @@
(define (tcp-connection-manager* local-addr remote-addr cin cout) (define (tcp-connection-manager* local-addr remote-addr cin cout)
(define (close-transition state send-eof?) (define (close-transition state send-eof?)
(transition #f (transition #f
(kill) (quit)
(when (not (eq? state #f)) (when (not (eq? state #f))
(list (when send-eof? (list (when send-eof?
(send-message (tcp-channel remote-addr local-addr eof))) (send-message (tcp-channel remote-addr local-addr eof)))
(spawn (lambda (dummy-pid) (spawn (lambda (dummy-pid)
(tcp:tcp-abandon-port cin) (tcp:tcp-abandon-port cin)
(tcp:tcp-abandon-port cout) (tcp:tcp-abandon-port cout)
(transition 'dummy (kill))) (transition 'dummy (quit)))
#:debug-name (list 'tcp-connection-closer local-addr remote-addr)))))) #:debug-name (list 'tcp-connection-closer local-addr remote-addr))))))
(define (adjust-credit state amount) (define (adjust-credit state amount)
(let ((new-credit (+ (tcp-connection-state-credit state) amount))) (let ((new-credit (+ (tcp-connection-state-credit state) amount)))

View File

@ -12,7 +12,7 @@
(topic-subscriber (udp-packet (wild) local-addr (wild)))) (topic-subscriber (udp-packet (wild) local-addr (wild))))
[(udp-packet source _ #"quit\n") [(udp-packet source _ #"quit\n")
(list (send-message (udp-packet local-addr source #"OK, quitting\n")) (list (send-message (udp-packet local-addr source #"OK, quitting\n"))
(kill #:reason "Asked to quit"))] (quit #:reason "Asked to quit"))]
[(udp-packet source sink body) [(udp-packet source sink body)
(send-message (udp-packet sink source body))])) (send-message (udp-packet sink source body))]))

View File

@ -94,11 +94,11 @@
(topic-subscriber (udp-packet local-addr any-remote (wild)))) (topic-subscriber (udp-packet local-addr any-remote (wild))))
#:state state #:state state
#:on-absence (transition 'socket-is-closed #:on-absence (transition 'socket-is-closed
(kill) (quit)
(when (eq? state 'socket-is-open) (when (eq? state 'socket-is-open)
(spawn (lambda (dummy-pid) (spawn (lambda (dummy-pid)
(udp-close s) (udp-close s)
(transition 'dummy (kill))) (transition 'dummy (quit)))
#:debug-name (list 'udp-socket-closer local-addr)))) #:debug-name (list 'udp-socket-closer local-addr))))
[(udp-packet (== local-addr) (udp-address remote-host remote-port) body) [(udp-packet (== local-addr) (udp-address remote-host remote-port) body)
(udp-send-to s remote-host remote-port body) (udp-send-to s remote-host remote-port body)

48
os2.rkt
View File

@ -45,8 +45,8 @@
send-feedback ;; TODO: maybe call this "send-reply" or "send-as-subscriber"? send-feedback ;; TODO: maybe call this "send-reply" or "send-as-subscriber"?
(except-out (struct-out spawn) spawn) (except-out (struct-out spawn) spawn)
(rename-out [make-spawn spawn]) (rename-out [make-spawn spawn])
(except-out (struct-out kill) kill) (except-out (struct-out quit) quit)
(rename-out [make-kill kill]) (rename-out [make-quit quit])
(except-out (struct-out yield) yield) (except-out (struct-out yield) yield)
(rename-out [yield-macro yield]) (rename-out [yield-macro yield])
(except-out (struct-out at-meta-level) at-meta-level) (except-out (struct-out at-meta-level) at-meta-level)
@ -61,7 +61,7 @@
(rename-out [delete-role <delete-role>]) (rename-out [delete-role <delete-role>])
(rename-out [send-message <send-message>]) (rename-out [send-message <send-message>])
(rename-out [spawn <spawn>]) (rename-out [spawn <spawn>])
(rename-out [kill <kill>]) (rename-out [quit <quit>])
(rename-out [yield <yield>]) (rename-out [yield <yield>])
(rename-out [at-meta-level <at-meta-level>]) (rename-out [at-meta-level <at-meta-level>])
@ -176,7 +176,7 @@
(cond [(transition? t) t] (cond [(transition? t) t]
[else [else
(define message (format "maybe-transition->transition: Expected transition; got ~v" t)) (define message (format "maybe-transition->transition: Expected transition; got ~v" t))
(transition #f (kill #f (exn:fail:contract message (current-continuation-marks))))])) (transition #f (quit #f (exn:fail:contract message (current-continuation-marks))))]))
;; Preactions. ;; Preactions.
;; Ks are various TrapKs or #f, signifying lack of interest. ;; Ks are various TrapKs or #f, signifying lack of interest.
@ -193,15 +193,15 @@
;; (spawn BootSpecification Maybe<TrapK<PID>> Any) ;; (spawn BootSpecification Maybe<TrapK<PID>> Any)
(struct spawn (spec k debug-name) #:prefab) (struct spawn (spec k debug-name) #:prefab)
;; ;;
;; (kill Maybe<PID> Any) ;; (quit Maybe<PID> Any)
(struct kill (pid reason) #:prefab) (struct quit (pid reason) #:prefab)
(define (preaction? a) (define (preaction? a)
(or (add-role? a) (or (add-role? a)
(delete-role? a) (delete-role? a)
(send-message? a) (send-message? a)
(spawn? a) (spawn? a)
(kill? a))) (quit? a)))
;; An Action is either a Preaction or a (yield InterruptK) or an ;; An Action is either a Preaction or a (yield InterruptK) or an
;; (at-meta-level Preaction) or an ignored placeholder (namely #f or ;; (at-meta-level Preaction) or an ignored placeholder (namely #f or
@ -310,7 +310,7 @@
(define make-add-role add-role) ;; no special treatment required at present (define make-add-role add-role) ;; no special treatment required at present
(define (make-delete-role pre-eid [reason #f]) (delete-role pre-eid reason)) (define (make-delete-role pre-eid [reason #f]) (delete-role pre-eid reason))
(define (make-send-message body [role 'publisher]) (send-message body role)) (define (make-send-message body [role 'publisher]) (send-message body role))
(define (make-kill [pid #f] #:reason [reason #f]) (kill pid reason)) (define (make-quit [pid #f] #:reason [reason #f]) (quit pid reason))
(define (make-at-meta-level . actions) (define (make-at-meta-level . actions)
(match actions (match actions
@ -511,8 +511,8 @@
(values '() (route-and-deliver role body state))] (values '() (route-and-deliver role body state))]
[(spawn spec k debug-name) [(spawn spec k debug-name)
(values '() (do-spawn pid spec k debug-name state))] (values '() (do-spawn pid spec k debug-name state))]
[(kill pid-to-kill reason) [(quit pid-to-quit reason)
(do-kill (or pid-to-kill pid) reason state)])) (do-quit (or pid-to-quit pid) reason state)]))
(define (topics-equal? ta tb) (define (topics-equal? ta tb)
;; TODO: OK, if we had a couple of simple topics here, we'd be done ;; TODO: OK, if we had a couple of simple topics here, we'd be done
@ -641,7 +641,7 @@
(match-define (transition initial-state initial-actions) (match-define (transition initial-state initial-actions)
(maybe-transition->transition (maybe-transition->transition
(cond (cond
[(procedure? main) (send-to-user (lambda (e) (transition #f (kill #f e))) main new-pid)] [(procedure? main) (send-to-user (lambda (e) (transition #f (quit #f e))) main new-pid)]
[else main]))) [else main])))
(define initial-process (process new-name (define initial-process (process new-name
new-pid new-pid
@ -657,43 +657,43 @@
(log-info (format "~a PID ~v (~a) started" (vm-name state) new-pid new-name)) (log-info (format "~a PID ~v (~a) started" (vm-name state) new-pid new-name))
(run-trapk spawned-state spawning-pid (list 'spawn 'k debug-name) k new-pid)) (run-trapk spawned-state spawning-pid (list 'spawn 'k debug-name) k new-pid))
(define (print-kill vm-name pid-to-kill process-name reason) (define (print-quit vm-name pid-to-quit process-name reason)
(cond (cond
[(eq? reason #f) (log-info (format "~a PID ~v (~a) exited normally" [(eq? reason #f) (log-info (format "~a PID ~v (~a) exited normally"
vm-name vm-name
pid-to-kill pid-to-quit
process-name))] process-name))]
[(exn? reason) (begin ((error-display-handler) [(exn? reason) (begin ((error-display-handler)
(format "~a PID ~v (~a) exited with exception~n~a" (format "~a PID ~v (~a) exited with exception~n~a"
vm-name vm-name
pid-to-kill pid-to-quit
process-name process-name
(exn-message reason)) (exn-message reason))
reason) reason)
(flush-output (current-output-port)))] (flush-output (current-output-port)))]
[else (log-info (format "~a PID ~v (~a) exited with reason: ~a" [else (log-info (format "~a PID ~v (~a) exited with reason: ~a"
vm-name vm-name
pid-to-kill pid-to-quit
process-name process-name
reason))])) reason))]))
(define (do-kill pid-to-kill reason state) (define (do-quit pid-to-quit reason state)
(cond (cond
[(hash-has-key? (vm-processes state) pid-to-kill) [(hash-has-key? (vm-processes state) pid-to-quit)
(define dying-process (hash-ref (vm-processes state) pid-to-kill)) (define dying-process (hash-ref (vm-processes state) pid-to-quit))
(print-kill (vm-name state) pid-to-kill (process-name dying-process) reason) (print-quit (vm-name state) pid-to-quit (process-name dying-process) reason)
(let* ((state (for/fold ([state state]) ([eid (in-set (process-endpoints dying-process))]) (let* ((state (for/fold ([state state]) ([eid (in-set (process-endpoints dying-process))])
(do-unsubscribe pid-to-kill (eid-pre-eid eid) reason state))) (do-unsubscribe pid-to-quit (eid-pre-eid eid) reason state)))
(new-outbound-actions (for/list ([eid (in-set (process-meta-endpoints dying-process))]) (new-outbound-actions (for/list ([eid (in-set (process-meta-endpoints dying-process))])
(delete-role eid reason)))) (delete-role eid reason))))
(values new-outbound-actions (values new-outbound-actions
(struct-copy vm state [processes (hash-remove (vm-processes state) pid-to-kill)])))] (struct-copy vm state [processes (hash-remove (vm-processes state) pid-to-quit)])))]
[else (values '() state)])) [else (values '() state)]))
(define (run-trapk state pid new-party trap-k . args) (define (run-trapk state pid new-party trap-k . args)
(if trap-k (if trap-k
(let ((failure-proc (lambda (e) (lambda (process-state) (let ((failure-proc (lambda (e) (lambda (process-state)
(transition process-state (kill #f e)))))) (transition process-state (quit #f e))))))
(run-ready state pid new-party (apply send-to-user failure-proc trap-k args))) (run-ready state pid new-party (apply send-to-user failure-proc trap-k args)))
state)) state))
@ -702,7 +702,7 @@
(hash-ref (vm-processes state) pid)) (hash-ref (vm-processes state) pid))
(match-define (transition new-state actions) (match-define (transition new-state actions)
(maybe-transition->transition (maybe-transition->transition
(send-to-user (lambda (e) (transition old-state (kill #f e))) (send-to-user (lambda (e) (transition old-state (quit #f e)))
(lambda () (interrupt-k (contract state-contract (lambda () (interrupt-k (contract state-contract
old-state old-state
old-party old-party
@ -758,7 +758,7 @@
(wrap-trapk pid (list 'meta-spawn 'k debug-name) k) (wrap-trapk pid (list 'meta-spawn 'k debug-name) k)
debug-name) debug-name)
state)] state)]
[(? kill? p) [(? quit? p)
(values p state)])) (values p state)]))
(define-syntax nested-vm (define-syntax nested-vm

View File

@ -50,14 +50,14 @@
(spawn (transition (ticker-state 0 rate-expr limit-expr) (spawn (transition (ticker-state 0 rate-expr limit-expr)
(role wild-sub (role wild-sub
#:state ts #:state ts
['stop (transition ts (kill))]) ['stop (transition ts (quit))])
(let loop ((next-alarm-time 0)) (let loop ((next-alarm-time 0))
(role (topic-subscriber (cons (time-evt next-alarm-time) (wild))) (role (topic-subscriber (cons (time-evt next-alarm-time) (wild)))
#:name 'tick-sequence #:name 'tick-sequence
#:state (and ts (ticker-state counter interval limit)) #:state (and ts (ticker-state counter interval limit))
[(cons _ now) [(cons _ now)
(if (and (positive? limit) (>= counter limit)) (if (and (positive? limit) (>= counter limit))
(transition ts (kill)) (transition ts (quit))
(transition (ticker-state (+ counter 1) interval limit) (transition (ticker-state (+ counter 1) interval limit)
(delete-role 'tick-sequence) (delete-role 'tick-sequence)
(loop (+ now (* 1000 interval))) (loop (+ now (* 1000 interval)))
@ -102,7 +102,7 @@
#:state w #:state w
['stop ['stop
(async-channel-put c:world->ui 'stop) (async-channel-put c:world->ui 'stop)
(transition w (kill))]) (transition w (quit))])
(role wild-sub (role wild-sub
#:state w #:state w
[`(render ,scene) [`(render ,scene)