blob: 253bf9b54b3e2f9e4bcc51210b641d0c039ee8ab (
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
|
(.using
[library
[lux "*"
["@" target]
[abstract
[monad {"+" do}]]
[control
["[0]" io]
[concurrency
["[0]" thread]]
["<>" parser
["<[0]>" code]
["<[0]>" cli]]]
[macro {"+" with_symbols}
[syntax {"+" syntax:}]
["[0]" code]]]])
(type: Arguments
(Variant
{#Raw Text}
{#Parsed (List Code)}))
(def: arguments^
(<code>.Parser Arguments)
(<>.or <code>.local_symbol
(<code>.tuple (<>.some <code>.any))))
(syntax: .public (program: [args ..arguments^
body <code>.any])
(with_symbols [g!program g!args g!_ g!output g!message]
(let [initialization+event_loop (for @.old body
@.jvm body
@.js body
@.python body
(` ((~! do) (~! io.monad)
[(~ g!output) (~ body)
(~ g!_) (~! thread.run!)]
((~' in) (~ g!output)))))]
(in (list (` ("lux def program"
(~ (case args
{#Raw args}
(` (.function ((~ g!program) (~ (code.symbol ["" args])))
(~ initialization+event_loop)))
{#Parsed args}
(` (.function ((~ g!program) (~ g!args))
(case ((~! <cli>.result) (: (~! (<cli>.Parser (io.IO .Any)))
((~! do) (~! <>.monad)
[(~+ args)
(~ g!_) (~! <cli>.end)]
((~' in) (~ initialization+event_loop))))
(~ g!args))
{.#Right (~ g!output)}
(~ g!output)
{.#Left (~ g!message)}
(.panic! (~ g!message))))))))))))))
|