-
Notifications
You must be signed in to change notification settings - Fork 20
/
constructors.lisp
executable file
·210 lines (171 loc) · 4.97 KB
/
constructors.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
;; -*- mode: Lisp; Syntax: Common-Lisp; Package: cells; -*-
#|
Cells -- Automatic Dataflow Managememnt
(See defpackage.lisp for license and copyright notigification)
|#
(in-package :cells)
(eval-now!
(export '(.cache-bound-p
;; Cells Constructors
c?n
c?once
c?n-until
c?1
c_1
c?+n
;; Debug Macros and Functions
c?dbg
c_?dbg
c-input-dbg
)))
;___________________ constructors _______________________________
(defmacro c-lambda (&body body)
`(c-lambda-var (slot-c) ,@body))
(defmacro c-lambda-var ((c) &body body)
`(lambda (,c &aux (self (c-model ,c))
(.cache (c-value ,c))
(.cache-bound-p (cache-bound-p ,c)))
(declare (ignorable .cache .cache-bound-p self))
,@body))
(defmacro with-c-cache ((fn) &body body)
(let ((new (gensym)))
`(or (bwhen (,new (progn ,@body))
(funcall ,fn ,new .cache))
.cache)))
;-----------------------------------------
(defmacro c? (&body body)
`(make-c-dependent
:code ',body
:value-state :unevaluated
:rule (c-lambda ,@body)))
(defmacro c?+n (&body body)
`(make-c-dependent
:inputp t
:code ',body
:value-state :unevaluated
:rule (c-lambda ,@body)))
(defmacro c?n (&body body)
`(make-c-dependent
:code '(without-c-dependency ,@body)
:inputp t
:value-state :unevaluated
:rule (c-lambda (without-c-dependency ,@body))))
(export! c?n-dbg)
(defmacro c?n-dbg (&body body)
`(make-c-dependent
:code '(without-c-dependency ,@body)
:inputp t
:debug t
:value-state :unevaluated
:rule (c-lambda (without-c-dependency ,@body))))
(defmacro c?n-until (args &body body)
`(make-c-dependent
:optimize :when-value-t
:code ',body
:inputp t
:value-state :unevaluated
:rule (c-lambda ,@body)
,@args))
(defmacro c?once (&body body)
`(make-c-dependent
:code '(without-c-dependency ,@body)
:inputp nil
:value-state :unevaluated
:rule (c-lambda (without-c-dependency ,@body))))
(defmacro c_1 (&body body)
`(make-c-dependent
:code '(without-c-dependency ,@body)
:inputp nil
:lazy t
:value-state :unevaluated
:rule (c-lambda (without-c-dependency ,@body))))
(defmacro c?1 (&body body)
`(c?once ,@body))
(defmacro c?dbg (&body body)
`(make-c-dependent
:code ',body
:value-state :unevaluated
:debug t
:rule (c-lambda ,@body)))
(defmacro c?_ (&body body)
`(make-c-dependent
:code ',body
:value-state :unevaluated
:lazy t
:rule (c-lambda ,@body)))
(defmacro c_? (&body body)
"Lazy until asked, then eagerly propagating"
`(make-c-dependent
:code ',body
:value-state :unevaluated
:lazy :until-asked
:rule (c-lambda ,@body)))
(defmacro c_?dbg (&body body)
"Lazy until asked, then eagerly propagating"
`(make-c-dependent
:code ',body
:value-state :unevaluated
:lazy :until-asked
:rule (c-lambda ,@body)
:debug t))
(defmacro c?? ((&key (tagp nil) (in nil) (out t))&body body)
(let ((result (copy-symbol 'result))
(thetag (gensym)))
`(make-c-dependent
:code ',body
:value-state :unevaluated
:rule (c-lambda
(let ((,thetag (gensym "tag"))
(*trcdepth* (1+ *trcdepth*))
)
(declare (ignorable self ,thetag))
,(when in
`(trc "c??> entry" (c-slot-name c) (c-model c) (when ,tagp ,thetag)))
(count-it :c?? (c-slot-name c) (md-name (c-model c)))
(let ((,result (progn ,@body)))
,(when out `(trc "c?? result:" ,result (c-slot-name c) (when ,tagp ,thetag)))
,result))))))
(defmacro c-formula ((&rest keys &key lazy &allow-other-keys) &body forms)
(assert (member lazy '(nil t :once-asked :until-asked :always)))
`(make-c-dependent
:code ',forms
:value-state :unevaluated
:rule (c-lambda ,@forms)
,@keys))
(defmacro c-input ((&rest keys) &optional (value nil valued-p))
`(make-cell
:inputp t
:value-state ,(if valued-p :valid :unbound)
:value ,value
,@keys))
(defmacro c-in (value)
`(make-cell
:inputp t
:value-state :valid
:value ,value))
(export! c-in-lazy c_in)
(defmacro c-in-lazy (&body body)
`(c-input (:lazy :once-asked) (progn ,@body)))
(defmacro c_in (&body body)
`(c-input (:lazy :once-asked) (progn ,@body)))
(defmacro c-input-dbg (&optional (value nil valued-p))
`(make-cell
:inputp t
:debug t
:value-state ,(if valued-p :valid :unbound)
:value ,value))
(defmacro c... ((value) &body body)
`(make-c-drifter
:code ',body
:value-state :valid
:value ,value
:rule (c-lambda ,@body)))
(defmacro c-abs (value &body body)
`(make-c-drifter-absolute
:code ',body
:value-state :valid
:value ,value
:rule (c-lambda ,@body)))
(defmacro c-envalue (&body body)
`(make-c-envaluer
:envalue-rule (c-lambda ,@body)))