aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/tool/compiler/meta/archive/artifact.lux
blob: 2d45592751f9d9eb604b603a848d8882d8f4c3e9 (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
(.module:
  [lux #*
   [data
    ["." text]
    [collection
     ["." list]
     ["." row (#+ Row)]
     ["." dictionary (#+ Dictionary)]]]
   [type
    abstract]])

(type: #export ID Nat)

(type: Artifact
  {#id ID
   #name (Maybe Text)})

(abstract: #export Registry
  {}
  {#artifacts (Row Artifact)
   #resolver (Dictionary Text ID)}

  (def: #export empty
    Registry
    (:abstraction {#artifacts row.empty
                   #resolver (dictionary.new text.hash)}))

  (def: next
    (-> Registry ID)
    (|>> :representation (get@ #artifacts) row.size))

  (def: #export (resource registry)
    (-> Registry [ID Registry])
    (let [id (..next registry)]
      [id
       (|> registry
           :representation
           (update@ #artifacts (row.add {#id id
                                         #name #.None}))
           :abstraction)]))

  (def: #export (definition name registry)
    (-> Text Registry [ID Registry])
    (let [id (..next registry)]
      [id
       (|> registry
           :representation
           (update@ #artifacts (row.add {#id id
                                         #name (#.Some name)}))
           (update@ #resolver (dictionary.put name id))
           :abstraction)]))

  (def: #export (definitions registry)
    (-> Registry (List Text))
    (|> registry
        :representation
        (get@ #artifacts)
        row.to-list
        (list.search-all (get@ #name))))

  (def: #export (remember name registry)
    (-> Text Registry (Maybe ID))
    (|> (:representation registry)
        (get@ #resolver)
        (dictionary.get name)))
  )