aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/tool/compiler/language/lux/program.lux
blob: ecafe76154125fc723f4d83f894f6e486c75f23a (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
(.module:
  [library
   [lux {"-" [Module]}
    [abstract
     ["[0]" monad {"+" [do]}]]
    [control
     ["[0]" maybe]
     ["[0]" try {"+" [Try]}]
     ["[0]" exception {"+" [exception:]}]]
    [data
     ["[0]" product]
     [text
      ["%" format {"+" [format]}]]
     [collection
      ["[0]" list ("[1]\[0]" functor)]]]]]
  [//
   [generation {"+" [Context]}]
   [///
    [meta
     ["[0]" archive {"+" [Archive]}
      ["[0]" descriptor {"+" [Module]}]
      ["[0]" artifact]]]]])

(type: .public (Program expression directive)
  (-> Context expression directive))

(def: .public name
  Text
  "")

(exception: .public (cannot_find_program {modules (List Module)})
  (exception.report
   ["Modules" (exception.listing %.text modules)]))

(def: .public (context archive)
  (-> Archive (Try Context))
  (do [! try.monad]
    [registries (|> archive
                    archive.archived
                    (monad.each !
                                (function (_ module)
                                  (do !
                                    [id (archive.id module archive)
                                     [descriptor document] (archive.find module archive)]
                                    (in [[module id] (value@ #descriptor.registry descriptor)])))))]
    (case (list.one (function (_ [[module module_id] registry])
                      (do maybe.monad
                        [program_id (artifact.remember ..name registry)]
                        (in [module_id program_id])))
                    registries)
      (#.Some program_context)
      (in program_context)
      
      #.None
      (|> registries
          (list\each (|>> product.left product.left))
          (exception.except ..cannot_find_program)))))