Compare commits
3 commits
83f1bab7a8
...
cd30c9226e
| Author | SHA1 | Date | |
|---|---|---|---|
| cd30c9226e | |||
| 8d153001fd | |||
| a0e0774a77 |
4 changed files with 69 additions and 20 deletions
|
|
@ -11,9 +11,8 @@
|
||||||
(:export #:scope #:environ
|
(:export #:scope #:environ
|
||||||
#:make-program #:create-zero
|
#:make-program #:create-zero
|
||||||
#:neuron #:std-proc #:eff-proc
|
#:neuron #:std-proc #:eff-proc
|
||||||
#:handle-action #:forward #:notify
|
#:handle-action #:basic-actions #:forward #:notify
|
||||||
#:basic-actions #:merge-actions
|
#:no-op #:printer #:value-add #:create #:connect
|
||||||
#:no-op #:value-add #:create #:connect
|
|
||||||
#:multiply
|
#:multiply
|
||||||
#:send-create #:send-connect))
|
#:send-create #:send-connect))
|
||||||
|
|
||||||
|
|
@ -117,6 +116,7 @@
|
||||||
(handle-action msg scope :default (no-op) :actions actions)
|
(handle-action msg scope :default (no-op) :actions actions)
|
||||||
(when nmsg
|
(when nmsg
|
||||||
(setf (nth 1 (shape:head nmsg)) :effect)
|
(setf (nth 1 (shape:head nmsg)) :effect)
|
||||||
|
(forward nmsg (syns nscope))
|
||||||
(notify nmsg nscope))
|
(notify nmsg nscope))
|
||||||
(update nscope)))))
|
(update nscope)))))
|
||||||
|
|
||||||
|
|
@ -189,6 +189,9 @@
|
||||||
|
|
||||||
;;;; public shortcuts
|
;;;; public shortcuts
|
||||||
|
|
||||||
|
(defun send-message (cell head data)
|
||||||
|
(actor:send cell (message:create head :data data)))
|
||||||
|
|
||||||
(defun send-create (cell &rest args &key (domain :csys)
|
(defun send-create (cell &rest args &key (domain :csys)
|
||||||
(cat :c00) loc connect op &allow-other-keys)
|
(cat :c00) loc connect op &allow-other-keys)
|
||||||
(let ((args+ (if loc
|
(let ((args+ (if loc
|
||||||
|
|
@ -203,6 +206,9 @@
|
||||||
(message:create (list domain :connect)
|
(message:create (list domain :connect)
|
||||||
:data (list :target target :op op))))
|
:data (list :target target :op op))))
|
||||||
|
|
||||||
|
(defun printer ()
|
||||||
|
(actor:create (lambda (msg) (print msg))))
|
||||||
|
|
||||||
;;;; internal helpers
|
;;;; internal helpers
|
||||||
|
|
||||||
(defun new-msg-head (msg scope)
|
(defun new-msg-head (msg scope)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
(:message :scopes/core/message)
|
(:message :scopes/core/message)
|
||||||
(:shape :scopes/shape)
|
(:shape :scopes/shape)
|
||||||
(:util :scopes/util))
|
(:util :scopes/util))
|
||||||
(:export #:create
|
(:export #:create #:simple-proc
|
||||||
#:actions
|
#:actions
|
||||||
#:send-value #:send-connect))
|
#:send-value #:send-connect))
|
||||||
|
|
||||||
|
|
@ -17,9 +17,38 @@
|
||||||
(defclass scope (csys:scope)
|
(defclass scope (csys:scope)
|
||||||
((cells :reader cells :initform (make-hash-table :test #'equal))))
|
((cells :reader cells :initform (make-hash-table :test #'equal))))
|
||||||
|
|
||||||
(defun create (proc meta-env)
|
(defun create (proc meta-env &key eff-contacts) ; meta-env example: (csys:printer)
|
||||||
(let ((prg (csys:make-program proc)))
|
(let* ((prg (csys:make-program proc))
|
||||||
(csys:neuron (csys:scope prg meta-env :cls 'scope :categ '(:env :c00)))))
|
(scope (csys:scope prg meta-env :cls 'scope :categ '(:env :c00)))
|
||||||
|
(env (csys:neuron scope)))
|
||||||
|
(create-contact-cells eff-contacts env (cells scope))
|
||||||
|
env))
|
||||||
|
|
||||||
|
(defun simple-proc (msg scope)
|
||||||
|
(util:mv-bind (nmsg (scope scope))
|
||||||
|
(csys:handle-action msg scope :actions (actions))
|
||||||
|
(util:lgi msg nmsg)
|
||||||
|
(when nmsg
|
||||||
|
(actor:send (env scope) nmsg))))
|
||||||
|
|
||||||
|
;;;; eff contact cells
|
||||||
|
|
||||||
|
(defclass contact-scope (csys:scope)
|
||||||
|
((loc :reader loc :initarg :loc)))
|
||||||
|
|
||||||
|
(defun create-contact-cells (eff-contacts env cells)
|
||||||
|
(util:loop-plist eff-contacts cat locs do
|
||||||
|
(dolist (loc locs)
|
||||||
|
(let ((ct (csys:neuron
|
||||||
|
(csys:scope (csys:make-program #'proc-contact) env
|
||||||
|
:cls 'contact-scope
|
||||||
|
:categ (list :env cat) :loc loc))))
|
||||||
|
;(util:lgi cells cat loc)
|
||||||
|
(register-cell cells (list :env cat loc) ct)))))
|
||||||
|
|
||||||
|
(defun proc-contact (msg scope)
|
||||||
|
(setf (nth 3 (shape:head msg)) (loc scope))
|
||||||
|
(actor:send (csys:environ scope) msg))
|
||||||
|
|
||||||
;;;; action handlers
|
;;;; action handlers
|
||||||
|
|
||||||
|
|
@ -37,6 +66,9 @@
|
||||||
(new (getf data :new)))
|
(new (getf data :new)))
|
||||||
(when addr
|
(when addr
|
||||||
(register-cell (cells scope) addr new))
|
(register-cell (cells scope) addr new))
|
||||||
|
(let* ((ct-addr (cons :env (cdr addr)))
|
||||||
|
(ct (find-cell (cells scope) ct-addr)))
|
||||||
|
(when ct (csys:send-connect new ct)))
|
||||||
;(csys:send-message new (list (message:domain msg) :next) :data data)
|
;(csys:send-message new (list (message:domain msg) :next) :data data)
|
||||||
(actor:send new
|
(actor:send new
|
||||||
(message:create (list (message:domain msg) :next) :data data))
|
(message:create (list (message:domain msg) :next) :data data))
|
||||||
|
|
@ -73,11 +105,11 @@
|
||||||
|
|
||||||
(defun register-cell (reg addr cell)
|
(defun register-cell (reg addr cell)
|
||||||
(destructuring-bind (dom cat &optional (key "")) addr
|
(destructuring-bind (dom cat &optional (key "")) addr
|
||||||
(let* ((dcat (list dom cat))
|
(let* ((categ (list dom cat))
|
||||||
(idx (gethash dcat reg)))
|
(idx (gethash categ reg)))
|
||||||
(unless idx
|
(unless idx
|
||||||
(setf idx (index:create))
|
(setf idx (index:create))
|
||||||
(setf (gethash dcat reg) idx))
|
(setf (gethash categ reg) idx))
|
||||||
(index:put idx key cell))))
|
(index:put idx key cell))))
|
||||||
|
|
||||||
(defun find-cells (reg addr)
|
(defun find-cells (reg addr)
|
||||||
|
|
@ -88,3 +120,9 @@
|
||||||
(util:lgw "not found" addr reg idx))
|
(util:lgw "not found" addr reg idx))
|
||||||
cells)))
|
cells)))
|
||||||
|
|
||||||
|
(defun find-cell (reg addr)
|
||||||
|
(let ((cells (find-cells reg addr)))
|
||||||
|
(when (> (length cells) 1)
|
||||||
|
(util:lgw "more than one cell found" addr reg cells))
|
||||||
|
(car cells)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
(:csys :scopes/csys)
|
(:csys :scopes/csys)
|
||||||
(:environ :scopes/csys/environ)
|
(:environ :scopes/csys/environ)
|
||||||
(:util :scopes/util))
|
(:util :scopes/util))
|
||||||
(:export #:basic-0 #:basic-1))
|
(:export #:basic-0 #:config-basic-1))
|
||||||
|
|
||||||
(in-package :scopes/csys/program)
|
(in-package :scopes/csys/program)
|
||||||
|
|
||||||
|
|
@ -29,6 +29,10 @@
|
||||||
|
|
||||||
;;;; basic-1: minimal cross-linked system
|
;;;; basic-1: minimal cross-linked system
|
||||||
|
|
||||||
|
(defun config-basic-1 ()
|
||||||
|
(list (basic-1) :zero-cat :s00
|
||||||
|
:eff-contacts '(:e00 ("1-0" "1-1"))))
|
||||||
|
|
||||||
(defun basic-1 ()
|
(defun basic-1 ()
|
||||||
(csys:make-program
|
(csys:make-program
|
||||||
(list '(:s00 :initial) (csys:std-proc :next (b1-next-zero))
|
(list '(:s00 :initial) (csys:std-proc :next (b1-next-zero))
|
||||||
|
|
@ -41,7 +45,7 @@
|
||||||
(let ((self actor:*self*))
|
(let ((self actor:*self*))
|
||||||
(csys:send-create self :cat :e00 :loc "1-0" :connect :succ)
|
(csys:send-create self :cat :e00 :loc "1-0" :connect :succ)
|
||||||
(csys:send-create self :cat :e00 :loc "1-1" :connect :succ :op (csys:multiply -1))
|
(csys:send-create self :cat :e00 :loc "1-1" :connect :succ :op (csys:multiply -1))
|
||||||
(csys:send-create self :cat :s00 :stage :basic :loc "0-1")
|
(csys:send-create self :cat :s00 :loc "0-1" :stage :basic)
|
||||||
;; switch :active
|
;; switch :active
|
||||||
nil)))
|
nil)))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,19 +54,20 @@
|
||||||
(tc:check-expected)
|
(tc:check-expected)
|
||||||
(t:show-result))))
|
(t:show-result))))
|
||||||
|
|
||||||
(defun setup-test (prg &key (zero-cat :c00))
|
(defun setup-test (cfg)
|
||||||
(setup-config)
|
(setup-config)
|
||||||
(core:setup-services)
|
(core:setup-services)
|
||||||
(let* ((rcvr (core:find-service :test-receiver))
|
(destructuring-bind (prg &key (zero-cat :c00) eff-contacts) cfg
|
||||||
(env (environ:create #'proc-env t:*test-suite*)))
|
(let ((rcvr (core:find-service :test-receiver))
|
||||||
|
(env (environ:create #'proc-env t:*test-suite* :eff-contacts eff-contacts)))
|
||||||
(setf (tc:receiver t:*test-suite*) rcvr)
|
(setf (tc:receiver t:*test-suite*) rcvr)
|
||||||
(csys:create-zero prg env :categ (list :csys zero-cat))
|
(csys:create-zero prg env :categ (list :csys zero-cat))
|
||||||
env))
|
env)))
|
||||||
|
|
||||||
;;;; test definitions
|
;;;; test definitions
|
||||||
|
|
||||||
(deftest test-basic-0 ()
|
(deftest test-basic-0 ()
|
||||||
(let ((env (setup-test (program:basic-0))))
|
(let ((env (setup-test (list (program:basic-0)))))
|
||||||
;(rcvr (tc:receiver t:*test-suite*))
|
;(rcvr (tc:receiver t:*test-suite*))
|
||||||
(sleep 0.1)
|
(sleep 0.1)
|
||||||
;(tc:expect rcvr (message:create '(:csys :effect :e01) :data '(:value 1)))
|
;(tc:expect rcvr (message:create '(:csys :effect :e01) :data '(:value 1)))
|
||||||
|
|
@ -76,7 +77,7 @@
|
||||||
(core:shutdown)))
|
(core:shutdown)))
|
||||||
|
|
||||||
(deftest test-basic-1 ()
|
(deftest test-basic-1 ()
|
||||||
(let ((env (setup-test (program:basic-1) :zero-cat :s00)))
|
(let ((env (setup-test (program:config-basic-1))))
|
||||||
(sleep 0.1)
|
(sleep 0.1)
|
||||||
(environ:send-value env 1 :cat :s00 :loc "0-0")
|
(environ:send-value env 1 :cat :s00 :loc "0-0")
|
||||||
(environ:send-value env 2 :cat :s00 :loc "0-1")
|
(environ:send-value env 2 :cat :s00 :loc "0-1")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue