blob: c59c410ae56d33c8a3ace6c8b5a3466a88a9a69a (
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
108
109
110
111
112
|
(.require
[library
[lux (.except)
[extension (.only declaration)]
[abstract
["[0]" monad (.only do)]]
[control
["<>" parser]]
[data
[text
["%" \\format]]
[collection
["[0]" list (.use "[1]#[0]" monad mix)]
["[0]" set]]]
[math
["[0]" random]]
["[0]" meta (.only)
["[0]" static]
["[0]" code (.only)
["<[1]>" \\parser]]
["[0]" macro (.only)
[syntax (.only syntax)]]
[target
["/" lua]]
[compiler
["[0]" phase]
[meta
[cache
["[0]" dependency
["[1]" artifact]]]]
[language
[lux
["[0]" generation]
["[0]" declaration]
[analysis
["[0]" type]]]]]]]])
(def definition
(-> Code (Meta [Text Code]))
(|>> (list)
(<code>.result (<| <code>.form
(<>.after (<code>.this_text "lux def"))
(<>.before <code>.any)
(all <>.and
<code>.local
<code>.any)))
meta.lifted))
... [15.2 – Privacy](https://www.lua.org/pil/15.2.html)
... [15.3 – Packages and Files](https://www.lua.org/pil/15.3.html)
... [15.4 – Using the Global Table](https://www.lua.org/pil/15.4.html)
(with_expansions [<extension> (static.random (|>> %.nat (%.format "lua export ") code.text)
random.nat)]
(declaration (<extension> self phase archive [name <code>.text
term <code>.any])
(do [! phase.monad]
[next declaration.analysis
[_ term] (<| declaration.lifted_analysis
type.inferring
(next archive term))
next declaration.synthesis
term (declaration.lifted_synthesis
(next archive term))
dependencies (declaration.lifted_generation
(dependency.dependencies archive term))
next declaration.generation
[interim_artifacts term] (declaration.lifted_generation
(generation.with_interim_artifacts archive
(next archive term)))
_ (declaration.lifted_generation
(do !
[@self (generation.learn_custom name (list#mix set.has dependencies interim_artifacts))
.let [$exports (/.var "_REQUIREDNAME")
$global (/.var "_G")
exporting? (/.not (/.= /.nil $exports))
no_exports? (/.= /.nil (/.item $exports $global))
initialize_exports! (/.set (list (/.item $exports $global)) (/.table (list)))
export_definition! (/.set (|> $global
(/.item $exports)
(/.item (/.string name))
(list))
(/.var name))
export! (/.when exporting?
(all /.then
(/.when no_exports?
initialize_exports!)
export_definition!
))]
_ (generation.execute! (all /.then
(/.set (list (/.var name)) term)
export!))
_ (generation.save! @self {.#None} (all /.then
(/.local/1 (/.var name) term)
export!))]
(generation.log! (%.format "Export " (%.text name)))))]
(in declaration.no_requirements)))
(def .public export
(syntax (_ [exports (<>.many <code>.any)])
(let [! meta.monad]
(|> exports
(monad.each ! macro.expansion)
(at ! each (|>> list#conjoint
(monad.each ! ..definition)))
(at ! conjoint)
(at ! each (list#each (function (_ [name term])
(` (<extension> (, (code.text name)) (, term)))))))))))
|