aboutsummaryrefslogtreecommitdiff
path: root/luxc/src/lux/analyser/proc/common.clj
blob: 0c38132a4e88b749b6c0b3eed375f321931ecabf (plain)
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
(ns lux.analyser.proc.common
  (:require (clojure [template :refer [do-template]])
            clojure.core.match
            clojure.core.match.array
            (lux [base :as & :refer [|let |do return* return |case assert!]]
                 [type :as &type])
            (lux.analyser [base :as &&])))

(defn ^:private analyse-lux-is [analyse exo-type ?values]
  (&type/with-var
    (fn [$var]
      (|do [:let [(&/$Cons left (&/$Cons right (&/$Nil))) ?values]
            =left (&&/analyse-1 analyse $var left)
            =right (&&/analyse-1 analyse $var right)
            _ (&type/check exo-type &type/Bool)
            _cursor &/cursor]
        (return (&/|list (&&/|meta exo-type _cursor
                                   (&&/$proc (&/T ["lux" "is"]) (&/|list =left =right) (&/|list)))))))))

(defn ^:private analyse-lux-try [analyse exo-type ?values]
  (&type/with-var
    (fn [$var]
      (|do [:let [(&/$Cons op (&/$Nil)) ?values]
            =op (&&/analyse-1 analyse (&/$Apply $var &type/IO) op)
            _ (&type/check exo-type (&/$Sum &type/Text ;; lux;Left
                                            $var ;; lux;Right
                                            ))
            _cursor &/cursor]
        (return (&/|list (&&/|meta exo-type _cursor
                                   (&&/$proc (&/T ["lux" "try"]) (&/|list =op) (&/|list)))))))))

(do-template [<name> <proc> <input-type> <output-type>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons x (&/$Cons y (&/$Nil))) ?values]
          =x (&&/analyse-1 analyse <input-type> x)
          =y (&&/analyse-1 analyse <input-type> y)
          _ (&type/check exo-type <output-type>)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T <proc>) (&/|list =x =y) (&/|list)))))))

  ^:private analyse-text-eq     ["text" "="]      &type/Text &type/Bool
  ^:private analyse-text-lt     ["text" "<"]      &type/Text &type/Bool
  ^:private analyse-text-concat ["text" "concat"] &type/Text &type/Text
  )

(do-template [<name> <proc-name> <output-type>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons text (&/$Cons part (&/$Cons start (&/$Nil)))) ?values]
          =text (&&/analyse-1 analyse &type/Text text)
          =part (&&/analyse-1 analyse &type/Text part)
          =start (&&/analyse-1 analyse &type/Nat start)
          _ (&type/check exo-type <output-type>)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T ["text" <proc-name>])
                                           (&/|list =text =part =start)
                                           (&/|list)))))))

  ^:private analyse-text-index      "index"      (&/$Apply &type/Nat &type/Maybe)
  )

(defn ^:private analyse-text-contains? [analyse exo-type ?values]
  (|do [:let [(&/$Cons text (&/$Cons part (&/$Nil))) ?values]
        =text (&&/analyse-1 analyse &type/Text text)
        =part (&&/analyse-1 analyse &type/Text part)
        _ (&type/check exo-type &type/Bool)
        _cursor &/cursor]
    (return (&/|list (&&/|meta exo-type _cursor
                               (&&/$proc (&/T ["text" "contains?"])
                                         (&/|list =text =part)
                                         (&/|list)))))))

(defn ^:private analyse-text-clip [analyse exo-type ?values]
  (|do [:let [(&/$Cons text (&/$Cons from (&/$Cons to (&/$Nil)))) ?values]
        =text (&&/analyse-1 analyse &type/Text text)
        =from (&&/analyse-1 analyse &type/Nat from)
        =to (&&/analyse-1 analyse &type/Nat to)
        _ (&type/check exo-type (&/$Apply &type/Text &type/Maybe))
        _cursor &/cursor]
    (return (&/|list (&&/|meta exo-type _cursor
                               (&&/$proc (&/T ["text" "clip"])
                                         (&/|list =text =from =to)
                                         (&/|list)))))))

