csys: scope creation: fixes and improvements

This commit is contained in:
Helmut Merz 2026-07-20 10:50:08 +02:00
parent 85c23f10e0
commit 7c78f1df2f
2 changed files with 12 additions and 11 deletions

View file

@ -9,7 +9,7 @@
(:util :scopes/util) (:util :scopes/util)
(:alx :alexandria)) (:alx :alexandria))
(:export #:scope #:environ (:export #:scope #:environ
#:make-prog #:make-program
#:neuron #:std-proc #:create #:neuron #:std-proc #:create
#:handle-action #:handle-action
#:notify)) #:notify))
@ -22,31 +22,32 @@
((value :accessor value :initarg :value :initform 0) ((value :accessor value :initarg :value :initform 0)
;(params :accessor params :initarg :params :initform nil) ; <- program ;(params :accessor params :initarg :params :initform nil) ; <- program
(categ :accessor categ :initarg :categ :initform '(:csys :c00)) (categ :accessor categ :initarg :categ :initform '(:csys :c00))
(stage :accessor stage :initform :initial) (stage :accessor stage :initarg :stage :initform :initial)
(proc :accessor proc :initarg :proc :initform #'std-proc) (proc :accessor proc)
(program :reader program :initarg :program :initform nil) (program :reader program :initarg :program)
;(actions :accessor actions :initarg :actions :initform nil) ; <- program ;(actions :accessor actions :initarg :actions :initform nil) ; <- program
(syns :accessor syns :initform nil) (syns :accessor syns :initform nil)
(environ :reader environ :initarg :environ))) (environ :reader environ :initarg :environ)))
(defun scope (program &rest args &key (cls 'scope) &allow-other-keys) (defun scope (prg env &rest args &key (cls 'scope) &allow-other-keys)
(remf args :cls) (remf args :cls)
(apply #'make-instance cls :program program 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 (scope &rest args)
(apply #'scope (or (getf args :program) (program scope)) (apply #'scope
(getf args :program) (program scope)
(getf args :environ (environ scope))
:categ (getf args :categ (categ scope)) :categ (getf args :categ (categ scope))
:environ (getf args :environ (environ scope))
args)) args))
(defun set-proc (scope) (defun set-proc (scope)
(setf (proc scope) (funcall (program scope) scope)) (setf (proc scope) (funcall (program scope) scope))
scope) scope)
(defgeneric make-prog (spec) (defgeneric make-program (spec)
(:method ((fn function)) (lambda (scope) fn))) (:method ((fn function)) (lambda (scope) fn)))
;;;; neurons (= async tasks) and synapses (= connections) ;;;; neurons (= async tasks) and synapses (= connections)

View file

@ -17,8 +17,8 @@
((cells :reader cells :initform (make-hash-table :test #'equal)))) ((cells :reader cells :initform (make-hash-table :test #'equal))))
(defun create (proc app) (defun create (proc app)
(let ((prog (csys:make-prog proc))) (let ((prog (csys:make-program proc)))
(csys:neuron (csys:scope prog :cls 'scope :environ app)))) (csys:neuron (csys:scope prog app :cls 'scope :categ '(:env :c00)))))
;;;; action handlers, public callables ;;;; action handlers, public callables