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

(def: #export (with-unknown-type action)
  (All [a] (-> (Meta a) (Meta [Type a])))
  (do macro.Monad<Meta>
    [[_ varT] (&.with-type-env tc.var)
     analysis (&.with-type varT
                action)
     knownT (&.with-type-env (tc.clean varT))]
    (wrap [knownT analysis])))

(exception: #export (Variant-Tag-Out-Of-Bounds {message Text})
  message)

(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))))