(defn ^:private analyse-text-replace-all [analyse exo-type ?values]
  (|do [:let [(&/$Cons text (&/$Cons to-find (&/$Cons replace-with (&/$Nil)))) ?values]
        =text (&&/analyse-1 analyse &type/Text text)
        =to-find (&&/analyse-1 analyse &type/Text to-find)
        =replace-with (&&/analyse-1 analyse &type/Text replace-with)
        _ (&type/check exo-type &type/Text)
        _cursor &/cursor]
    (return (&/|list (&&/|meta exo-type _cursor
                               (&&/$proc (&/T ["text" "replace-all"])
                                         (&/|list =text =to-find =replace-with)
                                         (&/|list)))))))

(do-template [<name> <proc>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons text (&/$Nil)) ?values]
          =text (&&/analyse-1 analyse &type/Text text)
          _ (&type/check exo-type &type/Nat)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T ["text" <proc>])
                                           (&/|list =text)
                                           (&/|list)))))))

  ^:private analyse-text-size "size"
  ^:private analyse-text-hash "hash"
  )

(do-template [<name> <proc>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons text (&/$Nil)) ?values]
          =text (&&/analyse-1 analyse &type/Text text)
          _ (&type/check exo-type &type/Text)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T ["text" <proc>])
                                           (&/|list =text)
                                           (&/|list)))))))

  ^:private analyse-text-upper-case "upper-case"
  ^:private analyse-text-lower-case "lower-case"
  )

(defn ^:private analyse-text-char [analyse exo-type ?values]
  (|do [:let [(&/$Cons text (&/$Cons idx (&/$Nil))) ?values]
        =text (&&/analyse-1 analyse &type/Text text)
        =idx (&&/analyse-1 analyse &type/Nat idx)
        _ (&type/check exo-type (&/$Apply &type/Nat &type/Maybe))
        _cursor &/cursor]
    (return (&/|list (&&/|meta exo-type _cursor
                               (&&/$proc (&/T ["text" "char"])
                                         (&/|list =text =idx)
                                         (&/|list)))))))

(do-template [<name> <op>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons input (&/$Cons mask (&/$Nil))) ?values]
          =mask (&&/analyse-1 analyse &type/Nat mask)
          =input (&&/analyse-1 analyse &type/Nat input)
          _ (&type/check exo-type &type/Nat)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T ["bit" <op>]) (&/|list =input =mask) (&/|list)))))))

  ^:private analyse-bit-and "and"
  ^:private analyse-bit-or  "or"
  ^:private analyse-bit-xor "xor"
  )

(defn ^:private analyse-bit-count [analyse exo-type ?values]
  (|do [:let [(&/$Cons input (&/$Nil)) ?values]
        =input (&&/analyse-1 analyse &type/Nat input)
        _ (&type/check exo-type &type/Nat)
        _cursor &/cursor]
    (return (&/|list (&&/|meta exo-type _cursor
                               (&&/$proc (&/T ["bit" "count"]) (&/|list =input) (&/|list)))))))

(do-template [<name> <op> <type>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons input (&/$Cons shift (&/$Nil))) ?values]
          =shift (&&/analyse-1 analyse &type/Nat shift)
          =input (&&/analyse-1 analyse <type> input)
          _ (&type/check exo-type <type>)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T ["bit" <op>]) (&/|list =input =shift) (&/|list)))))))

  ^:private analyse-bit-shift-left           "shift-left"           &type/Nat
  ^:private analyse-bit-shift-right          "shift-right"          &type/Int
  ^:private analyse-bit-unsigned-shift-right "unsigned-shift-right" &type/Nat
  )

