First round of trivial-bug fixes and tweaks
This commit is contained in:
parent
114595257c
commit
82229e28f1
43
os.rkt
43
os.rkt
|
@ -6,7 +6,22 @@
|
|||
(require racket/list)
|
||||
(require "functional-queue.rkt")
|
||||
|
||||
(provide ...)
|
||||
(provide
|
||||
;; Actions/Events
|
||||
(struct-out message)
|
||||
(struct-out process)
|
||||
|
||||
;; Kernel Events
|
||||
(struct-out meta-message)
|
||||
|
||||
;; Event handlers and kernel requests
|
||||
(struct-out event-handler)
|
||||
(struct-out kernel-mode-transition)
|
||||
|
||||
;; VMs
|
||||
make-vm
|
||||
run-vm
|
||||
)
|
||||
|
||||
;; Each VM hosts 0 or more *multiplexed* processes. Each process has
|
||||
;; its own state record. In between schedulings, a process consists of
|
||||
|
@ -79,8 +94,8 @@
|
|||
;; the process, and the output is the information passed back to the
|
||||
;; VM when the process yields the CPU.
|
||||
|
||||
;; A BootK is a (Void -> KernelModeTransition), effectively an
|
||||
;; InterruptK with a void initial process state.
|
||||
;; A BootK is a ( -> KernelModeTransition), effectively an InterruptK
|
||||
;; with a void initial process state.
|
||||
|
||||
;; A KernelModeTransition is a
|
||||
;; (kernel-mode-transition ProcessState
|
||||
|
@ -108,12 +123,14 @@
|
|||
;; TODO: timeouts
|
||||
|
||||
(define (make-vm boot)
|
||||
(boot-process boot (vm (list) (make-queue) (make-queue))))
|
||||
(boot-process boot (vm (list) (make-queue))))
|
||||
|
||||
(define (subscribe-process process-state event-handlers state)
|
||||
(struct-copy vm state [subscriptions (cons (subscription process-state
|
||||
event-handlers)
|
||||
(vm-subscriptions state))]))
|
||||
(if (null? event-handlers)
|
||||
state ;; dead process because no continuations offered
|
||||
(struct-copy vm state [subscriptions (cons (subscription process-state
|
||||
event-handlers)
|
||||
(vm-subscriptions state))])))
|
||||
|
||||
(define (enqueue-event event state)
|
||||
(struct-copy vm state [pending-events (cons event (vm-pending-events state))]))
|
||||
|
@ -125,7 +142,7 @@
|
|||
(define state-after-events
|
||||
(foldl dispatch-event
|
||||
(struct-copy vm state-after-timeouts [pending-events (make-queue)])
|
||||
(vm-pending-events state)))
|
||||
(queue->list (vm-pending-events state))))
|
||||
(trap-to-metalevel state-after-events))
|
||||
|
||||
(define (dispatch-event event state)
|
||||
|
@ -148,7 +165,7 @@
|
|||
(search-handlers (cdr event-handlers))])))
|
||||
|
||||
(define (boot-process k state)
|
||||
(run-process (void) k state))
|
||||
(run-process (void) (lambda (dummy) (k)) state))
|
||||
|
||||
(define (run-process process-state k state)
|
||||
(match (k process-state)
|
||||
|
@ -157,11 +174,13 @@
|
|||
new-event-handlers)
|
||||
(subscribe-process new-process-state
|
||||
new-event-handlers
|
||||
(foldl enqueue-event state outbound-events))]))
|
||||
(foldl enqueue-event state outbound-events))]
|
||||
[other
|
||||
(error 'vm "Processes must return a kernel-mode-transition struct; got ~v" other)]))
|
||||
|
||||
(define (trap-to-metalevel state)
|
||||
(define-values (meta-messages non-meta-messages)
|
||||
(partition meta-message? (vm-pending-events state)))
|
||||
(partition meta-message? (queue->list (vm-pending-events state))))
|
||||
(define-values (processes remainder)
|
||||
(partition process? non-meta-messages))
|
||||
(define-values (messages junk)
|
||||
|
@ -170,7 +189,7 @@
|
|||
(struct-copy vm (foldl (lambda (p state) (boot-process (process-boot p) state))
|
||||
state
|
||||
processes)
|
||||
[pending-events messages]))
|
||||
[pending-events (list->queue messages)]))
|
||||
(define outbound-meta-messages
|
||||
(map (lambda (mm) (message (meta-message-body mm))) meta-messages))
|
||||
(kernel-mode-transition
|
||||
|
|
Loading…
Reference in New Issue