blob: 1725e80e527a9bc0c0104a57ba498abdbd551677 (
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
113
114
115
116
117
118
119
120
121
|
(.module:
[lux #*
[type (#+ :share)]
[abstract
[monad (#+ do)]]
[control
["." io (#+ IO io)]
["." try (#+ Try)]
[parser
[cli (#+ program:)]]
[security
["!" capability]]]
[data
["." product]
["." text
["%" format (#+ format)]]
[collection
["." dictionary]
["." row]
["." list ("#@." functor fold)]]]
[time
["." instant (#+ Instant)]]
[world
["." file (#+ File)]
["." console]]
[tool
[compiler
["." analysis]
["." directive]
["." phase
[macro (#+ Expander)]
["." generation]]
[default
["." platform (#+ Platform)]
["." syntax]]
[meta
["." archive (#+ Archive)]
[packager
["." script]]]]
## ["." interpreter]
]]
[/
["." cli (#+ Service)]])
(def: (or-crash! failure-description action)
(All [a]
(-> Text (IO (Try a)) (IO a)))
(do io.monad
[?output action]
(case ?output
(#try.Failure error)
(exec (log! (format text.new-line
failure-description text.new-line
error text.new-line))
(io.exit +1))
(#try.Success output)
(wrap output))))
(def: (save-artifacts! system state)
(All [anchor expression directive]
(-> (file.System IO)
(directive.State+ anchor expression directive)
(IO (Try Any))))
(let [?outcome (phase.run' state
(:share [anchor expression directive]
{(directive.State+ anchor expression directive)
state}
{(directive.Operation anchor expression directive
(generation.Output directive))
(directive.lift-generation generation.output)}))]
(case ?outcome
(#try.Success [state output])
(do (try.with io.monad)
[file (: (IO (Try (File IO)))
(file.get-file io.monad system "program.js"))]
(!.use (:: file over-write) (script.package output)))
(#try.Failure error)
(:: io.monad wrap (#try.Failure error)))))
(def: #export (compiler target partial-host-extension expander host-analysis platform generation-bundle host-directive-bundle program service)
(All [anchor expression directive]
(-> Text
Text
Expander
analysis.Bundle
(IO (Platform IO anchor expression directive))
(generation.Bundle anchor expression directive)
(directive.Bundle anchor expression directive)
(-> expression directive)
Service
(IO Any)))
(do io.monad
[platform platform
console (:: @ map try.assume console.system)]
(case service
(#cli.Compilation configuration)
(<| (or-crash! "Compilation failed:")
(do (try.with io.monad)
[state (:share [anchor expression directive]
{(Platform IO anchor expression directive)
platform}
{(IO (Try (directive.State+ anchor expression directive)))
(platform.initialize target expander host-analysis platform generation-bundle host-directive-bundle program)})
[archive state] (:share [anchor expression directive]
{(Platform IO anchor expression directive)
platform}
{(IO (Try [Archive (directive.State+ anchor expression directive)]))
(platform.compile partial-host-extension expander platform configuration archive.empty state)})
_ (save-artifacts! (get@ #platform.&file-system platform) state)
## _ (cache/io.clean target ...)
]
(wrap (log! "Compilation complete!"))))
(#cli.Interpretation configuration)
## TODO: Fix the interpreter...
(undefined)
## (<| (or-crash! "Interpretation failed:")
## (interpreter.run (try.with io.monad) console platform configuration generation-bundle))
)))
|