(do-template [<name> <proc> <input-type> <output-type>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons x (&/$Cons y (&/$Nil))) ?values]
          =x (&&/analyse-1 analyse <input-type> x)
          =y (&&/analyse-1 analyse <input-type> y)
          _ (&type/check exo-type <output-type>)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T <proc>) (&/|list =x =y) (&/|list)))))))

  ^:private analyse-nat-add  ["nat" "+"]  &type/Nat  &type/Nat
  ^:private analyse-nat-sub  ["nat" "-"]  &type/Nat  &type/Nat
  ^:private analyse-nat-mul  ["nat" "*"]  &type/Nat  &type/Nat
  ^:private analyse-nat-div  ["nat" "/"]  &type/Nat  &type/Nat
  ^:private analyse-nat-rem  ["nat" "%"]  &type/Nat  &type/Nat
  ^:private analyse-nat-eq   ["nat" "="]  &type/Nat  &type/Bool
  ^:private analyse-nat-lt   ["nat" "<"]  &type/Nat  &type/Bool

  ^:private analyse-int-add  ["int" "+"]  &type/Int  &type/Int
  ^:private analyse-int-sub  ["int" "-"]  &type/Int  &type/Int
  ^:private analyse-int-mul  ["int" "*"]  &type/Int  &type/Int
  ^:private analyse-int-div  ["int" "/"]  &type/Int  &type/Int
  ^:private analyse-int-rem  ["int" "%"]  &type/Int  &type/Int
  ^:private analyse-int-eq   ["int" "="]  &type/Int  &type/Bool
  ^:private analyse-int-lt   ["int" "<"]  &type/Int  &type/Bool

  ^:private analyse-deg-add  ["deg" "+"]  &type/Deg  &type/Deg
  ^:private analyse-deg-sub  ["deg" "-"]  &type/Deg  &type/Deg
  ^:private analyse-deg-mul  ["deg" "*"]  &type/Deg  &type/Deg
  ^:private analyse-deg-div  ["deg" "/"]  &type/Deg  &type/Deg
  ^:private analyse-deg-rem  ["deg" "%"]  &type/Deg  &type/Deg
  ^:private analyse-deg-eq   ["deg" "="]  &type/Deg  &type/Bool
  ^:private analyse-deg-lt   ["deg" "<"]  &type/Deg  &type/Bool

  ^:private analyse-frac-add ["frac" "+"] &type/Frac &type/Frac
  ^:private analyse-frac-sub ["frac" "-"] &type/Frac &type/Frac
  ^:private analyse-frac-mul ["frac" "*"] &type/Frac &type/Frac
  ^:private analyse-frac-div ["frac" "/"] &type/Frac &type/Frac
  ^:private analyse-frac-rem ["frac" "%"] &type/Frac &type/Frac
  ^:private analyse-frac-eq  ["frac" "="] &type/Frac &type/Bool
  ^:private analyse-frac-lt  ["frac" "<"] &type/Frac &type/Bool
  )

(do-template [<name> <proc>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons x (&/$Cons y (&/$Nil))) ?values]
          =x (&&/analyse-1 analyse &type/Deg x)
          =y (&&/analyse-1 analyse &type/Nat y)
          _ (&type/check exo-type &type/Deg)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T <proc>) (&/|list =x =y) (&/|list)))))))

  ^:private analyse-deg-scale      ["deg" "scale"]
  ^:private analyse-deg-reciprocal ["deg" "reciprocal"]
  )

(do-template [<encode> <encode-op> <decode> <decode-op> <type>]
  (do (defn <encode> [analyse exo-type ?values]
        (|do [:let [(&/$Cons x (&/$Nil)) ?values]
              =x (&&/analyse-1 analyse <type> x)
              _ (&type/check exo-type &type/Text)
              _cursor &/cursor]
          (return (&/|list (&&/|meta exo-type _cursor
                                     (&&/$proc (&/T <encode-op>) (&/|list =x) (&/|list)))))))

    (let [decode-type (&/$Apply <type> &type/Maybe)]
      (defn <decode> [analyse exo-type ?values]
        (|do [:let [(&/$Cons x (&/$Nil)) ?values]
              =x (&&/analyse-1 analyse &type/Text x)
              _ (&type/check exo-type decode-type)
              _cursor &/cursor]
          (return (&/|list (&&/|meta exo-type _cursor
                                     (&&/$proc (&/T <decode-op>) (&/|list =x) (&/|list)))))))))

  ^:private analyse-frac-encode ["frac" "encode"] ^:private analyse-frac-decode ["frac" "decode"] &type/Frac
  )

