(.require [library [lux (.except) [abstract [monad (.only do)]] [control ["<>" parser] ["[0]" io (.only IO)] [concurrency ["[0]" thread]]] [meta ["@" target] ["[0]" code (.only) ["<[1]>" \\parser]] [macro (.only with_symbols) [syntax (.only syntax)]]]]] ["" \\parser]) (type .public Program (-> (List Text) (IO Any))) (type Arguments (Variant {#Raw Text} {#Parsed (List Code)})) (def arguments^ (.Parser Arguments) (<>.or .local (.tuple (<>.some .any)))) (def .public program (syntax (_ [args ..arguments^ body .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 ... else (` (do io.monad [(, g!output) (, body) (, g!_) thread.run!] ((,' in) (, g!output)))))] (in (list (` (is Program (, (when args {#Raw args} (` (.function ((, g!program) (, (code.symbol ["" args]))) (, initialization+event_loop))) {#Parsed args} (` (.function ((, g!program) (, g!args)) (when (.result (.is (.Parser (io.IO .Any)) (do <>.monad [(,* args) (, g!_) .end] ((,' in) (, initialization+event_loop)))) (, g!args)) {.#Right (, g!output)} (, g!output) {.#Left (, g!message)} (.panic! (, g!message)))))))))))))))