diff options
author | Eduardo Julian | 2022-03-14 01:09:08 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-03-14 01:09:08 -0400 |
commit | b8681fd206d5b5076b9737ee54f0cb0405a898d6 (patch) | |
tree | 6ba25cc4f31ad07b4279828568e9019f26334eca /stdlib/source/library/lux/world/program.lux | |
parent | 6766be5427b1788a44e07151e3fabe33ec4f8b37 (diff) |
Can now add type-vars to imported procedures from scripting languages.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/world/program.lux | 214 |
1 files changed, 98 insertions, 116 deletions
diff --git a/stdlib/source/library/lux/world/program.lux b/stdlib/source/library/lux/world/program.lux index 95118c399..7ec1fbd68 100644 --- a/stdlib/source/library/lux/world/program.lux +++ b/stdlib/source/library/lux/world/program.lux @@ -1,39 +1,41 @@ -(.using - [library - [lux "*" - ["@" target] - ["[0]" ffi {"+" import:}] - [abstract - ["[0]" monad {"+" Monad do}]] - [control - ["[0]" function] - ["[0]" io {"+" IO}] - ["[0]" maybe ("[1]#[0]" functor)] - ["[0]" try {"+" Try}] - ["[0]" exception {"+" exception:}] - [concurrency - ["[0]" atom] - ["[0]" async {"+" Async}]] - [parser - ["[0]" environment {"+" Environment}]]] - [data - ["[0]" bit ("[1]#[0]" equivalence)] - ["[0]" text - ["%" format {"+" format}]] - [collection - ["[0]" array {"+" Array}] - ["[0]" dictionary {"+" Dictionary}] - ["[0]" list ("[1]#[0]" functor)]]] - ["[0]" macro - ["[0]" template]] - [math - [number - ["i" int]]] - [type - abstract]]] - [// - [file {"+" Path}] - [shell {"+" Exit}]]) +(.`` (.`` (.using + [library + [lux "*" + ["@" target] + [abstract + ["[0]" monad {"+" Monad do}]] + [control + ["[0]" function] + ["[0]" io {"+" IO}] + ["[0]" maybe ("[1]#[0]" functor)] + ["[0]" try {"+" Try}] + ["[0]" exception {"+" exception:}] + [concurrency + ["[0]" atom] + ["[0]" async {"+" Async}]] + [parser + ["[0]" environment {"+" Environment}]]] + [data + ["[0]" bit ("[1]#[0]" equivalence)] + ["[0]" text + ["%" format {"+" format}]] + [collection + ["[0]" array {"+" Array}] + ["[0]" dictionary {"+" Dictionary}] + ["[0]" list ("[1]#[0]" functor)]]] + ["[0]" ffi {"+" import:} + (~~ (.for ["JavaScript" (~~ (.as_is ["[0]" node_js]))] + (~~ (.as_is))))] + ["[0]" macro + ["[0]" template]] + [math + [number + ["i" int]]] + [type + abstract]]] + [// + [file {"+" Path}] + [shell {"+" Exit}]]))) (exception: .public (unknown_environment_variable [name Text]) (exception.report @@ -148,13 +150,13 @@ (|>> %.int panic! io.io)) (import: NodeJs_Process - ["[1]::[0]" - (exit [ffi.Number] "io" Nothing) - (cwd [] "io" Path)]) + "[1]::[0]" + (exit [ffi.Number] "io" Nothing) + (cwd [] "io" Path)) (def: (exit_node_js! code) (-> Exit (IO Nothing)) - (case (ffi.constant ..NodeJs_Process [process]) + (case (ffi.global ..NodeJs_Process [process]) {.#Some process} (NodeJs_Process::exit (i.frac code) process) @@ -162,81 +164,60 @@ (..default_exit! code))) (import: Browser_Window - ["[1]::[0]" - (close [] Nothing)]) + "[1]::[0]" + (close [] Nothing)) (import: Browser_Location - ["[1]::[0]" - (reload [] Nothing)]) + "[1]::[0]" + (reload [] Nothing)) (def: (exit_browser! code) (-> Exit (IO Nothing)) - (case [(ffi.constant ..Browser_Window [window]) - (ffi.constant ..Browser_Location [location])] + (case [(ffi.global ..Browser_Window [window]) + (ffi.global ..Browser_Location [location])] [{.#Some window} {.#Some location}] (exec - (Browser_Window::close [] window) - (Browser_Location::reload [] location) + (Browser_Window::close window) + (Browser_Location::reload location) (..default_exit! code)) [{.#Some window} {.#None}] (exec - (Browser_Window::close [] window) + (Browser_Window::close window) (..default_exit! code)) [{.#None} {.#Some location}] (exec - (Browser_Location::reload [] location) + (Browser_Location::reload location) (..default_exit! code)) [{.#None} {.#None}] (..default_exit! code))) (import: Object - ["[1]::[0]" - ("static" entries [Object] (Array (Array ffi.String)))]) + "[1]::[0]" + ("static" entries [Object] (Array (Array ffi.String)))) (import: NodeJs_OS - ["[1]::[0]" - (homedir [] "io" Path)]) - - (template [<name> <path>] - [(def: (<name> _) - (-> [] (Maybe (-> ffi.String Any))) - (ffi.constant (-> ffi.String Any) <path>))] - - [normal_require [require]] - [global_require [global require]] - [process_load [global process mainModule constructor _load]] - ) - - (def: (require _) - (-> [] (-> ffi.String Any)) - (case [(normal_require []) (global_require []) (process_load [])] - (^or [{.#Some require} _ _] - [_ {.#Some require} _] - [_ _ {.#Some require}]) - require - - _ - (undefined)))) + "[1]::[0]" + (homedir [] "io" Path))) @.python (as_is (import: os - ["[1]::[0]" - ("static" getcwd [] "io" ffi.String) - ("static" _exit [ffi.Integer] "io" Nothing)]) + "[1]::[0]" + ("static" getcwd [] "io" ffi.String) + ("static" _exit [ffi.Integer] "io" Nothing)) (import: os/path - ["[1]::[0]" - ("static" expanduser [ffi.String] "io" ffi.String)]) + "[1]::[0]" + ("static" expanduser [ffi.String] "io" ffi.String)) (import: os/environ - ["[1]::[0]" - ("static" keys [] "io" (Array ffi.String)) - ("static" get [ffi.String] "io" "?" ffi.String)])) + "[1]::[0]" + ("static" keys [] "io" (Array ffi.String)) + ("static" get [ffi.String] "io" "?" ffi.String))) @.lua (as_is (ffi.import: LuaFile - ["[1]::[0]" - (read [ffi.String] "io" "?" ffi.String) - (close [] "io" ffi.Boolean)]) + "[1]::[0]" + (read [ffi.String] "io" "?" ffi.String) + (close [] "io" ffi.Boolean)) (ffi.import: (io/popen [ffi.String] "io" "try" "?" LuaFile)) (ffi.import: (os/getenv [ffi.String] "io" "?" ffi.String)) @@ -251,8 +232,8 @@ (case outcome {.#Some file} (do ! - [?output (LuaFile::read ["*l"] file) - _ (LuaFile::close [] file)] + [?output (LuaFile::read "*l" file) + _ (LuaFile::close file)] (in (maybe.else default ?output))) {.#None} @@ -260,22 +241,22 @@ {try.#Failure _} (in default))))) - @.ruby (as_is (ffi.import: Env "as" RubyEnv - ["[1]::[0]" - ("static" keys [] (Array Text)) - ("static" fetch [Text] "io" "?" Text)]) - - (ffi.import: "fileutils" FileUtils "as" RubyFileUtils - ["[1]::[0]" - ("static" pwd Path)]) + @.ruby (as_is (ffi.import: Env + "[1]::[0]" + ("static" keys [] (Array Text)) + ("static" fetch [Text] "io" "?" Text)) + + (ffi.import: "fileutils" FileUtils + "[1]::[0]" + ("static" pwd Path)) - (ffi.import: Dir "as" RubyDir - ["[1]::[0]" - ("static" home Path)]) + (ffi.import: Dir + "[1]::[0]" + ("static" home Path)) - (ffi.import: Kernel "as" RubyKernel - ["[1]::[0]" - ("static" exit [Int] "io" Nothing)])) + (ffi.import: Kernel + "[1]::[0]" + ("static" exit [Int] "io" Nothing))) ... @.php ... (as_is (ffi.import: (exit [Int] "io" Nothing)) @@ -315,7 +296,7 @@ (for [@.old <jvm> @.jvm <jvm> @.js (io.io (if ffi.on_node_js? - (case (ffi.constant Object [process env]) + (case (ffi.global Object [process env]) {.#Some process/env} (|> (Object::entries [process/env]) (array.list {.#None}) @@ -327,7 +308,7 @@ @.python (# io.monad each (array.list {.#None}) (os/environ::keys [])) ... Lua offers no way to get all the environment variables available. @.lua (io.io (list)) - @.ruby (io.io (array.list {.#None} (RubyEnv::keys []))) + @.ruby (io.io (array.list {.#None} (Env::keys []))) ... @.php (do io.monad ... [environment (..getenv/0 [])] ... (in (|> environment @@ -362,7 +343,7 @@ @.jvm <jvm> @.js (io.io (if ffi.on_node_js? (case (do maybe.monad - [process/env (ffi.constant Object [process env])] + [process/env (ffi.global Object [process env])] (array.read! (:as Nat name) (:as (Array Text) process/env))) {.#Some value} @@ -373,7 +354,7 @@ (exception.except ..unknown_environment_variable [name]))) @.python (!fetch os/environ::get |>) @.lua (!fetch os/getenv |>) - @.ruby (!fetch RubyEnv::fetch |>) + @.ruby (!fetch Env::fetch |>) ])))) (def: home @@ -386,13 +367,14 @@ (for [@.old <jvm> @.jvm <jvm> @.js (if ffi.on_node_js? - (|> (..require [] "os") + (|> (node_js.require "os") + maybe.trusted (:as NodeJs_OS) - (NodeJs_OS::homedir [])) + NodeJs_OS::homedir) <default>) - @.python (os/path::expanduser ["~"]) + @.python (os/path::expanduser "~") @.lua (..run_command "~" "echo ~") - @.ruby (io.io (RubyDir::home)) + @.ruby (io.io (Dir::home)) ... @.php (do io.monad ... [output (..getenv/1 ["HOME"])] ... (in (if (bit#= false (:as Bit output)) @@ -412,9 +394,9 @@ (for [@.old <jvm> @.jvm <jvm> @.js (if ffi.on_node_js? - (case (ffi.constant ..NodeJs_Process [process]) + (case (ffi.global ..NodeJs_Process [process]) {.#Some process} - (NodeJs_Process::cwd [] process) + (NodeJs_Process::cwd process) {.#None} (io.io <default>)) @@ -426,7 +408,7 @@ (if (same? default on_windows) (..run_command default "pwd") (in on_windows))) - @.ruby (io.io (RubyFileUtils::pwd)) + @.ruby (io.io (FileUtils::pwd)) ... @.php (do io.monad ... [output (..getcwd [])] ... (in (if (bit#= false (:as Bit output)) @@ -450,9 +432,9 @@ ... else (..default_exit! code)) - @.python (os::_exit [code]) - @.lua (os/exit [code]) - @.ruby (RubyKernel::exit [code]) + @.python (os::_exit code) + @.lua (os/exit code) + @.ruby (Kernel::exit code) ... @.php (..exit [code]) ... @.scheme (..exit [code]) ])))) |