(do-template [<name> <type> <op>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Nil) ?values]
          _ (&type/check exo-type <type>)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T <op>) (&/|list) (&/|list)))))))

  ^:private analyse-nat-min-value            &type/Nat  ["nat"  "min-value"]
  ^:private analyse-nat-max-value            &type/Nat  ["nat"  "max-value"]

  ^:private analyse-int-min-value            &type/Int  ["int"  "min-value"]
  ^:private analyse-int-max-value            &type/Int  ["int"  "max-value"]

  ^:private analyse-deg-min-value           &type/Deg ["deg" "min-value"]
  ^:private analyse-deg-max-value           &type/Deg ["deg" "max-value"]

  ^:private analyse-frac-smallest-value     &type/Frac  ["frac"  "smallest-value"]
  ^:private analyse-frac-min-value          &type/Frac  ["frac"  "min-value"]
  ^:private analyse-frac-max-value          &type/Frac  ["frac"  "max-value"]
  ^:private analyse-frac-not-a-number       &type/Frac  ["frac"  "not-a-number"]
  ^:private analyse-frac-positive-infinity  &type/Frac  ["frac"  "positive-infinity"]
  ^:private analyse-frac-negative-infinity  &type/Frac  ["frac"  "negative-infinity"]
  )

(do-template [<name> <from-type> <to-type> <op>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons x (&/$Nil)) ?values]
          =x (&&/analyse-1 analyse <from-type> x)
          _ (&type/check exo-type <to-type>)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T <op>) (&/|list =x) (&/|list)))))))

  ^:private analyse-nat-to-int   &type/Nat  &type/Int    ["nat" "to-int"]
  ^:private analyse-int-to-nat   &type/Int  &type/Nat    ["int" "to-nat"]
  
  ^:private analyse-nat-to-char  &type/Nat  &type/Text   ["nat" "to-char"]
  
  ^:private analyse-int-to-frac  &type/Int  &type/Frac   ["int" "to-frac"]
  ^:private analyse-frac-to-int  &type/Frac &type/Int    ["frac" "to-int"]

  ^:private analyse-deg-to-frac  &type/Deg  &type/Frac   ["deg" "to-frac"]
  ^:private analyse-frac-to-deg  &type/Frac &type/Deg    ["frac" "to-deg"]
  
  ^:private analyse-io-log       &type/Text &/$Unit     ["io" "log"]
  ^:private analyse-io-error     &type/Text &type/Bottom ["io" "error"]
  ^:private analyse-io-exit      &type/Int  &type/Bottom ["io" "exit"]
  )

(defn ^:private analyse-io-current-time [analyse exo-type ?values]
  (|do [:let [(&/$Nil) ?values]
        _ (&type/check exo-type &type/Int)
        _cursor &/cursor]
    (return (&/|list (&&/|meta exo-type _cursor
                               (&&/$proc (&/T ["io" "current-time"]) (&/|list) (&/|list)))))))

(defn ^:private analyse-array-new [analyse exo-type ?values]
  (|do [:let [(&/$Cons length (&/$Nil)) ?values]
        =length (&&/analyse-1 analyse &type/Nat length)
        _ (&type/check exo-type (&/$UnivQ (&/|list) (&type/Array (&/$Bound 1))))
        _cursor &/cursor]
    (return (&/|list (&&/|meta exo-type _cursor
                               (&&/$proc (&/T ["array" "new"]) (&/|list =length) (&/|list)))))))

(defn ^:private analyse-array-get [analyse exo-type ?values]
  (&type/with-var
    (fn [$var]
      (|do [:let [(&/$Cons array (&/$Cons idx (&/$Nil))) ?values]
            =array (&&/analyse-1 analyse (&type/Array $var) array)
            =idx (&&/analyse-1 analyse &type/Nat idx)
            _ (&type/check exo-type (&/$Apply $var &type/Maybe))
            _cursor &/cursor]
        (return (&/|list (&&/|meta exo-type _cursor
                                   (&&/$proc (&/T ["array" "get"]) (&/|list =array =idx) (&/|list)))))))))

