Compare commits
No commits in common. "2d30776e815741d75fbf084fb64e7c5fa8772c58" and "8cd2b882ee0c7d9a954ea49d4c50f479ceff7843" have entirely different histories.
2d30776e81
...
8cd2b882ee
5 changed files with 18 additions and 26 deletions
|
|
@ -21,10 +21,12 @@
|
|||
|
||||
(defclass scope ()
|
||||
((value :accessor value :initarg :value :initform 0)
|
||||
;(params :accessor params :initarg :params :initform nil) ; <- program
|
||||
(categ :accessor categ :initarg :categ :initform '(:csys :c00))
|
||||
(stage :accessor stage :initarg :stage :initform :initial)
|
||||
(proc :accessor proc)
|
||||
(program :reader program :initarg :program)
|
||||
;(actions :accessor actions :initarg :actions :initform nil) ; <- program
|
||||
(syns :accessor syns :initform nil)
|
||||
(environ :reader environ :initarg :environ)))
|
||||
|
||||
|
|
@ -73,18 +75,12 @@
|
|||
(defun process (scope)
|
||||
(lambda (msg) (funcall (proc scope) msg scope)))
|
||||
|
||||
(defun std-proc (msg scope &key (default #'remember) params actions)
|
||||
(util:mv-bind (nmsg &optional (nscope scope))
|
||||
(handle-action msg scope :default default :actions actions :params params)
|
||||
(defun std-proc (msg scope)
|
||||
(destructuring-bind (nmsg nscope)
|
||||
(handle-action msg scope :default #'remember) ; + params, actions
|
||||
(forward nmsg (syns nscope))
|
||||
(update nscope)))
|
||||
|
||||
(defun eff-proc (msg scope &key params actions)
|
||||
(util:mv-bind (nmsg &optional (nscope scope))
|
||||
(handle-action msg scope :default #'no-op :actions actions :params params)
|
||||
(notify nmsg nscope)
|
||||
(update nscope)))
|
||||
|
||||
(defun create (msg scope)
|
||||
(let ((new (neuron (apply #'reset-scope scope (shape:data msg)))))
|
||||
(notify-created msg new scope)))
|
||||
|
|
@ -101,6 +97,7 @@
|
|||
|
||||
(defun handle-action (msg scope &key (default #'no-op) actions params)
|
||||
(let* ((key (message:action msg))
|
||||
;(act (gethash key (actions scope) default))
|
||||
(act (getf actions key (getf actions :default default))))
|
||||
(apply act msg scope params)))
|
||||
|
||||
|
|
@ -108,12 +105,15 @@
|
|||
(let* ((head (list (message:domain msg) :created))
|
||||
(data (util:plist-merge (shape:data msg) `(:new ,new :parent ,actor:*self*)))
|
||||
(msg1 (message:create head :data data)))
|
||||
(notify msg1 scope)))
|
||||
(notify msg1 scope))
|
||||
)
|
||||
|
||||
;;;; predefined neuron actions
|
||||
|
||||
(defun no-op (msg scope) msg)
|
||||
(defun no-op (msg scope)
|
||||
(list msg scope))
|
||||
|
||||
(defun remember (msg scope)
|
||||
(setf (value scope) (shape:data-value msg :value))
|
||||
(values msg scope))
|
||||
;(list msg (make-neuron-state (shape:data msg) syns))
|
||||
(list msg scope))
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@
|
|||
(addr (getf data :addr)))
|
||||
(when addr
|
||||
(register-cell (cells scope) addr (getf data :new)))
|
||||
msg))
|
||||
(list msg scope)))
|
||||
|
||||
(defun forward (msg scope)
|
||||
(dolist (cell (find-cells (cells scope) (message:addr msg)))
|
||||
(actor:send cell msg))
|
||||
msg)
|
||||
(list msg scope))
|
||||
|
||||
;;;; helpers
|
||||
|
||||
|
|
|
|||
|
|
@ -99,10 +99,6 @@
|
|||
(let ((pl '(:a 0)))
|
||||
(== (util:plist-add pl :b 1) '(:b 1 :a 0))
|
||||
(== pl '(:b 1 :a 0)))
|
||||
(util:mv-bind (a &optional (b :not-set) (c :not-set)) (values 42 2)
|
||||
(== a 42)
|
||||
(== b 2)
|
||||
(== c :not-set))
|
||||
(util:load-dotenv (t:test-path ".test.env"))
|
||||
(== (util:getenv "SCOPES_USER") "user-from-env-file")
|
||||
(== (util:getenv "SCOPES_PASSWORD") "very_secret"))
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
(defun proc-env (msg scope)
|
||||
(let ((t:*test-suite* (csys:environ scope)))
|
||||
(util:mv-bind (nmsg &optional (scope scope))
|
||||
(destructuring-bind (nmsg scope)
|
||||
(csys:handle-action msg scope :actions (environ:actions))
|
||||
(util:lgi nmsg (tc:receiver t:*test-suite*))
|
||||
(actor:send (core:mailbox (tc:receiver t:*test-suite*)) nmsg))))
|
||||
|
|
@ -52,18 +52,18 @@
|
|||
|
||||
;;;; test: initialization
|
||||
|
||||
(defun setup-test (prg)
|
||||
(defun setup-test-basic-0 ()
|
||||
(setup-config)
|
||||
(core:setup-services)
|
||||
(let* ((recv (core:find-service :test-receiver))
|
||||
(env (environ:create #'proc-env t:*test-suite*)))
|
||||
(setf (tc:receiver t:*test-suite*) recv)
|
||||
;(csys:create-zero (test-program) env)
|
||||
(csys:create-zero prg env)
|
||||
(csys:create-zero (csys:make-program #'csys:std-proc) env)
|
||||
env))
|
||||
|
||||
(deftest test-basic-0 ()
|
||||
(let ((env (setup-test (csys:make-program #'csys:std-proc))))
|
||||
(let ((env (setup-test-basic-0)))
|
||||
(sleep 0.1)
|
||||
(actor:send env (message:create '(:csys :value :c00 "0-0") :data '(:value 1)))
|
||||
(sleep 0.1)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
#:rfill #:rtrim
|
||||
#:loop-plist #:filter-plist #:map-plist
|
||||
#:plist-pairs #:plist-equal #:plist-add #:plist-merge
|
||||
#:mv-bind
|
||||
#:flatten-str #:from-keyword #:to-keyword #:to-integer #:to-string
|
||||
#:from-bytes #:to-bytes #:b64-decode #:b64-encode #:from-b64 #:to-b64
|
||||
#:absolute-dir #:check-dir #:ensure-dir #:home-path #:path-from-string
|
||||
|
|
@ -98,9 +97,6 @@
|
|||
(defmacro plist-add (pl k v)
|
||||
`(setf ,pl (cons ,k (cons ,v ,pl))))
|
||||
|
||||
(defmacro mv-bind (vars vform &body body)
|
||||
`(destructuring-bind ,vars (multiple-value-list ,vform) ,@body))
|
||||
|
||||
;;;; strings, symbols, keywords, ...
|
||||
|
||||
(defun flatten-str (s &key (sep " "))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue