blob: 7cb10b457f4e851a27397d0e05f4676c498714b9 (
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 #*
[control
[monad (#+ do)]
["p" parser]]
[concurrency
["." promise (#+ Promise)]
["." task (#+ Task)]]
[data
["e" error]
[text
format]]
["." io (#+ IO Process io)]
[time
["." instant]]
["." cli (#+ CLI program:)]
[world
["." file (#+ File)]]
[compiler
["." default (#+ Configuration Platform)]]]
[luxc
## ["." repl]
[lang
["." host/jvm]
[translation
["." jvm
["." runtime]
["." expression]]]]])
(type: Build
[Configuration Text])
(type: REPL
Configuration)
(do-template [<name> <short> <long>]
[(def: <name>
(CLI Text)
(cli.parameter [<short> <long>]))]
[source "-s" "--source"]
[target "-t" "--target"]
[program "-p" "--program"]
)
(def: configuration
(CLI Configuration)
($_ p.and
(p.some ..source)
..target))
(def: build
(CLI Build)
($_ p.and
configuration
..program))
(def: repl
(CLI REPL)
..configuration)
(type: Service
(#Build Build)
(#REPL REPL))
(def: service
(CLI Service)
(p.or (p.after (cli.this "build") build)
(p.after (cli.this "repl") repl)))
(def: (or-crash! failure-describer action)
(All [a]
(-> Text (Task a) (Promise a)))
(do promise.Monad<Promise>
[?output action]
(case ?output
(#e.Error error)
(exec (log! (format "\n"
failure-describer "\n"
error "\n"))
(io.run (io.exit +1)))
(#e.Success output)
(wrap output))))
(def: (timed action)
(All [a]
(-> (Process a) (Process a)))
(do io.Monad<Process>
[start (io.from-io instant.now)
result action
finish (io.from-io instant.now)
#let [elapsed-time (instant.span start finish)
_ (log! (format "\n" "Elapsed time: " (%duration elapsed-time)))]]
(wrap result)))
(def: jvm-platform
(IO (Platform Process host/jvm.Anchor host/jvm.Inst host/jvm.Definition))
(do io.Monad<IO>
[host jvm.init]
(wrap {#default.host host
#default.phase expression.translate
#default.runtime runtime.translate
#default.file-system file.JVM@System})))
(program: [{service ..service}]
(do io.Monad<IO>
[platform ..jvm-platform]
(wrap (: (Promise Any)
(case service
(#Build [configuration program])
(<| (or-crash! "Compilation failed:")
promise.future
..timed
(default.compile platform configuration program))
(#REPL configuration)
(undefined)
## (<| (or-crash! "REPL failed:")
## (repl.run sources target))
)))))
|