(defn ^:private analyse-array-put [analyse exo-type ?values]
  (&type/with-var
    (fn [$var]
      (|do [:let [(&/$Cons array (&/$Cons idx (&/$Cons elem (&/$Nil)))) ?values]
            :let [array-type (&type/Array $var)]
            =array (&&/analyse-1 analyse array-type array)
            =idx (&&/analyse-1 analyse &type/Nat idx)
            =elem (&&/analyse-1 analyse $var elem)
            _ (&type/check exo-type array-type)
            _cursor &/cursor]
        (return (&/|list (&&/|meta exo-type _cursor
                                   (&&/$proc (&/T ["array" "put"]) (&/|list =array =idx =elem) (&/|list)))))))))

(defn ^:private analyse-array-remove [analyse exo-type ?values]
  (&type/with-var
    (fn [$var]
      (|do [:let [(&/$Cons array (&/$Cons idx (&/$Nil))) ?values]
            :let [array-type (&type/Array $var)]
            =array (&&/analyse-1 analyse array-type array)
            =idx (&&/analyse-1 analyse &type/Nat idx)
            _ (&type/check exo-type array-type)
            _cursor &/cursor]
        (return (&/|list (&&/|meta exo-type _cursor
                                   (&&/$proc (&/T ["array" "remove"]) (&/|list =array =idx) (&/|list)))))))))

(defn ^:private analyse-array-size [analyse exo-type ?values]
  (&type/with-var
    (fn [$var]
      (|do [:let [(&/$Cons array (&/$Nil)) ?values]
            =array (&&/analyse-1 analyse (&type/Array $var) array)
            _ (&type/check exo-type &type/Nat)
            _cursor &/cursor]
        (return (&/|list (&&/|meta exo-type _cursor
                                   (&&/$proc (&/T ["array" "size"]) (&/|list =array) (&/|list)))))))))

(do-template [<name> <proc>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Nil) ?values]
          _ (&type/check exo-type &type/Frac)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T ["math" <proc>]) (&/|list) (&/|list)))))))

  ^:private analyse-math-e  "e"
  ^:private analyse-math-pi "pi"
  )

(do-template [<name> <proc>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons ?input (&/$Nil)) ?values]
          =input (&&/analyse-1 analyse &type/Frac ?input)
          _ (&type/check exo-type &type/Frac)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T ["math" <proc>]) (&/|list =input) (&/|list)))))))

  ^:private analyse-math-cos "cos"
  ^:private analyse-math-sin "sin"
  ^:private analyse-math-tan "tan"
  ^:private analyse-math-acos "acos"
  ^:private analyse-math-asin "asin"
  ^:private analyse-math-atan "atan"
  ^:private analyse-math-cosh "cosh"
  ^:private analyse-math-sinh "sinh"
  ^:private analyse-math-tanh "tanh"
  ^:private analyse-math-exp "exp"
  ^:private analyse-math-log "log"
  ^:private analyse-math-root2 "root2"
  ^:private analyse-math-root3 "root3"
  ^:private analyse-math-ceil "ceil"
  ^:private analyse-math-floor "floor"
  ^:private analyse-math-round "round"
  )

(do-template [<name> <proc>]
  (defn <name> [analyse exo-type ?values]
    (|do [:let [(&/$Cons ?input (&/$Cons ?param (&/$Nil))) ?values]
          =input (&&/analyse-1 analyse &type/Frac ?input)
          =param (&&/analyse-1 analyse &type/Frac ?param)
          _ (&type/check exo-type &type/Frac)
          _cursor &/cursor]
      (return (&/|list (&&/|meta exo-type _cursor
                                 (&&/$proc (&/T ["math" <proc>]) (&/|list =input =param) (&/|list)))))))

  ^:private analyse-math-atan2 "atan2"
  ^:private analyse-math-pow "pow"
  )

