#:use-module (oop goops)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-9 gnu)
+ #:use-module (ice-9 control)
#:use-module (ice-9 format)
#:use-module (ice-9 match)
#:use-module (ice-9 pretty-print)
simple-dispatcher build-actions make-action-dispatch
define-simple-actor
+ mhandlers
+
<hive>
make-hive
;; There are more methods for the hive, but there's
;;; Main actor implementation
;;; =========================
+(define (actor-inheritable-message-handler actor message)
+ (define action (message-action message))
+ (define (find-message-handler return)
+ (for-each (lambda (this-class)
+ (define actions
+ (or (and (class-slot-definition this-class 'actions)
+ (class-slot-ref this-class 'actions))
+ '()))
+ (for-each (match-lambda
+ ((action-name . method)
+ (when (eq? action-name action)
+ (return method))))
+ actions))
+ (class-precedence-list (class-of actor)))
+ (throw 'action-not-found
+ "No appropriate action handler found for actor"
+ #:action action
+ #:actor actor
+ #:message message))
+ (define method
+ (call/ec find-message-handler))
+ (apply method actor message (message-body message)))
+
(define-class <actor> ()
;; An address object
(id #:init-keyword #:id
(hive #:init-keyword #:hive
#:accessor actor-hive)
;; How we receive and process new messages
- (message-handler #:allocation #:each-subclass))
+ (message-handler #:init-value actor-inheritable-message-handler
+ ;; @@: There's no reason not to use #:class instead of
+ ;; #:each-subclass anywhere in this file, except for
+ ;; Guile bug #25211 (#:class is broken in Guile 2.2)
+ #:allocation #:each-subclass)
+
+ ;; This is the default, "simple" way to inherit and process messages.
+ (actions #:init-value '()
+ #:allocation #:each-subclass))
(define-method (actor-message-handler (actor <actor>))
(slot-ref actor 'message-handler))
(define %current-actor
(make-parameter #f))
+
\f
;;; Actor utilities
;;; ===============
+;;;;;;;;;;; Deprecated abstractions start here ;;;;;;;;;;;
+
(define (simple-dispatcher action-map)
(lambda (actor message)
(let* ((action (message-action message))
((make-action-dispatch action-item ...)
(simple-dispatcher (build-actions action-item ...)))))
-(define-syntax-rule (define-simple-actor class actions ...)
+;;;;;;;;;;; Deprecated abstractions end here ;;;;;;;;;;;
+
+
+(define-syntax-rule (mhandlers (symbol method) ...)
+ "Construct an alist of (symbol . method), where the method is wrapped
+with wrap-apply to facilitate live hacking and allow the method definition
+to come after class definition."
+ (list
+ (cons (quote symbol)
+ (wrap-apply method)) ...))
+
+(define-syntax-rule (define-simple-actor class action ...)
(define-class class (<actor>)
- (message-handler
- #:init-value (make-action-dispatch actions ...)
- #:allocation #:each-subclass)))
+ (actions #:init-value (mhandlers action ...)
+ #:allocation #:each-subclass)))
\f
;;; The Hive