aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/tool/compiler/language/lux.lux
blob: e6d5816a4738df18f0333b3986ccb35a7ed91622 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(.module:
  [library
   [lux #*
    [control
     ["<>" parser
      ["<b>" binary (#+ Parser)]]]
    [data
     [format
      ["_" binary (#+ Writer)]]]]]
  ["." / #_
   ["#." version]
   [phase
    [analysis
     ["." module]]]
   [///
    [meta
     [archive
      ["." signature]
      ["." key (#+ Key)]]]]])

## TODO: Remove #module_hash, #imports & #module_state ASAP.
## TODO: Not just from this parser, but from the lux.Module type.
(def: #export writer
  (Writer .Module)
  (let [definition (: (Writer Definition)
                      ($_ _.and _.bit _.type _.code _.any))
        name (: (Writer Name)
                (_.and _.text _.text))
        alias (: (Writer Alias)
                 (_.and _.text _.text))
        global (: (Writer Global)
                  (_.or alias
                        definition))
        tag (: (Writer [Nat (List Name) Bit Type])
               ($_ _.and
                   _.nat
                   (_.list name)
                   _.bit
                   _.type))
        type (: (Writer [(List Name) Bit Type])
                ($_ _.and
                    (_.list name)
                    _.bit
                    _.type))]
    ($_ _.and
        ## #module_hash
        _.nat
        ## #module_aliases
        (_.list alias)
        ## #definitions
        (_.list (_.and _.text global))
        ## #imports
        (_.list _.text)
        ## #tags
        (_.list (_.and _.text tag))
        ## #types
        (_.list (_.and _.text type))
        ## #module_annotations
        (_.maybe _.code)
        ## #module_state
        _.any)))

(def: #export parser
  (Parser .Module)
  (let [definition (: (Parser Definition)
                      ($_ <>.and <b>.bit <b>.type <b>.code <b>.any))
        name (: (Parser Name)
                (<>.and <b>.text <b>.text))
        alias (: (Parser Alias)
                 (<>.and <b>.text <b>.text))
        global (: (Parser Global)
                  (<b>.or alias
                          definition))
        tag (: (Parser [Nat (List Name) Bit Type])
               ($_ <>.and
                   <b>.nat
                   (<b>.list name)
                   <b>.bit
                   <b>.type))
        type (: (Parser [(List Name) Bit Type])
                ($_ <>.and
                    (<b>.list name)
                    <b>.bit
                    <b>.type))]
    ($_ <>.and
        ## #module_hash
        <b>.nat
        ## #module_aliases
        (<b>.list alias)
        ## #definitions
        (<b>.list (<>.and <b>.text global))
        ## #imports
        (<b>.list <b>.text)
        ## #tags
        (<b>.list (<>.and <b>.text tag))
        ## #types
        (<b>.list (<>.and <b>.text type))
        ## #module_annotations
        (<b>.maybe <b>.code)
        ## #module_state
        (\ <>.monad wrap #.Cached))))

(def: #export key
  (Key .Module)
  (key.key {#signature.name (name_of ..compiler)
            #signature.version /version.version}
           (module.new 0)))