diff --git a/csys/environ.lisp b/csys/environ.lisp index 3c7c94a..0c03726 100644 --- a/csys/environ.lisp +++ b/csys/environ.lisp @@ -11,10 +11,23 @@ (in-package :scopes/csys/environ) +(defclass scope (csys:scope) + (cells :reader cells :initarg :cells :initform (make-hash-table :test #'equal))) + +;;;; action handlers, public callables + +(defun cell-created (msg scope)) + (defun forward-message (head scope &key data customer) (forward (message:create head :data data :customer customer) scope)) (defun forward (msg scope) - (dolist (cell (find-cells (message:addr msg) scope)) + (dolist (cell (find-cells (cells scope) (message:addr msg))) (actor:send cell msg))) +;;;; helpers + +(defun register-cell (reg addr cell)) + +(defun find-cells (reg addr)) + diff --git a/scopes-core.asd b/scopes-core.asd index 8927d42..8584b1d 100644 --- a/scopes-core.asd +++ b/scopes-core.asd @@ -25,6 +25,7 @@ (:file "util/util") (:file "util/async" :depends-on ("util/util")) (:file "util/crypt" :depends-on ("util/util")) + (:file "util/index") (:file "util/iter") (:file "testing" :depends-on ("util/util"))) :long-description "scopes/core: The core packages of the scopes project." diff --git a/test/test-core.lisp b/test/test-core.lisp index 18e9854..5f5432b 100644 --- a/test/test-core.lisp +++ b/test/test-core.lisp @@ -8,6 +8,7 @@ (:config :scopes/config) (:core :scopes/core) (:crypt :scopes/util/crypt) + (:index :scopes/util/index) (:iter :scopes/util/iter) (:logging :scopes/logging) (:message :scopes/core/message) @@ -66,6 +67,7 @@ (progn (test-util) (test-util-crypt) + (test-util-index) (test-util-iter) (test-shape) (core:setup-services) @@ -116,6 +118,15 @@ (== (iter:next it) nil) (== (string (iter:value it)) "A"))) +(deftest test-util-index () + (let ((idx (index:create))) + (index:put idx "1-1" 42) + (index:put idx "1-2" 46) + (index:put idx "1-1" 43) + (== (index:query idx "1-1") '(43 42)) + (== (index:query idx "1-2") '(46)) + )) + (deftest test-shape () (let ((rec (make-instance 'shape:record :head '(:t1)))) (== (shape:head rec) '(:t1 nil)) diff --git a/util/index.lisp b/util/index.lisp new file mode 100644 index 0000000..c2467b3 --- /dev/null +++ b/util/index.lisp @@ -0,0 +1,25 @@ +;;;; cl-scopes/util/index + +;;;; smart string-based indexes e.g. for queryable registries + +(defpackage :scopes/util/index + (:use :common-lisp) + (:export #:create #:put #:query)) + +(in-package :scopes/util/index) + +(defclass index () + ((data :reader data :initform (make-hash-table :test #'equal)))) + +(defun create () + (make-instance 'index)) + +(defgeneric put (idx key value) + (:method ((idx index) key value) + (let* ((data (data idx)) + (cur (gethash key data))) + (setf (gethash key data) (cons value cur))))) + +(defgeneric query (idx key) + (:method ((idx index) key) + (gethash key (data idx))))