From 16b4dc413ef200c0405deee2c3b921abcc5d8863 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Mon, 16 Jan 2012 18:29:32 -0500 Subject: [PATCH] Rename meta-message-handler to ground-message-handler --- os-big-bang-example.rkt | 4 ++-- os-big-bang.rkt | 25 ++++++++++++++++++------- universe.rkt | 4 ++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/os-big-bang-example.rkt b/os-big-bang-example.rkt index 2a06f8b..3dbafd0 100644 --- a/os-big-bang-example.rkt +++ b/os-big-bang-example.rkt @@ -17,7 +17,7 @@ (define sid `(read-line-transaction ,reply-addr)) (transition w (subscribe sid - (meta-message-handler w + (ground-message-handler w [((read-line-evt (current-input-port) 'any) => l) (transition w (unsubscribe sid) @@ -30,7 +30,7 @@ (define (tick-driver self-sid interval) (let loop ((last-tick-time 0) (counter 0)) (subscribe self-sid - (meta-message-handler w + (ground-message-handler w [((time-evt (+ last-tick-time interval)) => now) (transition w (unsubscribe self-sid) diff --git a/os-big-bang.rkt b/os-big-bang.rkt index caf644c..5f6f7d8 100644 --- a/os-big-bang.rkt +++ b/os-big-bang.rkt @@ -16,7 +16,8 @@ (struct-out on-message) (struct-out on-meta-message) message-handlers - meta-message-handler + meta-message-handlers + ground-message-handler (except-out (struct-out transition) transition) (rename-out [make-transition transition]) @@ -58,16 +59,26 @@ ;; representation of a suspended world and its active subscriptions. (struct world (state subscriptions) #:transparent) +(define-syntax message-handlers* + (syntax-rules () + ((_ action-constructor old-state-pattern [pattern body ...] ...) + (action-constructor (match-lambda [pattern #t] ... [_ #f]) + (lambda (message old-state) + (match-define old-state-pattern old-state) + (match message + [pattern body ...] ...)))))) + (define-syntax message-handlers (syntax-rules () ((_ old-state-pattern [pattern body ...] ...) - (on-message (match-lambda [pattern #t] ... [_ #f]) - (lambda (message old-state) - (match-define old-state-pattern old-state) - (match message - [pattern body ...] ...)))))) + (message-handlers* on-message old-state-pattern [pattern body ...] ...)))) -(define-syntax meta-message-handler +(define-syntax meta-message-handlers + (syntax-rules () + ((_ old-state-pattern [pattern body ...] ...) + (message-handlers* on-meta-message old-state-pattern [pattern body ...] ...)))) + +(define-syntax ground-message-handler (syntax-rules (=>) ((_ old-state-pattern [(raw-pattern => pattern) body ...]) (on-meta-message raw-pattern diff --git a/universe.rkt b/universe.rkt index 5d505f5..c823e24 100644 --- a/universe.rkt +++ b/universe.rkt @@ -57,7 +57,7 @@ (unsubscribe 'ticker))])) (let loop ((next-alarm-time 0)) (subscribe 'ticker - (meta-message-handler + (ground-message-handler (and w (ticker-state counter interval limit)) [((time-evt next-alarm-time) => now) (if (and (positive? limit) (>= counter limit)) @@ -105,7 +105,7 @@ (list (spawn (os-big-bang 'none (subscribe 'inbound-relay - (meta-message-handler w + (ground-message-handler w [(c:ui->world => message) (transition w (send-message message))])) (subscribe 'stopper