aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/lang/analysis/common.lux
blob: 4d16e4ae644be3376255d7dbe2d82d04b6fe17d7 (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
(;module:
  lux
  (lux (control monad
                ["ex" exception #+ exception:])
       (data text/format
             [product])
       [meta #+ Monad<Meta>]
       (meta [type]
             (type ["tc" check])))
  (luxc ["&" base]
        (lang analysis)))

(def: #export (with-unknown-type action)
  (All [a] (-> (Meta Analysis) (Meta [Type Analysis])))
  (do Monad<Meta>
    [[var-id var-type] (&;with-type-env
                         tc;var)
     analysis (&;with-expected-type var-type
                action)
     analysis-type (&;with-type-env
                     (tc;clean var-id var-type))]
    (wrap [analysis-type analysis])))

(def: #export (with-var body)
  (All [a] (-> (-> [Nat Type] (Meta a)) (Meta a)))
  (do Monad<Meta>
    [[id var] (&;with-type-env
                tc;var)]
    (body [id var])))

(exception: #export Variant-Tag-Out-Of-Bounds)

(def: #export (variant-out-of-bounds-error type size tag)
  (All [a] (-> Type Nat Nat (Meta a)))
  (&;throw Variant-Tag-Out-Of-Bounds
           (format "         Tag: " (%n tag) "\n"
                   "Variant Size: " (%n size) "\n"
                   "Variant Type: " (%type type))))