diff --git a/csys/csys.lisp b/csys/csys.lisp index 22c4b5c..0a3b89e 100644 --- a/csys/csys.lisp +++ b/csys/csys.lisp @@ -183,7 +183,7 @@ nil))) (defun connect () - ;; TODO: target may be a list => check if already connected + ;; TODO: checks: already connected? category OK? other conditions? (lambda (msg scope) (let* ((data (shape:data msg)) (syn (synapse (getf data :target) (getf data :op)))) diff --git a/csys/environ.lisp b/csys/environ.lisp index d432a7e..a45e8a7 100644 --- a/csys/environ.lisp +++ b/csys/environ.lisp @@ -98,13 +98,18 @@ nil) (defun forward-connect (msg scope) - (let* ((data (shape:data msg)) + (let* ((head (shape:head msg)) + (data (shape:data msg)) (tgt (getf data :target)) (cust (actor:customer msg))) - (cond - ((null tgt) (setf (getf data :target) (find-cells-near scope cust))) - ((listp tgt) (setf (getf data :target) (find-cell scope tgt)))) - (forward (message:create (shape:head msg) :data data :customer cust) scope))) + (when (listp tgt) + (setf tgt (find-cell scope tgt)) + (setf (getf data :target) tgt)) + (if (or cust (message:addr msg)) + (forward (message:create head :data data :customer cust) scope) + (let ((rcvrs (find-cells-near scope tgt))) + (dolist (rcvr rcvrs) + (actor:send rcvr (message:create head :data data))))))) ;;;; public shortcuts @@ -126,12 +131,18 @@ (when op (util:plist-add data :op op)) (send-message head data :customer cust :env env))) +(defun send-connect-pred (target &key (domain csys:*domain*) (env *env*) op cat) + (let ((head (cons domain :connect)) + (data (list :target target))) + (when op (util:plist-add data :op op)) + (when cat (util:plist-add data :cat cat)) + (send-message head data :env env))) + ;;;; internal helpers (defun register-cell (scope addr cell) (destructuring-bind (dom cat loc) addr - (let* ((reg (spaces scope)) - (spc (getf reg dom))) + (let ((spc (getf (spaces scope) dom))) (space:put spc loc cell) (setf (gethash cell (cells scope)) addr)))) @@ -145,9 +156,10 @@ cell))) (defun find-cells-near (scope cell &key (dist 2)) - (destructuring-bind (&optional dom cat loc) (getf cell (cells scope)) - (when (null loc) - (error "cell not found or loc missing! scope: ~s, cell: ~s" scope cell)) - (let ((space (getf dom (spaces scope)))) - (space:neighbors space loc :dist dist)))) + (let ((addr (gethash cell (cells scope)))) + (destructuring-bind (&optional dom cat loc) addr + (when (null loc) + (error "cell not found or loc missing! cells: ~s, cell: ~s, addr: ~s" + (cells scope) cell addr)) + (space:neighbors (getf (spaces scope) dom) loc :dist dist))))