(defn ^:private analyse-atom-new [analyse exo-type ?values]
  (&type/with-var
    (fn [$var]
      (|do [:let [(&/$Cons ?init (&/$Nil)) ?values]
            =init (&&/analyse-1 analyse $var ?init)
            _ (&type/check exo-type (&type/Atom $var))
            _cursor &/cursor]
        (return (&/|list (&&/|meta exo-type _cursor
                                   (&&/$proc (&/T ["atom" "new"]) (&/|list =init) (&/|list)))))))))

(defn ^:private analyse-atom-get [analyse exo-type ?values]
  (&type/with-var
    (fn [$var]
      (|do [:let [(&/$Cons ?atom (&/$Nil)) ?values]
            =atom (&&/analyse-1 analyse (&type/Atom $var) ?atom)
            _ (&type/check exo-type $var)
            _cursor &/cursor]
        (return (&/|list (&&/|meta exo-type _cursor
                                   (&&/$proc (&/T ["atom" "get"]) (&/|list =atom) (&/|list)))))))))

(defn ^:private analyse-atom-compare-and-swap [analyse exo-type ?values]
  (&type/with-var
    (fn [$var]
      (|do [:let [(&/$Cons ?atom (&/$Cons ?old (&/$Cons ?new (&/$Nil)))) ?values]
            =atom (&&/analyse-1 analyse (&type/Atom $var) ?atom)
            =old (&&/analyse-1 analyse $var ?old)
            =new (&&/analyse-1 analyse $var ?new)
            _ (&type/check exo-type &type/Bool)
            _cursor &/cursor]
        (return (&/|list (&&/|meta exo-type _cursor
                                   (&&/$proc (&/T ["atom" "compare-and-swap"]) (&/|list =atom =old =new) (&/|list)))))))))

(defn ^:private analyse-process-concurrency-level [analyse exo-type ?values]
  (|do [:let [(&/$Nil) ?values]
        _ (&type/check exo-type &type/Nat)
        _cursor &/cursor]
    (return (&/|list (&&/|meta exo-type _cursor
                               (&&/$proc (&/T ["process" "concurrency-level"]) (&/|list) (&/|list)))))))

(defn ^:private analyse-process-future [analyse exo-type ?values]
  (|do [:let [(&/$Cons ?procedure (&/$Nil)) ?values]
        =procedure (&&/analyse-1 analyse (&/$Apply &type/Top &type/IO) ?procedure)
        _ (&type/check exo-type &/$Unit)
        _cursor &/cursor]
    (return (&/|list (&&/|meta exo-type _cursor
                               (&&/$proc (&/T ["process" "future"]) (&/|list =procedure) (&/|list)))))))

(defn ^:private analyse-process-schedule [analyse exo-type ?values]
  (|do [:let [(&/$Cons ?milliseconds (&/$Cons ?procedure (&/$Nil))) ?values]
        =milliseconds (&&/analyse-1 analyse &type/Nat ?milliseconds)
        =procedure (&&/analyse-1 analyse (&/$Apply &type/Top &type/IO) ?procedure)
        _ (&type/check exo-type &/$Unit)
        _cursor &/cursor]
    (return (&/|list (&&/|meta exo-type _cursor
                               (&&/$proc (&/T ["process" "schedule"]) (&/|list =milliseconds =procedure) (&/|list)))))))

