From 85c23f10e0f7e0b6c601686e6c972cd21ee91d7f Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sun, 19 Jul 2026 21:16:16 +0200 Subject: [PATCH] environ:create, with fixes / improvemenst on csys:scope --- csys/csys.lisp | 14 ++++++++------ csys/environ.lisp | 7 ++++++- test/test-csys.lisp | 4 +--- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/csys/csys.lisp b/csys/csys.lisp index 76c2e00..581de4f 100644 --- a/csys/csys.lisp +++ b/csys/csys.lisp @@ -29,16 +29,18 @@ (syns :accessor syns :initform nil) (environ :reader environ :initarg :environ))) -(defun scope (&optional (program (make-prog #'std-proc)) &rest args) - (let ((sc (apply #'make-instance 'scope :program program args))) - (set-proc sc))) +(defun scope (program &rest args &key (cls 'scope) &allow-other-keys) + (remf args :cls) + (apply #'make-instance cls :program program args)) + +(defmethod initialize-instance :after ((sc scope) &key &allow-other-keys) + (set-proc sc)) (defun reset-scope (scope &rest args) - (let ((sc (apply #'scope (or (getf args :program) (program scope)) + (apply #'scope (or (getf args :program) (program scope)) :categ (getf args :categ (categ scope)) :environ (getf args :environ (environ scope)) - args))) - (set-proc sc))) + args)) (defun set-proc (scope) (setf (proc scope) (funcall (program scope) scope)) diff --git a/csys/environ.lisp b/csys/environ.lisp index 3495a9e..4801ef1 100644 --- a/csys/environ.lisp +++ b/csys/environ.lisp @@ -7,7 +7,8 @@ (:index :scopes/util/index) (:message :scopes/core/message) (:shape :scopes/shape)) - (:export #:actions + (:export #:create + #:actions #:forward)) (in-package :scopes/csys/environ) @@ -15,6 +16,10 @@ (defclass scope (csys:scope) ((cells :reader cells :initform (make-hash-table :test #'equal)))) +(defun create (proc app) + (let ((prog (csys:make-prog proc))) + (csys:neuron (csys:scope prog :cls 'scope :environ app)))) + ;;;; action handlers, public callables (defun actions () diff --git a/test/test-csys.lisp b/test/test-csys.lisp index 08fe447..da61202 100644 --- a/test/test-csys.lisp +++ b/test/test-csys.lisp @@ -57,9 +57,7 @@ (core:setup-services) (setf (tc:receiver t:*test-suite*) (core:find-service :test-receiver)) ;(csys:add-action '(:csys :sensor) #'csys:create-sensor) - (let* ((prog (csys:make-prog #'proc-env)) - (env (csys:neuron (csys:scope prog - :environ (tc:receiver t:*test-suite*)))) + (let* ((env (environ:create #'proc-env (tc:receiver t:*test-suite*))) (msg (message:create '(:csys :create) :data `(:addr (:csys :c00 "0-0") :categ :c00