aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/analyser.lux
blob: 05a755b080404558958ae57dae53490e3f8f52c2 (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
(;module:
  lux
  (lux (control monad
                pipe)
       [io #- run]
       (concurrency ["A" atom])
       (data ["E" error]
             [text "T/" Eq<Text>]
             text/format
             (coll [list "L/" Fold<List> Monoid<List> Monad<List>]
                   ["D" dict])
             [number]
             [product])
       [macro #+ Monad<Lux>]
       [type]
       (type ["TC" check]))
  (luxc ["&" base]
        (lang ["la" analysis])
        ["&;" module]
        ["&;" env])
  (. ["&&;" lux]))

(def: #export (analyse eval ast)
  &;Analyser
  (case ast
    (^template [<tag> <analyser>]
      [cursor (<tag> value)]
      (<analyser> cursor value))
    ([#;Bool &&lux;analyse-bool]
     [#;Nat  &&lux;analyse-nat]
     [#;Int  &&lux;analyse-int]
     [#;Deg  &&lux;analyse-deg]
     [#;Real &&lux;analyse-real]
     [#;Char &&lux;analyse-char]
     [#;Text &&lux;analyse-text])

    (^ [cursor (#;Tuple (list))])
    (&&lux;analyse-unit cursor)

    (^ [cursor (#;Tuple (list singleton))])
    (analyse eval singleton)

    (^ [cursor (#;Tuple elems)])
    (&&lux;analyse-tuple (analyse eval) cursor elems)

    [cursor (#;Symbol reference)]
    (&&lux;analyse-reference cursor reference)

    (^ [cursor (#;Form (list [_ (#;Symbol ["" "_lux_check"])]
                             type
                             value))])
    (&&lux;analyse-check analyse eval cursor type value)

    (^ [cursor (#;Form (list [_ (#;Symbol ["" "_lux_coerce"])]
                             type
                             value))])
    (&&lux;analyse-coerce analyse eval cursor type value)

    (^ [cursor (#;Form (list [_ (#;Nat tag)]
                             value))])
    (&&lux;analyse-variant (analyse eval) cursor tag value)

    _
    (&;fail (format "Unrecognized syntax: " (%ast ast)))
    ))