csys:create-zero basically working

This commit is contained in:
Helmut Merz 2026-07-21 12:53:49 +02:00
parent 72de4e9126
commit d316b73e93
3 changed files with 36 additions and 35 deletions

View file

@ -10,8 +10,9 @@
(:alx :alexandria)) (:alx :alexandria))
(:export #:scope #:environ (:export #:scope #:environ
#:make-program #:make-program
#:neuron #:std-proc #:create #:neuron #:std-proc #:create-zero
#:handle-action #:handle-action
#:no-op
#:notify)) #:notify))
(in-package :scopes/csys) (in-package :scopes/csys)
@ -30,17 +31,17 @@
(environ :reader environ :initarg :environ))) (environ :reader environ :initarg :environ)))
(defun scope (prg env &rest args &key (cls 'scope) &allow-other-keys) (defun scope (prg env &rest args &key (cls 'scope) &allow-other-keys)
(remf args :cls) (setf args (alx:remove-from-plist args :cls :environ :program))
(apply #'make-instance cls :program prg :environ env args)) (apply #'make-instance cls :program prg :environ env args))
(defmethod initialize-instance :after ((sc scope) &key &allow-other-keys) (defmethod initialize-instance :after ((sc scope) &key &allow-other-keys)
(set-proc sc)) (set-proc sc))
(defun reset-scope (scope &rest args) (defun reset-scope (scp &rest args)
(apply #'scope (apply #'scope
(getf args :program) (program scope) (getf args :program (program scp))
(getf args :environ (environ scope)) (getf args :environ (environ scp))
:categ (getf args :categ (categ scope)) :categ (getf args :categ (categ scp))
args)) args))
(defun set-proc (scope) (defun set-proc (scope)
@ -48,27 +49,26 @@
scope) scope)
(defgeneric make-program (spec) (defgeneric make-program (spec)
(:method ((fn function)) (lambda (scope) fn))) (:method ((fn function)) (lambda (scp) fn)))
(defun create-zero (prg env &key (categ '(:csys :c00)) (name "0-0"))
(let* ((domain (car categ))
(addr (list domain (cadr categ) name))
(msg (message:create (list domain :create) :data (list :addr addr)))
(scope (scope prg env :categ categ)))
(create msg scope)))
;;;; neurons (= async tasks) and synapses (= connections) ;;;; neurons (= async tasks) and synapses (= connections)
(defun neuron (scope) (defun neuron (scope)
(actor:create (process scope))) (actor:create (process scope)))
(defun synapse (rcvr &optional (op #'identity))
(lambda (msg)
(actor:send rcvr (funcall op msg))))
(defun update (scope) (defun update (scope)
(actor:become (process scope))) (actor:become (process scope)))
(defun create (prg env &key (categ '(:csys :c00)) name value) (defun synapse (rcvr &optional (op #'identity))
(let* ((domain (car categ)) (lambda (msg)
(addr (when name (list domain (cadr categ) name))) (actor:send rcvr (funcall op msg))))
(scope (apply #'scope prg env :categ categ (when value (list :value value))))
(msg (message:create (list domain :create)
:data (when addr (list :addr addr)))))
(do-create msg scope)))
;;;; message handlers, proc steps ;;;; message handlers, proc steps
@ -81,7 +81,7 @@
(forward nmsg (syns nscope)) (forward nmsg (syns nscope))
(update nscope))) (update nscope)))
(defun do-create (msg scope) (defun create (msg scope)
(let ((new (neuron (apply #'reset-scope scope (shape:data msg))))) (let ((new (neuron (apply #'reset-scope scope (shape:data msg)))))
(notify-created msg new scope))) (notify-created msg new scope)))

View file

@ -6,7 +6,8 @@
(:csys :scopes/csys) (:csys :scopes/csys)
(:index :scopes/util/index) (:index :scopes/util/index)
(:message :scopes/core/message) (:message :scopes/core/message)
(:shape :scopes/shape)) (:shape :scopes/shape)
(:util :scopes/util))
(:export #:create (:export #:create
#:actions #:actions
#:forward)) #:forward))
@ -23,14 +24,15 @@
;;;; action handlers, public callables ;;;; action handlers, public callables
(defun actions () (defun actions ()
'(:created #'cell-created (list :created #'cell-created
:default #'csys:notify)) :default #'csys:no-op))
(defun cell-created (msg scope) (defun cell-created (msg scope)
(let* ((data (shape:data msg)) (let* ((data (shape:data msg))
(addr (getf data :addr))) (addr (getf data :addr)))
(when addr (when addr
(register-cell (cells scope) addr (getf data :new))))) (register-cell (cells scope) addr (getf data :new)))
(list msg scope)))
(defun forward-message (head scope &key data customer) (defun forward-message (head scope &key data customer)
(forward (message:create head :data data :customer customer) scope)) (forward (message:create head :data data :customer customer) scope))
@ -42,16 +44,17 @@
;;;; helpers ;;;; helpers
(defun register-cell (reg addr cell) (defun register-cell (reg addr cell)
(destructuring-bind (cat key) addr (destructuring-bind (dom cat key) addr
(let ((idx (getf cat reg))) (let* ((dcat (list dom cat))
(idx (gethash dcat reg)))
(unless idx (unless idx
(setf idx (index:create)) (setf idx (index:create))
(setf (getf cat reg) idx)) (setf (gethash dcat reg) idx))
(index:put idx key cell)))) (index:put idx key cell))))
(defun find-cells (reg addr) (defun find-cells (reg addr)
(destructuring-bind (cat key) addr (destructuring-bind (dom cat key) addr
(let ((idx (getf cat reg))) (let ((idx (gethash (list dom cat) reg)))
(when idx (when idx
(index:query idx key))))) (index:query idx key)))))

View file

@ -38,7 +38,7 @@
(let ((t:*test-suite* (csys:environ scope))) (let ((t:*test-suite* (csys:environ scope)))
(destructuring-bind (nmsg scope) (destructuring-bind (nmsg scope)
(csys:handle-action msg scope :actions (environ:actions)) (csys:handle-action msg scope :actions (environ:actions))
(util:lgi nmsg) (util:lgi nmsg (tc:receiver t:*test-suite*))
(actor:send (core:mailbox (tc:receiver t:*test-suite*)) nmsg)))) (actor:send (core:mailbox (tc:receiver t:*test-suite*)) nmsg))))
(defun run () (defun run ()
@ -55,13 +55,11 @@
(defun setup-test-basic-0 () (defun setup-test-basic-0 ()
(setup-config) (setup-config)
(core:setup-services) (core:setup-services)
(let* ((app (core:find-service :test-receiver)) (let* ((recv (core:find-service :test-receiver))
(env (environ:create #'proc-env app)) (env (environ:create #'proc-env t:*test-suite*)))
(msg (message:create '(:csys :create) (setf (tc:receiver t:*test-suite*) recv)
:data `(:addr (:csys :c00 "0-0")
:environ ,env))))
(setf (tc:receiver t:*test-suite*) app)
;(csys:create-zero (test-program) env) ;(csys:create-zero (test-program) env)
(csys:create-zero (csys:make-program #'csys:std-proc) env)
)) ))
(deftest test-basic-0 () (deftest test-basic-0 ()