Last active 1757375455

complete-generic-compiler.nv Raw Playground
1| :: get cause 1 |
2 :stack: A
3 :pattern: . a
4 . b
5 . variable c
6 . d
7 . variable e
8 :index: ( 0 1 2 3 4 )
9| :: get cause 2 |
10 :stack: A
11 :pattern: . stride
12 . test
13 :index: ( 0 1 )
14| :: get cause 3 |
15 :stack: B
16 :pattern: . other
17 . cause
18 . match
19 . variable c
20 :index: ( 0 1 2 3 )
21| :: get effect 1 |
22 :stack: out_A
23 :items: . output
24 . one
25 . variable c
26 :index: ( 0 1 2 )
27| :: get effect 2 |
28 :stack: out_B
29 :items: . output
30 . 2
31 . variable e
32 :index: ( 0 1 2 )
33
34| :: get rule 1 |
35 :causes: ( 1 2 3 )
36 :effects: ( 1 2 )
37
38| :: get cause 4 |
39 :stack: ohnoes
40 :pattern: . a
41 . second
42 . rule
43 :index: ( 0 1 2 )
44| :: get effect 3 |
45 :stack: x
46 :items: . what
47 . shall
48 . we
49 . do
50 :index: ( 0 1 2 3 )
51
52| :: get rule 2 |
53 :causes: ( 4 )
54 :effects: ( 3 )
55
56|| :rules: ( 1 2 )
57
58|------------------------------|
59|- handle incrementing -|
60|------------------------------|
61| :@math: add 0 1 | :@math: 1
62| :@math: add 1 1 | :@math: 2
63| :@math: add 2 1 | :@math: 3
64| :@math: add 3 1 | :@math: 4
65| :@math: add 4 1 | :@math: 5
66| :@math: add 5 1 | :@math: 6
67| :@math: add 6 1 | :@math: 7
68| :@math: add 7 1 | :@math: 8
69| :@math: add 8 1 | :@math: 9
70| :@math: add 9 1 | :@math: 10
71| :@math: add 10 1 | :@math: 11
72| :@math: add 11 1 | :@math: 12
73| :@math: add 12 1 | :@math: 13
74| :@math: add 13 1 | :@math: 14
75| :@math: add 14 1 | :@math: 15
76| :@math: add 1 $x | :@math: add $x 1
77|------------------------------|
78
79
80
81| :: process rule :rules: $ruleid | :processed rule: $ruleid
82 :: get rule $ruleid :current rule id: $ruleid
83 :: process causes
84 :: clear causes temp state
85 :: check stack depths
86 :: process effects
87 :: clear rule temp state
88
89| :: clear rule temp state? :stack: $stack |
90| :: clear rule temp state? :vars: variable $x = index $y of stack $z at depth $q |
91
92
93| :: clear rule temp state |
94
95
96| :: process causes? :causes: $causeid |
97 :: get cause $causeid :length: 0
98 :: check stack
99 :: process pattern
100 :: check fact lengths
101 :: pop cause
102
103
104| :: process causes |
105
106
107|:: check stack depths|
108
109| :: check fact lengths
110:stack: $stack?
111:current stride depth: $depth ?
112:length: $length |
113 :check fact lengths: check stack $stack depth $depth has length $length
114
115| :: clear causes temp state :current stride depth: $n |
116
117| :: check stack :stack: $stack?
118 | :: add stack $stack
119
120| :: pop cause
121 :stack: $stack |
122 :pop causes: pop $stack
123
124|------------------------------|
125
126| :: add stack $stack?
127 :current stride depth: $n |
128
129| :: add stack $stack :@math: $depth |
130 :current stride depth: $depth
131 :strides: check stack $stack has at least depth $depth
132 :: strides temp -> strides
133
134| :: add stack $stack? :strides: check stack $stack has at least depth $depth |
135 :@math: add $depth 1
136
137
138| :: add stack $stack? :strides: check stack $different has at least depth $depth |
139 :strides temp: check stack $different has at least depth $depth
140
141| :: add stack $stack |
142 :current stride depth: 1
143 :strides temp: check stack $stack has at least depth 1
144 :: strides temp -> strides
145
146| :: strides temp -> strides?
147 :strides temp: check stack $stack has at least depth $depth |
148 :strides: check stack $stack has at least depth $depth
149
150| :: strides temp -> strides |
151
152|------------------------------|
153
154| :: increment length :length: $old :@math: $n | :length: $n
155| :: increment length? :length: $n? | :@math: add $n 1
156
157
158|
159:: process pattern?
160:stack: $stack?
161:pattern: variable $name
162:index: $i
163:current stride depth: $depth?
164|
165 :: do variable $name at index $i of stack $stack at depth $depth
166 :: increment length
167
168|- var is already declared -|
169| :: do variable $name at index $i of stack $stack at depth $depth
170 :vars: variable $name = index $j of stack $stack2 at depth $depth2?
171|
172 :check vars: check index $i of top of stack $stack at depth $depth equals value of var $name
173 :: vars temp -> vars
174
175|# can also do this to give more information #|
176 :check vars: check index $i of top of stack $stack at depth $depth equals
177 var $name stack $stack2 depth $depth2 index $index2
178
179|- not the right var, check next -|
180| :: do variable $name at index $i of stack $stack at depth $depth?
181 :vars: variable $different = index $j of stack $stack2 at depth $depth2
182|
183 :vars temp: variable $different = index $j of stack $stack2 at depth $depth2
184
185
186|- variable isn't declared yet, so declare it -|
187| :: do variable $name at index $i of stack $stack at depth $depth |
188 :set vars: declare variable $name = index $i of stack $stack at depth $depth
189 :vars: variable $name = index $i of stack $stack at depth $depth
190 :: vars temp -> vars
191
192
193
194| :: vars temp -> vars
195 :vars temp: variable $name = index $i of stack $stack at depth $depth
196|
197 :vars: variable $name = index $i of stack $stack at depth $depth
198
199| :: vars temp -> vars |
200
201|
202:: process pattern?
203:stack: $stack?
204:pattern: $symbol
205:index: $i
206:current stride depth: $depth?
207|
208 :check facts: check stack $stack at depth $depth matches symbol $symbol at index $i
209 :: increment length
210
211| :: process pattern |
212
213|--------------------|
214
215
216| :: process effects? :effects: $effectid |
217 :: get effect $effectid
218 :: push effects start
219 :: process items
220 :: push effects end
221
222| :: process effects |
223
224| :: push effects start | :push effects: start fact to push
225| :: push effects end | :push effects: end fact to push
226
227
228|
229:: process items?
230:stack: $stack?
231:items: $symbol
232:index: $i
233|
234 :push effects: symbol $symbol
235
236|
237:: process items?
238:stack: $stack?
239:items: variable $name
240:index: $i
241|
242 :push effects: variable $name
243
244| :: process items |
245
246
247| :emit: rule header $ruleid
248 | :out: rule header $ruleid
249
250| :emit: check stack heights?
251 :strides: check stack $stack has at least depth $depth
252 | :out: check stack $stack has at least depth $depth
253| :emit: check stack heights |
254
255| :emit: check facts lengths?
256 :check fact lengths: check stack $stack depth $depth has length $length
257 | :out: check stack $stack depth $depth has length $length
258| :emit: check facts lengths |
259
260| :emit: check facts constant symbol matches?
261 :check facts: check stack $stack at depth $depth matches symbol $symbol at index $index
262 | :out: check stack $stack at depth $depth matches symbol $symbol at index $index
263| :emit: check facts constant symbol matches |
264
265| :emit: set variables?
266 :set vars: declare variable $name = index $i of stack $stack at depth $depth
267 | :out: declare variable $name = index $i of stack $stack at depth $depth
268| :emit: set variables |
269
270| :emit: check variables equality?
271 :check vars: check index $i of top of stack $stack at depth $depth equals value of var $name
272 | :out: check index $i of top of stack $stack at depth $depth equals value of var $name
273| :emit: check variables equality |
274
275| :emit: pop causes ?
276 :pop causes: $a $b
277 | :out: $a $b
278
279| :emit: pop causes |
280
281| :emit: push effects -> push effects reversed?
282 :push effects: $a $b
283 | :push effects reversed: $a $b
284
285| :emit: push effects -> push effects reversed?
286 :push effects: $a $b $c $d
287 | :push effects reversed: $a $b $c $d
288| :emit: push effects -> push effects reversed |
289
290| :emit: push effects reversed -> out?
291 :push effects reversed: $a $b $c $d
292 | :out: $a $b $c $d
293
294| :emit: push effects reversed -> out?
295 :push effects reversed: $a $b
296 | :out: $a $b
297| :emit: push effects reversed -> out |
298
299| :emit: push effects |
300 :emit: push effects -> push effects reversed
301 :emit: push effects reversed -> out
302
303| :emit: rule footer
304 | :out: spacer :out: rule footer
305
306| :: emit rule
307 :current rule id: $ruleid
308 | :: emitting rule
309 :emit:
310 . rule header $ruleid
311 . check stack heights
312 . check facts lengths
313 . check facts constant symbol matches
314 . set variables
315 . check variables equality
316 . pop causes
317 . push effects
318 . rule footer
319
320| :: emitting rule |
321
322| :: emit step function |
323 :emit:
324 . step function header
325 . try each rule
326 . step function footer
327
328| :emit: step function header | :out: step function header
329| :emit: step function footer | :out: spacer :out: step function footer
330
331| :emit: try each rule? :rules: $ruleid |
332 :out: try rule $ruleid
333| :emit: try each rule |
334
335
336|- :vim:sw=3:ts=3:et: -|
337
338
339| :: breakpoint | :@js: me.gas = 0;
340
341|://:| :: emit file header :: output
342
343||
344 :: output file header
345 :: process, emit, and output rules
346 :: processed rules -> rules
347 :: output step function
348 :: output file footer
349
350| :: output file header |
351 :out: spacer
352 :out: file header
353 :: translate :: output
354
355| :: output file footer |
356 :out: file footer
357 :out: spacer
358 :: translate :: output
359
360| :: output step function |
361 :: emit step function
362 :: translate
363 :: output
364
365| :: processed rules -> rules? :processed rule: $r | :rules: $r
366| :: processed rules -> rules |
367
368| :: process, emit, and output rules ? :rules: $n?|
369 :: process rule
370 :: emit rule
371 :: translate
372 :: output
373| :: process, emit, and output rules |
374
375
376|#===============#|
377|| '@include' lib/platforms/browser_dom.nv
378
379|| :DOM: ( <query #code-actions <@after #out or textarea id = out value = [] rows = 20 cols = 80 )
380
381| :: output :current dom element: $out? |
382 :@js: $out.value += (stacks['final out'].map(x=>x.join(' ')).toReversed().join('\n')+'\n'); delete stacks['final out'];
383
384|#===============#|
385
386| :: translate? :out: spacer |
387 :final out: []
388
389| :: translate? :out: $a | :final out: $a
390| :: translate? :out: $a $b | :final out: $a $b
391| :: translate? :out: $a $b $c | :final out: $a $b $c
392| :: translate? :out: $a $b $c $d | :final out: $a $b $c $d
393| :: translate? :out: $a $b $c $d $e | :final out: $a $b $c $d $e
394| :: translate? :out: $a $b $c $d $e $f | :final out: $a $b $c $d $e $f
395| :: translate? :out: $a $b $c $d $e $f $g | :final out: $a $b $c $d $e $f $g
396| :: translate? :out: $a $b $c $d $e $f $g $h | :final out: $a $b $c $d $e $f $g $h
397| :: translate? :out: $a $b $c $d $e $f $g $h $i | :final out: $a $b $c $d $e $f $g $h $i
398| :: translate? :out: $a $b $c $d $e $f $g $h $i $j | :final out: $a $b $c $d $e $f $g $h $i $j
399| :: translate? :out: $a $b $c $d $e $f $g $h $i $j $k | :final out: $a $b $c $d $e $f $g $h $i $j $k
400| :: translate? :out: $a $b $c $d $e $f $g $h $i $j $k $l | :final out: $a $b $c $d $e $f $g $h $i $j $k $l
401| :: translate? :out: $a $b $c $d $e $f $g $h $i $j $k $l $m | :final out: $a $b $c $d $e $f $g $h $i $j $k $l $m
402| :: translate? :out: $a $b $c $d $e $f $g $h $i $j $k $l $m $n | :final out: $a $b $c $d $e $f $g $h $i $j $k $l $m $n
403| :: translate? :out: $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o | :final out: $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o
404| :: translate? :out: $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p | :final out: $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p
405| :: translate? :out: $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q | :final out: $a $b $c $d $e $f $g $h $i $j $k $l $m $n $o $p $q
406| :: translate |
407
408
409|#========#|
410