forked from kennytilton/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynapse.lisp
executable file
·80 lines (62 loc) · 2.39 KB
/
synapse.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;; -*- mode: Lisp; Syntax: Common-Lisp; Package: cells; -*-
#|
Cells -- Automatic Dataflow Managememnt
(See defpackage.lisp for license and copyright notigification)
|#
(in-package :cells)
(eval-when (:compile-toplevel :load-toplevel :execute)
(export '(mk-synapse f-delta f-sensitivity f-plusp f-zerop fdifferent with-synapse)))
(defmacro with-synapse (synapse-id (&rest closure-vars) &body body)
(let ((syn-id (gensym)))
`(let* ((,syn-id ,synapse-id)
(synapse (or (find ,syn-id (cd-useds *depender*) :key 'c-slot-name)
(let ((new-syn
(let (,@closure-vars)
(make-c-dependent
:model (c-model *depender*)
:slot-name ,syn-id
:code ',body
:synaptic t
:rule (c-lambda ,@body)))))
(record-caller new-syn)
new-syn))))
(prog1
(multiple-value-bind (v p)
(with-integrity ()
(ensure-value-is-current synapse :synapse *depender*))
(values v p))
(record-caller synapse)))))
;__________________________________________________________________________________
;
(defmethod delta-exceeds (bool-delta sensitivity (subtypename (eql 'boolean)))
(unless (eql bool-delta :unchanged)
(or (eq sensitivity t)
(eq sensitivity bool-delta))))
(defmethod delta-diff ((new number) (old number) subtypename)
(declare (ignore subtypename))
(- new old))
(defmethod delta-identity ((dispatcher number) subtypename)
(declare (ignore subtypename))
0)
(defmethod delta-abs ((n number) subtypename)
(declare (ignore subtypename))
(abs n))
(defmethod delta-exceeds ((d1 number) (d2 number) subtypename)
(declare (ignore subtypename))
(> d1 d2))
(defmethod delta-greater-or-equal ((d1 number) (d2 number) subtypename)
(declare (ignore subtypename))
(>= d1 d2))
;_________________________________________________________________________________
;
(defmethod delta-diff (new old (subtypename (eql 'boolean)))
(if new
(if old
:unchanged
:on)
(if old
:off
:unchanged)))
(defmethod delta-identity (dispatcher (subtypename (eql 'boolean)))
(declare (ignore dispatcher))
:unchanged)