(defn analyse-proc [analyse exo-type proc ?values]
  (try (case proc
         "lux is"                   (analyse-lux-is analyse exo-type ?values)
         "lux try"                  (analyse-lux-try analyse exo-type ?values)

         "lux io log"                  (analyse-io-log analyse exo-type ?values)
         "lux io error"                (analyse-io-error analyse exo-type ?values)
         "lux io exit"                 (analyse-io-exit analyse exo-type ?values)
         "lux io current-time"         (analyse-io-current-time analyse exo-type ?values)
         
         "lux text ="                    (analyse-text-eq analyse exo-type ?values)
         "lux text <"                    (analyse-text-lt analyse exo-type ?values)
         "lux text concat"               (analyse-text-concat analyse exo-type ?values)
         "lux text clip"                 (analyse-text-clip analyse exo-type ?values)
         "lux text index"                (analyse-text-index analyse exo-type ?values)
         "lux text size"                 (analyse-text-size analyse exo-type ?values)
         "lux text hash"                 (analyse-text-hash analyse exo-type ?values)
         "lux text replace-all"          (analyse-text-replace-all analyse exo-type ?values)
         "lux text char"                 (analyse-text-char analyse exo-type ?values)
         "lux text upper-case"           (analyse-text-upper-case analyse exo-type ?values)
         "lux text lower-case"           (analyse-text-lower-case analyse exo-type ?values)
         "lux text contains?"            (analyse-text-contains? analyse exo-type ?values)
         
         "lux bit count"                (analyse-bit-count analyse exo-type ?values)
         "lux bit and"                  (analyse-bit-and analyse exo-type ?values)
         "lux bit or"                   (analyse-bit-or analyse exo-type ?values)
         "lux bit xor"                  (analyse-bit-xor analyse exo-type ?values)
         "lux bit shift-left"           (analyse-bit-shift-left analyse exo-type ?values)
         "lux bit shift-right"          (analyse-bit-shift-right analyse exo-type ?values)
         "lux bit unsigned-shift-right" (analyse-bit-unsigned-shift-right analyse exo-type ?values)
         
         "lux array new"    (analyse-array-new analyse exo-type ?values)
         "lux array get"    (analyse-array-get analyse exo-type ?values)
         "lux array put"    (analyse-array-put analyse exo-type ?values)
         "lux array remove" (analyse-array-remove analyse exo-type ?values)
         "lux array size"   (analyse-array-size analyse exo-type ?values)

         "lux nat +" (analyse-nat-add analyse exo-type ?values)
         "lux nat -" (analyse-nat-sub analyse exo-type ?values)
         "lux nat *" (analyse-nat-mul analyse exo-type ?values)
         "lux nat /" (analyse-nat-div analyse exo-type ?values)
         "lux nat %" (analyse-nat-rem analyse exo-type ?values)
         "lux nat =" (analyse-nat-eq analyse exo-type ?values)
         "lux nat <" (analyse-nat-lt analyse exo-type ?values)
         "lux nat min-value" (analyse-nat-min-value analyse exo-type ?values)
         "lux nat max-value" (analyse-nat-max-value analyse exo-type ?values)
         "lux nat to-int" (analyse-nat-to-int analyse exo-type ?values)
         "lux nat to-char" (analyse-nat-to-char analyse exo-type ?values)
         
         "lux int +" (analyse-int-add analyse exo-type ?values)
         "lux int -" (analyse-int-sub analyse exo-type ?values)
         "lux int *" (analyse-int-mul analyse exo-type ?values)
         "lux int /" (analyse-int-div analyse exo-type ?values)
         "lux int %" (analyse-int-rem analyse exo-type ?values)
         "lux int =" (analyse-int-eq analyse exo-type ?values)
         "lux int <" (analyse-int-lt analyse exo-type ?values)
         "lux int min-value" (analyse-int-min-value analyse exo-type ?values)
         "lux int max-value" (analyse-int-max-value analyse exo-type ?values)
         "lux int to-nat" (analyse-int-to-nat analyse exo-type ?values)
         "lux int to-frac" (analyse-int-to-frac analyse exo-type ?values)
         
         "lux deg +" (analyse-deg-add analyse exo-type ?values)
         "lux deg -" (analyse-deg-sub analyse exo-type ?values)
         "lux deg *" (analyse-deg-mul analyse exo-type ?values)
         "lux deg /" (analyse-deg-div analyse exo-type ?values)
         "lux deg %" (analyse-deg-rem analyse exo-type ?values)
         "lux deg =" (analyse-deg-eq analyse exo-type ?values)
         "lux deg <" (analyse-deg-lt analyse exo-type ?values)
         "lux deg min-value" (analyse-deg-min-value analyse exo-type ?values)
         "lux deg max-value" (analyse-deg-max-value analyse exo-type ?values)
         "lux deg to-frac" (analyse-deg-to-frac analyse exo-type ?values)
         "lux deg scale" (analyse-deg-scale analyse exo-type ?values)
         "lux deg reciprocal" (analyse-deg-reciprocal analyse exo-type ?values)
         
         "lux frac +" (analyse-frac-add analyse exo-type ?values)
         "lux frac -" (analyse-frac-sub analyse exo-type ?values)
         "lux frac *" (analyse-frac-mul analyse exo-type ?values)
         "lux frac /" (analyse-frac-div analyse exo-type ?values)
         "lux frac %" (analyse-frac-rem analyse exo-type ?values)
         "lux frac =" (analyse-frac-eq analyse exo-type ?values)
         "lux frac <" (analyse-frac-lt analyse exo-type ?values)
         "lux frac encode" (analyse-frac-encode analyse exo-type ?values)
         "lux frac decode" (analyse-frac-decode analyse exo-type ?values)
         "lux frac smallest-value" (analyse-frac-smallest-value analyse exo-type ?values)
         "lux frac min-value" (analyse-frac-min-value analyse exo-type ?values)
         "lux frac max-value" (analyse-frac-max-value analyse exo-type ?values)
         "lux frac not-a-number" (analyse-frac-not-a-number analyse exo-type ?values)
         "lux frac positive-infinity" (analyse-frac-positive-infinity analyse exo-type ?values)
         "lux frac negative-infinity" (analyse-frac-negative-infinity analyse exo-type ?values)
         "lux frac to-deg" (analyse-frac-to-deg analyse exo-type ?values)
         "lux frac to-int" (analyse-frac-to-int analyse exo-type ?values)
         
         "lux math e" (analyse-math-e analyse exo-type ?values)
         "lux math pi" (analyse-math-pi analyse exo-type ?values)
         "lux math cos" (analyse-math-cos analyse exo-type ?values)
         "lux math sin" (analyse-math-sin analyse exo-type ?values)
         "lux math tan" (analyse-math-tan analyse exo-type ?values)
         "lux math acos" (analyse-math-acos analyse exo-type ?values)
         "lux math asin" (analyse-math-asin analyse exo-type ?values)
         "lux math atan" (analyse-math-atan analyse exo-type ?values)
         "lux math cosh" (analyse-math-cosh analyse exo-type ?values)
         "lux math sinh" (analyse-math-sinh analyse exo-type ?values)
         "lux math tanh" (analyse-math-tanh analyse exo-type ?values)
         "lux math exp" (analyse-math-exp analyse exo-type ?values)
         "lux math log" (analyse-math-log analyse exo-type ?values)
         "lux math root2" (analyse-math-root2 analyse exo-type ?values)
         "lux math root3" (analyse-math-root3 analyse exo-type ?values)
         "lux math ceil" (analyse-math-ceil analyse exo-type ?values)
         "lux math floor" (analyse-math-floor analyse exo-type ?values)
         "lux math round" (analyse-math-round analyse exo-type ?values)
         "lux math atan2" (analyse-math-atan2 analyse exo-type ?values)
         "lux math pow" (analyse-math-pow analyse exo-type ?values)
         
         "lux atom new" (analyse-atom-new analyse exo-type ?values)
         "lux atom get" (analyse-atom-get analyse exo-type ?values)
         "lux atom compare-and-swap" (analyse-atom-compare-and-swap analyse exo-type ?values)
         
         "lux process concurrency-level" (analyse-process-concurrency-level analyse exo-type ?values)
         "lux process future" (analyse-process-future analyse exo-type ?values)
         "lux process schedule" (analyse-process-schedule analyse exo-type ?values)
         
         ;; else
         (&/fail-with-loc (str "[Analyser Error] Unknown host procedure: " proc)))
    (catch Exception ex
      (&/fail-with-loc (str "[Analyser Error] Invalid syntax for procedure: " proc)))))