aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/ffi.jvm.lux53
-rw-r--r--stdlib/source/lux/time/date.lux3
-rw-r--r--stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux3
-rw-r--r--stdlib/source/program/aedifex.lux17
-rw-r--r--stdlib/source/program/aedifex/command/auto.lux6
-rw-r--r--stdlib/source/program/aedifex/command/build.lux20
-rw-r--r--stdlib/source/program/aedifex/command/test.lux57
-rw-r--r--stdlib/source/program/aedifex/format.lux43
-rw-r--r--stdlib/source/program/aedifex/parser.lux28
-rw-r--r--stdlib/source/program/aedifex/profile.lux68
-rw-r--r--stdlib/source/program/aedifex/runtime.lux48
-rw-r--r--stdlib/source/test/aedifex/command/auto.lux13
-rw-r--r--stdlib/source/test/aedifex/profile.lux6
-rw-r--r--stdlib/source/test/aedifex/runtime.lux51
-rw-r--r--stdlib/source/test/lux/data/text/format.lux14
-rw-r--r--stdlib/source/test/lux/ffi.jvm.lux258
-rw-r--r--stdlib/source/test/lux/time/date.lux7
17 files changed, 497 insertions, 198 deletions
diff --git a/stdlib/source/lux/ffi.jvm.lux b/stdlib/source/lux/ffi.jvm.lux
index b9f1a3b7e..8e58c5e50 100644
--- a/stdlib/source/lux/ffi.jvm.lux
+++ b/stdlib/source/lux/ffi.jvm.lux
@@ -54,7 +54,9 @@
(|>> type.reflection reflection.reflection))
(template [<name> <class>]
- [(def: #export <name> .Type (#.Primitive <class> #.Nil))]
+ [(def: #export <name>
+ .Type
+ (#.Primitive <class> #.Nil))]
[Boolean box.boolean]
[Byte box.byte]
@@ -67,7 +69,9 @@
)
(template [<name> <class>]
- [(def: #export <name> .Type (#.Primitive (reflection.reflection <class>) #.Nil))]
+ [(def: #export <name>
+ .Type
+ (#.Primitive (reflection.reflection <class>) #.Nil))]
## Primitives
[boolean reflection.boolean]
@@ -161,7 +165,22 @@
[char_to_long "jvm conversion char-to-long" ..Character ..Long]
)
-(def: constructor_method_name "<init>")
+(template [<name> <from> <to> <0> <1>]
+ [(template: #export (<name> value)
+ {#.doc (doc "Type converter."
+ (: <to>
+ (<name> (: <from> foo))))}
+ (|> value <0> <1>))]
+
+ [long_to_char ..Long ..Character ..long_to_int ..int_to_char]
+ [byte_to_int ..Byte ..Integer ..byte_to_long ..long_to_int]
+ [short_to_int ..Short ..Integer ..short_to_long ..long_to_int]
+ [byte_to_char ..Byte ..Character ..byte_to_int ..int_to_char]
+ [short_to_char ..Short ..Character ..short_to_int ..int_to_char]
+ )
+
+(def: constructor_method_name
+ "<init>")
(type: Primitive_Mode
#ManualPrM
@@ -526,21 +545,16 @@
(<>.assert (exception.construct exception payload)
test))
-(def: (assert_valid_class_name type_vars name)
- (-> (List (Type Var)) External (Parser Any))
- (do <>.monad
- [_ (..assert ..class_names_cannot_contain_periods [name]
- (not (text.contains? name.external_separator name)))]
- (..assert ..class_name_cannot_be_a_type_variable [name type_vars]
- (not (list.member? text.equivalence
- (list\map parser.name type_vars)
- name)))))
-
(def: (valid_class_name type_vars)
(-> (List (Type Var)) (Parser External))
(do <>.monad
[name <code>.local_identifier
- _ (assert_valid_class_name type_vars name)]
+ _ (..assert ..class_names_cannot_contain_periods [name]
+ (not (text.contains? name.external_separator name)))
+ _ (..assert ..class_name_cannot_be_a_type_variable [name type_vars]
+ (not (list.member? text.equivalence
+ (list\map parser.name type_vars)
+ name)))]
(wrap name)))
(def: (class^' parameter^ type_vars)
@@ -659,9 +673,9 @@
(Parser (Type Declaration))
(do <>.monad
[[name variables] (: (Parser [External (List (Type Var))])
- (<>.either (<>.and (valid_class_name (list))
+ (<>.either (<>.and (..valid_class_name (list))
(<>\wrap (list)))
- (<code>.form (<>.and (valid_class_name (list))
+ (<code>.form (<>.and (..valid_class_name (list))
(<>.some var^)))
))]
(wrap (type.declaration name variables))))
@@ -1448,7 +1462,8 @@
[decorate_return_io #import_member_io? (` ((~! io.io) (~ return_term)))]
)
-(def: $String (type.class "java.lang.String" (list)))
+(def: $String
+ (type.class "java.lang.String" (list)))
(template [<input?> <name> <unbox/box> <special+>]
[(def: (<name> mode [unboxed raw])
@@ -1806,7 +1821,7 @@
(with_expansions [<failure> (as_is (meta.fail (exception.construct ..cannot_convert_to_jvm_type [type])))]
(def: (lux_type->jvm_type type)
(-> .Type (Meta (Type Value)))
- (if (lux_type\= Any type)
+ (if (lux_type\= .Any type)
(\ meta.monad wrap $Object)
(case type
(#.Primitive name params)
@@ -2013,7 +2028,7 @@
(wrap (list (` ("jvm object class" (~ (code.text (..reflection type))))))))
(syntax: #export (type {type (..type^ (list))})
- (wrap (list (value_type #ManualPrM type))))
+ (wrap (list (..value_type #ManualPrM type))))
(exception: #export (cannot_cast_to_non_object {type (Type Value)})
(exception.report
diff --git a/stdlib/source/lux/time/date.lux b/stdlib/source/lux/time/date.lux
index 2b7d657d0..b8b483cca 100644
--- a/stdlib/source/lux/time/date.lux
+++ b/stdlib/source/lux/time/date.lux
@@ -34,7 +34,8 @@
(dictionary.new n.hash)
//month.year))
-(def: minimum_day 1)
+(def: minimum_day
+ 1)
(def: (month_days year month)
(-> Year Month Nat)
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux
index 66ef65e71..0d67b2224 100644
--- a/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux
+++ b/stdlib/source/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux
@@ -951,8 +951,7 @@
(recur [next_name nextT])
#.Nil
- (/////analysis.throw ..cannot_cast [fromT toT fromC]))
- )))))))]
+ (wrap false)))))))))]
(if can_cast?
(wrap (#/////analysis.Extension extension_name (list (/////analysis.text from_name)
(/////analysis.text to_name)
diff --git a/stdlib/source/program/aedifex.lux b/stdlib/source/program/aedifex.lux
index f5ec4caf2..4cfc376d3 100644
--- a/stdlib/source/program/aedifex.lux
+++ b/stdlib/source/program/aedifex.lux
@@ -31,7 +31,7 @@
[lux
["." syntax]]]]]
[world
- ["." shell (#+ Shell)]
+ ["." shell (#+ Exit Shell)]
["." console (#+ Console)]
["." program (#+ Program)]
["." file (#+ Path)
@@ -72,7 +72,7 @@
(def: (with_dependencies program console command profile)
(All [a]
(-> (Program Promise) (Console Promise)
- (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command a))
+ (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Exit a]))
(Command a)))
(do /action.monad
[resolution (/command/deps.do! console
@@ -80,8 +80,17 @@
(..repositories profile)
(|>> (/repository/remote.repository http.default #.None)
/repository.async)
- profile)]
- ((command console program (file.async file.default) (shell.async shell.default) resolution) profile)))
+ profile)
+ [exit_code output] ((command console program (file.async file.default) (shell.async shell.default) resolution) profile)
+ _ (case exit_code
+ (^ (static shell.normal))
+ (wrap [])
+
+ _
+ (do promise.monad
+ [_ (\ program exit exit_code)]
+ (wrap (#try.Failure ""))))]
+ (wrap output)))
(exception: (cannot_find_repository {repository Text}
{options (Dictionary Text Address)})
diff --git a/stdlib/source/program/aedifex/command/auto.lux b/stdlib/source/program/aedifex/command/auto.lux
index 398fb26cf..ee2ab4bbd 100644
--- a/stdlib/source/program/aedifex/command/auto.lux
+++ b/stdlib/source/program/aedifex/command/auto.lux
@@ -12,7 +12,7 @@
["." set]]]
[world
[program (#+ Program)]
- [shell (#+ Shell)]
+ [shell (#+ Exit Shell)]
[console (#+ Console)]
["." file
["." watch (#+ Watcher)]]]]
@@ -45,8 +45,8 @@
(def: #export (do! delay watcher command)
(All [a]
(-> Nat (Watcher Promise)
- (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command a))
- (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command Any))))
+ (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Exit a]))
+ (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Exit Any]))))
(function (_ console program fs shell resolution)
(function (_ profile)
(with_expansions [<call> ((command console program fs shell resolution) profile)]
diff --git a/stdlib/source/program/aedifex/command/build.lux b/stdlib/source/program/aedifex/command/build.lux
index 2f603dbc1..34351f636 100644
--- a/stdlib/source/program/aedifex/command/build.lux
+++ b/stdlib/source/program/aedifex/command/build.lux
@@ -23,7 +23,7 @@
[world
["." program (#+ Program)]
["." file (#+ Path)]
- ["." shell (#+ Process Shell)]
+ ["." shell (#+ Exit Process Shell)]
["." console (#+ Console)]
[net
["." uri]]]]
@@ -169,7 +169,7 @@
)
(def: #export (do! console program fs shell resolution)
- (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Compiler Path]))
+ (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Exit Compiler Path]))
(function (_ profile)
(let [target (get@ #///.target profile)]
(case (get@ #///.program profile)
@@ -186,13 +186,14 @@
#let [[[command compiler_params] output] (case compiler
(^template [<tag> <runtime> <program>]
[(<tag> dependency)
- [(<runtime> (..path fs home dependency))
+ [(///runtime.for (get@ <runtime> profile)
+ (..path fs home dependency))
<program>]])
- ([#JVM ///runtime.java "program.jar"]
- [#JS ///runtime.node "program.js"]
- [#Python ///runtime.java "program.py"]
- [#Lua ///runtime.java "program.lua"]
- [#Ruby ///runtime.java "program.rb"]))
+ ([#JVM #///.java "program.jar"]
+ [#JS #///.js "program.js"]
+ [#Python #///.java "program.py"]
+ [#Lua #///.java "program.lua"]
+ [#Ruby #///.java "program.rb"]))
/ (\ fs separator)
cache_directory (format working_directory / target)]
_ (console.write_line ..start console)
@@ -212,5 +213,6 @@
..success
..failure)
console)]
- (wrap [compiler
+ (wrap [exit
+ compiler
(format cache_directory / output)])))))))
diff --git a/stdlib/source/program/aedifex/command/test.lux b/stdlib/source/program/aedifex/command/test.lux
index 0ccc0cfb2..55614ba80 100644
--- a/stdlib/source/program/aedifex/command/test.lux
+++ b/stdlib/source/program/aedifex/command/test.lux
@@ -14,7 +14,7 @@
[world
["." program (#+ Program)]
["." file]
- ["." shell (#+ Shell)]
+ ["." shell (#+ Exit Shell)]
["." console (#+ Console)]]]
["." // #_
["#." build]
@@ -31,32 +31,35 @@
(def: #export failure "[TEST FAILED]")
(def: #export (do! console program fs shell resolution profile)
- (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command Any))
+ (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Exit Any]))
(do promise.monad
[environment (program.environment promise.monad program)
#let [working_directory (\ program directory)]]
- (do ///action.monad
- [[compiler program] (//build.do! console program fs shell resolution
- (set@ #///.program (get@ #///.test profile) profile))
- _ (console.write_line ..start console)
- #let [[compiler_command compiler_parameters] (case compiler
- (^template [<tag> <runtime>]
- [(<tag> artifact)
- (<runtime> program)])
- ([#//build.JVM ///runtime.java]
- [#//build.JS ///runtime.node]
- [#//build.Python ///runtime.python]
- [#//build.Lua ///runtime.lua]
- [#//build.Ruby ///runtime.ruby]))]
- process (\ shell execute [environment
- working_directory
- compiler_command
- compiler_parameters])
- _ (//build.log_output! console process)
- _ (//build.log_error! console process)
- exit (\ process await [])
- _ (console.write_line (if (i.= shell.normal exit)
- ..success
- ..failure)
- console)]
- (wrap []))))
+ (do {! ///action.monad}
+ [[build_exit compiler program] (//build.do! console program fs shell resolution
+ (set@ #///.program (get@ #///.test profile) profile))]
+ (if (i.= shell.normal build_exit)
+ (do !
+ [_ (console.write_line ..start console)
+ #let [[compiler_command compiler_parameters] (case compiler
+ (^template [<tag> <runtime>]
+ [(<tag> artifact)
+ (///runtime.for (get@ <runtime> profile) program)])
+ ([#//build.JVM #///.java]
+ [#//build.JS #///.js]
+ [#//build.Python #///.python]
+ [#//build.Lua #///.lua]
+ [#//build.Ruby #///.ruby]))]
+ process (\ shell execute [environment
+ working_directory
+ compiler_command
+ compiler_parameters])
+ _ (//build.log_output! console process)
+ _ (//build.log_error! console process)
+ exit (\ process await [])
+ _ (console.write_line (if (i.= shell.normal exit)
+ ..success
+ ..failure)
+ console)]
+ (wrap [exit []]))
+ (wrap [build_exit []])))))
diff --git a/stdlib/source/program/aedifex/format.lux b/stdlib/source/program/aedifex/format.lux
index 9b44eced5..c7fc93b5a 100644
--- a/stdlib/source/program/aedifex/format.lux
+++ b/stdlib/source/program/aedifex/format.lux
@@ -7,9 +7,11 @@
["." list ("#\." functor)]
["." set (#+ Set)]]]
[macro
- ["." code]]]
+ ["." code]
+ ["." template]]]
["." // #_
["/" profile]
+ ["#." runtime (#+ Runtime)]
["#." project (#+ Project)]
["#." dependency (#+ Dependency)]
["#." artifact (#+ Artifact)
@@ -131,21 +133,34 @@
(` [(~+ (..artifact' artifact))
(~ (code.text type))])))
+(def: (runtime [program parameters])
+ (Format Runtime)
+ (` [(~ (code.text program))
+ (~+ (list\map code.text parameters))]))
+
(def: #export (profile value)
(Format /.Profile)
- (|> ..empty
- (..on_list "parents" (get@ #/.parents value) code.text)
- (..on_maybe "identity" (get@ #/.identity value) ..artifact)
- (..on_maybe "info" (get@ #/.info value) ..info)
- (..on_set "repositories" (get@ #/.repositories value) code.text)
- (..on_set "dependencies" (get@ #/.dependencies value) ..dependency)
- (dictionary.put "compiler" (..dependency (get@ #/.compiler value)))
- (..on_set "sources" (get@ #/.sources value) code.text)
- (dictionary.put "target" (code.text (get@ #/.target value)))
- (..on_maybe "program" (get@ #/.program value) code.text)
- (..on_maybe "test" (get@ #/.test value) code.text)
- (..on_dictionary "deploy_repositories" (get@ #/.deploy_repositories value) code.text code.text)
- ..aggregate))
+ (`` (|> ..empty
+ (..on_list "parents" (get@ #/.parents value) code.text)
+ (..on_maybe "identity" (get@ #/.identity value) ..artifact)
+ (..on_maybe "info" (get@ #/.info value) ..info)
+ (..on_set "repositories" (get@ #/.repositories value) code.text)
+ (..on_set "dependencies" (get@ #/.dependencies value) ..dependency)
+ (dictionary.put "compiler" (..dependency (get@ #/.compiler value)))
+ (..on_set "sources" (get@ #/.sources value) code.text)
+ (dictionary.put "target" (code.text (get@ #/.target value)))
+ (..on_maybe "program" (get@ #/.program value) code.text)
+ (..on_maybe "test" (get@ #/.test value) code.text)
+ (..on_dictionary "deploy_repositories" (get@ #/.deploy_repositories value) code.text code.text)
+ (~~ (template [<tag>]
+ [(dictionary.put (template.text [<tag>]) (..runtime (get@ <tag> value)))]
+
+ [#/.java]
+ [#/.js]
+ [#/.python]
+ [#/.lua]
+ [#/.ruby]))
+ ..aggregate)))
(def: #export project
(Format Project)
diff --git a/stdlib/source/program/aedifex/parser.lux b/stdlib/source/program/aedifex/parser.lux
index 8d0fcdf73..6374f8807 100644
--- a/stdlib/source/program/aedifex/parser.lux
+++ b/stdlib/source/program/aedifex/parser.lux
@@ -19,6 +19,7 @@
[net (#+ URL)]]]
["." // #_
["/" profile]
+ ["#." runtime (#+ Runtime)]
["#." project (#+ Project)]
["#." dependency]
["#." repository #_
@@ -171,6 +172,11 @@
(<>.and <code>.text
..repository))))
+(def: runtime
+ (Parser Runtime)
+ (<code>.tuple (<>.and <code>.text
+ (<>.some <code>.text))))
+
(def: profile
(Parser /.Profile)
(do {! <>.monad}
@@ -216,7 +222,22 @@
^deploy_repositories (: (Parser (Dictionary Text //repository.Address))
(<| (\ ! map (dictionary.from_list text.hash))
(<>.default (list))
- (..singular input "deploy_repositories" ..deploy_repository)))]]
+ (..singular input "deploy_repositories" ..deploy_repository)))
+ ^java (|> ..runtime
+ (..singular input "java")
+ (<>.default //runtime.default_java))
+ ^js (|> ..runtime
+ (..singular input "js")
+ (<>.default //runtime.default_js))
+ ^python (|> ..runtime
+ (..singular input "python")
+ (<>.default //runtime.default_python))
+ ^lua (|> ..runtime
+ (..singular input "lua")
+ (<>.default //runtime.default_lua))
+ ^ruby (|> ..runtime
+ (..singular input "ruby")
+ (<>.default //runtime.default_ruby))]]
($_ <>.and
^parents
^identity
@@ -229,6 +250,11 @@
^program
^test
^deploy_repositories
+ ^java
+ ^js
+ ^python
+ ^lua
+ ^ruby
)))
(def: #export project
diff --git a/stdlib/source/program/aedifex/profile.lux b/stdlib/source/program/aedifex/profile.lux
index d31d0aca9..9fe05b10b 100644
--- a/stdlib/source/program/aedifex/profile.lux
+++ b/stdlib/source/program/aedifex/profile.lux
@@ -13,6 +13,8 @@
["." dictionary (#+ Dictionary)]
["." list ("#\." monoid)]
["." set (#+ Set)]]]
+ [macro
+ ["." template]]
[world
[net (#+ URL)]
[file (#+ Path)]]
@@ -22,6 +24,7 @@
[archive
[descriptor (#+ Module)]]]]]]
[//
+ ["." runtime (#+ Runtime) ("#\." equivalence)]
["." dependency (#+ Dependency) ("#\." equivalence)]
["." artifact (#+ Artifact)
["." type]]
@@ -160,7 +163,12 @@
#target Target
#program (Maybe Module)
#test (Maybe Module)
- #deploy_repositories (Dictionary Text Address)})
+ #deploy_repositories (Dictionary Text Address)
+ #java Runtime
+ #js Runtime
+ #python Runtime
+ #lua Runtime
+ #ruby Runtime})
(def: #export equivalence
(Equivalence Profile)
@@ -186,7 +194,17 @@
## #test
(maybe.equivalence text.equivalence)
## #deploy_repositories
- (dictionary.equivalence text.equivalence)))
+ (dictionary.equivalence text.equivalence)
+ ## #java
+ runtime.equivalence
+ ## #js
+ runtime.equivalence
+ ## #python
+ runtime.equivalence
+ ## #lua
+ runtime.equivalence
+ ## #ruby
+ runtime.equivalence))
(implementation: #export monoid
(Monoid Profile)
@@ -202,23 +220,37 @@
#target ..default_target
#program #.None
#test #.None
- #deploy_repositories (dictionary.new text.hash)})
+ #deploy_repositories (dictionary.new text.hash)
+ #java runtime.default_java
+ #js runtime.default_js
+ #python runtime.default_python
+ #lua runtime.default_lua
+ #ruby runtime.default_ruby})
(def: (compose override baseline)
- {#parents (list\compose (get@ #parents baseline) (get@ #parents override))
- #identity (maybe\compose (get@ #identity override) (get@ #identity baseline))
- #info (maybe\compose (get@ #info override) (get@ #info baseline))
- #repositories (set.union (get@ #repositories baseline) (get@ #repositories override))
- #dependencies (set.union (get@ #dependencies baseline) (get@ #dependencies override))
- #compiler (if (dependency\= ..default_compiler (get@ #compiler override))
- (get@ #compiler baseline)
- (get@ #compiler override))
- #sources (set.union (get@ #sources baseline) (get@ #sources override))
- #target (if (text\= ..default_target (get@ #target baseline))
- (get@ #target override)
- (get@ #target baseline))
- #program (maybe\compose (get@ #program override) (get@ #program baseline))
- #test (maybe\compose (get@ #test override) (get@ #test baseline))
- #deploy_repositories (dictionary.merge (get@ #deploy_repositories override) (get@ #deploy_repositories baseline))}))
+ (template.let [(!runtime <tag> <runtime>)
+ [(if (runtime\= <runtime> (get@ <tag> override))
+ (get@ <tag> baseline)
+ (get@ <tag> override))]]
+ {#parents (list\compose (get@ #parents baseline) (get@ #parents override))
+ #identity (maybe\compose (get@ #identity override) (get@ #identity baseline))
+ #info (maybe\compose (get@ #info override) (get@ #info baseline))
+ #repositories (set.union (get@ #repositories baseline) (get@ #repositories override))
+ #dependencies (set.union (get@ #dependencies baseline) (get@ #dependencies override))
+ #compiler (if (dependency\= ..default_compiler (get@ #compiler override))
+ (get@ #compiler baseline)
+ (get@ #compiler override))
+ #sources (set.union (get@ #sources baseline) (get@ #sources override))
+ #target (if (text\= ..default_target (get@ #target baseline))
+ (get@ #target override)
+ (get@ #target baseline))
+ #program (maybe\compose (get@ #program override) (get@ #program baseline))
+ #test (maybe\compose (get@ #test override) (get@ #test baseline))
+ #deploy_repositories (dictionary.merge (get@ #deploy_repositories override) (get@ #deploy_repositories baseline))
+ #java (!runtime #java runtime.default_java)
+ #js (!runtime #js runtime.default_js)
+ #python (!runtime #python runtime.default_python)
+ #lua (!runtime #lua runtime.default_lua)
+ #ruby (!runtime #ruby runtime.default_ruby)})))
(exception: #export no_identity)
diff --git a/stdlib/source/program/aedifex/runtime.lux b/stdlib/source/program/aedifex/runtime.lux
index e3f5a4e92..571a9fc43 100644
--- a/stdlib/source/program/aedifex/runtime.lux
+++ b/stdlib/source/program/aedifex/runtime.lux
@@ -1,22 +1,44 @@
(.module:
- [lux #*
+ [lux (#- for)
+ [abstract
+ [equivalence (#+ Equivalence)]]
[data
- [text
- ["%" format (#+ format)]]]
+ ["." product]
+ ["." text
+ ["%" format (#+ format)]]
+ [collection
+ ["." list ("#\." monoid)]]]
[macro
["." template]]
[world
- [file (#+ Path)]
- [shell (#+ Command)]]])
+ ["." file]]])
+
+(type: #export Runtime
+ {#program Text
+ #parameters (List Text)})
+
+(def: #export equivalence
+ (Equivalence Runtime)
+ (product.equivalence
+ text.equivalence
+ (list.equivalence text.equivalence)))
(template [<name> <command> <parameters>]
- [(def: #export (<name> path)
- (-> Path [Text (List Text)])
- (`` (format [<command> (list (~~ (template.splice <parameters>)) path)])))]
+ [(def: #export <name>
+ Runtime
+ {#program <command>
+ #parameters (`` (list (~~ (template.splice <parameters>))))})]
- [java "java" ["-jar"]]
- [node "node" ["--stack_size=8192"]]
- [python "python3" []]
- [lua "lua" []]
- [ruby "RUBY_THREAD_VM_STACK_SIZE=15700000 ruby" []]
+ [default_java "java" ["-jar"]]
+ [default_js "node" ["--stack_size=8192"]]
+ [default_python "python3" []]
+ [default_lua "lua" []]
+ [default_ruby "RUBY_THREAD_VM_STACK_SIZE=15700000 ruby" []]
)
+
+(def: #export (for runtime path)
+ (-> Runtime file.Path Runtime)
+ (update@ #parameters
+ (function (_ parameters)
+ (list\compose parameters (list path)))
+ runtime))
diff --git a/stdlib/source/test/aedifex/command/auto.lux b/stdlib/source/test/aedifex/command/auto.lux
index dfb4dc672..193a5b8d8 100644
--- a/stdlib/source/test/aedifex/command/auto.lux
+++ b/stdlib/source/test/aedifex/command/auto.lux
@@ -27,7 +27,7 @@
["." instant]]
[world
[console (#+ Console)]
- ["." shell (#+ Shell)]
+ ["." shell (#+ Exit Shell)]
["." program (#+ Program)]
["." file
["." watch]]]]
@@ -46,7 +46,7 @@
(def: (command expected_runs end_signal fs dummy_file)
(-> Nat Text (file.System Promise) file.Path
[(Atom Nat)
- (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command Any))])
+ (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Exit Any]))])
(let [@runs (: (Atom Nat)
(atom.atom 0))]
[@runs
@@ -56,10 +56,11 @@
(if (n.= expected_runs actual_runs)
(wrap (#try.Failure end_signal))
(do (try.with !)
- [_ (\ fs write (\ utf8.codec encode (%.nat actual_runs)) dummy_file)]
- (\ fs modify
- (|> actual_runs .int instant.from_millis)
- dummy_file)))))]))
+ [_ (\ fs write (\ utf8.codec encode (%.nat actual_runs)) dummy_file)
+ _ (\ fs modify
+ (|> actual_runs .int instant.from_millis)
+ dummy_file)]
+ (wrap [shell.normal []])))))]))
(def: #export test
Test
diff --git a/stdlib/source/test/aedifex/profile.lux b/stdlib/source/test/aedifex/profile.lux
index d4cbb958a..e7e3f50ac 100644
--- a/stdlib/source/test/aedifex/profile.lux
+++ b/stdlib/source/test/aedifex/profile.lux
@@ -27,6 +27,7 @@
[\\program
["." /
["/#" // #_
+ ["#." runtime]
["#." dependency (#+ Dependency)]
["#." format]
[repository
@@ -129,6 +130,11 @@
(random.maybe (random.ascii/alpha 1))
(random.maybe (random.ascii/alpha 1))
(..dictionary_of text.hash (random.ascii/alpha 1) ..repository)
+ (random\wrap //runtime.default_java)
+ (random\wrap //runtime.default_js)
+ (random\wrap //runtime.default_python)
+ (random\wrap //runtime.default_lua)
+ (random\wrap //runtime.default_ruby)
))
(def: #export test
diff --git a/stdlib/source/test/aedifex/runtime.lux b/stdlib/source/test/aedifex/runtime.lux
index 968e753f8..e75a9297e 100644
--- a/stdlib/source/test/aedifex/runtime.lux
+++ b/stdlib/source/test/aedifex/runtime.lux
@@ -4,26 +4,57 @@
[abstract
[monad (#+ do)]]
[data
- ["." text]]
+ ["." maybe ("#\." functor)]
+ ["." text ("#\." equivalence)]
+ [collection
+ ["." list ("#\." functor)]
+ ["." set]]]
[math
- ["." random]]]
+ ["." random (#+ Random) ("#\." monad)]
+ [number
+ ["n" nat]]]]
[\\program
["." /]])
+(def: #export random
+ (Random /.Runtime)
+ ($_ random.either
+ (random\wrap /.default_java)
+ (random\wrap /.default_js)
+ (random\wrap /.default_python)
+ (random\wrap /.default_lua)
+ (random\wrap /.default_ruby)
+ ))
+
(def: #export test
Test
(<| (_.covering /._)
+ (_.for [/.Runtime])
(do random.monad
- [path (random.ascii/alpha 5)]
+ [path (random.ascii/alpha 5)
+ runtime ..random]
(`` ($_ _.and
(~~ (template [<command>]
- [(_.cover [<command>]
- (let [command (text.join_with " " (#.Cons (<command> path)))
- pure_command (text.join_with " " (#.Cons (<command> "")))]
- (and (text.starts_with? pure_command command)
- (text.ends_with? path command))))]
+ [(_.cover [/.default_java /.default_js /.default_python /.default_lua /.default_ruby]
+ (let [listing (|> (list /.default_java /.default_js /.default_python /.default_lua /.default_ruby)
+ (list\map (get@ #/.program)))
+ unique (set.from_list text.hash listing)]
+ (n.= (list.size listing)
+ (set.size unique))))]
- [/.java]
- [/.node]
+ [/.default_java]
+ [/.default_js]
+ [/.default_python]
+ [/.default_lua]
+ [/.default_ruby]
))
+ (_.cover [/.for]
+ (let [runtime' (/.for runtime path)]
+ (and (text\= (get@ #/.program runtime)
+ (get@ #/.program runtime'))
+ (|> runtime'
+ (get@ #/.parameters)
+ list.last
+ (maybe\map (text\= path))
+ (maybe.default false)))))
)))))
diff --git a/stdlib/source/test/lux/data/text/format.lux b/stdlib/source/test/lux/data/text/format.lux
index db1615631..54176cda3 100644
--- a/stdlib/source/test/lux/data/text/format.lux
+++ b/stdlib/source/test/lux/data/text/format.lux
@@ -19,6 +19,8 @@
[collection
["." list ("#\." functor)]]]
["." time
+ ["." day]
+ ["." month]
["." instant]
["." duration]
["." date]]
@@ -102,6 +104,8 @@
[/.name name.codec ($///name.random 5 5)]
[/.xml xml.codec $///xml.random]
[/.json json.codec $///json.random]
+ [/.day day.codec random.day]
+ [/.month month.codec random.month]
[/.instant instant.codec random.instant]
[/.duration duration.codec random.duration]
[/.date date.codec random.date]
@@ -152,6 +156,16 @@
(text.join_with " ")
list
(/.list (|>>))))))
+ (do random.monad
+ [sample (random.maybe random.nat)]
+ (_.cover [/.maybe]
+ (case sample
+ #.None
+ true
+
+ (#.Some value)
+ (text.contains? (/.nat value)
+ (/.maybe /.nat sample)))))
(do {! random.monad}
[modulus (random.one (|>> modulus.modulus
try.to_maybe)
diff --git a/stdlib/source/test/lux/ffi.jvm.lux b/stdlib/source/test/lux/ffi.jvm.lux
index 86e43a9f3..7baa32fa2 100644
--- a/stdlib/source/test/lux/ffi.jvm.lux
+++ b/stdlib/source/test/lux/ffi.jvm.lux
@@ -1,16 +1,28 @@
(.module:
[lux #*
- [abstract/monad (#+ Monad do)]
+ ["_" test (#+ Test)]
+ ["." type ("#\." equivalence)]
+ ["." meta]
+ [abstract
+ [monad (#+ do)]]
[control
- pipe]
+ [pipe (#+ case>)]
+ ["." try]
+ ["." exception]]
[data
- ["." text ("#\." equivalence)]]
+ ["." bit ("#\." equivalence)]
+ ["." text ("#\." equivalence)]
+ [collection
+ ["." array (#+ Array)]]]
+ ["." macro
+ [syntax (#+ syntax:)]
+ ["." code]]
[math
- ["r" random]
+ ["." random]
[number
["n" nat]
- ["i" int]]]
- ["_" test (#+ Test)]]
+ ["i" int ("#\." equivalence)]
+ ["f" frac ("#\." equivalence)]]]]
[\\
["." /]])
@@ -74,78 +86,184 @@
## (/.interface: TestInterface
## ([] foo [boolean java/lang/String] void #throws [java/lang/Exception]))
+(template [<name> <type> <conversion> <lux> <=>]
+ [(def: (<name> left right)
+ (-> <type> <type> Bit)
+ (<=> (:as <lux> (<conversion> left))
+ (:as <lux> (<conversion> right))))]
+
+ [boolean\= /.Boolean <| Bit bit\=]
+ [byte\= /.Byte /.byte_to_long Int i\=]
+ [short\= /.Short /.short_to_long Int i\=]
+ [integer\= /.Integer /.int_to_long Int i\=]
+ [long\= /.Long <| Int i\=]
+ [float\= /.Float /.float_to_double Frac f\=]
+ [double\= /.Double <| Frac f\=]
+ [character\= /.Character /.char_to_long Int i\=]
+ )
+
+(syntax: (macro_error expression)
+ (function (_ lux)
+ (|> (macro.expand_once expression)
+ (meta.run lux)
+ (case> (#try.Success expansion)
+ (#try.Failure "OOPS!")
+
+ (#try.Failure error)
+ (#try.Success [lux (list (code.text error))])))))
+
(def: conversions
Test
- (do r.monad
- [sample r.int]
+ (do {! random.monad}
+ [long (\ ! map (|>> (:as /.Long)) random.int)
+ integer (\ ! map (|>> (:as /.Long) /.long_to_int) random.int)
+ byte (\ ! map (|>> (:as /.Long) /.long_to_byte) random.int)
+ short (\ ! map (|>> (:as /.Long) /.long_to_short) random.int)
+ float (\ ! map (|>> (:as /.Double) /.double_to_float) random.frac)]
(`` ($_ _.and
- (~~ (template [<to> <from> <message>]
- [(_.test <message>
- (or (|> sample (:as java/lang/Long) <to> <from> (:as Int) (i.= sample))
- (let [capped_sample (|> sample (:as java/lang/Long) <to> <from>)]
- (|> capped_sample <to> <from> (:as Int) (i.= (:as Int capped_sample))))))]
-
- [/.long_to_byte /.byte_to_long "Can succesfully convert to/from byte."]
- [/.long_to_short /.short_to_long "Can succesfully convert to/from short."]
- [/.long_to_int /.int_to_long "Can succesfully convert to/from int."]
- [/.long_to_float /.float_to_long "Can succesfully convert to/from float."]
- [/.long_to_double /.double_to_long "Can succesfully convert to/from double."]
- [(<| /.int_to_char /.long_to_int) (<| /.int_to_long /.char_to_int) "Can succesfully convert to/from char."]
- ))
- ))))
+ (~~ (template [<sample> <=> <to> <from>]
+ [(_.cover [<to> <from>]
+ (or (|> <sample> <to> <from> (<=> <sample>))
+ (let [capped (|> <sample> <to> <from>)]
+ (|> capped <to> <from> (<=> capped)))))]
-(def: miscellaneous
- Test
- (do {! r.monad}
- [sample (\ ! map (|>> (:as java/lang/Object))
- (r.ascii 1))]
- ($_ _.and
- (_.test "Can check if an object is of a certain class."
- (and (case (/.check java/lang/String sample) (#.Some _) true #.None false)
- (case (/.check java/lang/Long sample) (#.Some _) false #.None true)
- (case (/.check java/lang/Object sample) (#.Some _) true #.None false)
- (case (/.check java/lang/Object (/.null)) (#.Some _) false #.None true)))
-
- (_.test "Can run code in a 'synchronized' block."
- (/.synchronized sample #1))
-
- (_.test "Can access Class instances."
- (text\= "java.lang.Class" (java/lang/Class::getName (/.class_for java/lang/Class))))
-
- (_.test "Can check if a value is null."
- (and (/.null? (/.null))
- (not (/.null? sample))))
-
- (_.test "Can safely convert nullable references into Maybe values."
- (and (|> (: (Maybe java/lang/Object) (/.??? (/.null)))
- (case> #.None #1
- _ #0))
- (|> (: (Maybe java/lang/Object) (/.??? sample))
- (case> (#.Some _) #1
- _ #0))))
- )))
+ [long long\= /.long_to_byte /.byte_to_long]
+ [long long\= /.long_to_short /.short_to_long]
+ [long long\= /.long_to_int /.int_to_long]
+ [long long\= /.long_to_float /.float_to_long]
+ [long long\= /.long_to_double /.double_to_long]
+ [long long\= /.long_to_char /.char_to_long]
+
+ [integer integer\= /.int_to_double /.double_to_int]
+ [integer integer\= /.int_to_float /.float_to_int]
+ [integer integer\= /.int_to_char /.char_to_int]
+
+ [byte byte\= /.byte_to_int /.int_to_byte]
+ [short short\= /.short_to_int /.int_to_short]
+ [byte byte\= /.byte_to_char /.char_to_byte]
+ [short short\= /.short_to_char /.char_to_short]
+ [float float\= /.float_to_double /.double_to_float]
+ ))))))
(def: arrays
Test
- (do {! r.monad}
- [size (|> r.nat (\ ! map (|>> (n.% 100) (n.max 1))))
- idx (|> r.nat (\ ! map (n.% size)))
- value (\ ! map (|>> (:as java/lang/Long)) r.int)]
+ (do {! random.monad}
+ [size (|> random.nat (\ ! map (|>> (n.% 100) (n.max 1))))
+ idx (|> random.nat (\ ! map (n.% size)))
+ value (\ ! map (|>> (:as java/lang/Long)) random.int)]
($_ _.and
- (_.test "Can create arrays of some length."
- (n.= size (/.array_length (/.array java/lang/Long size))))
+ (_.cover [/.array /.array_length]
+ (|> size
+ (/.array java/lang/Long)
+ /.array_length
+ (n.= size)))
+ (_.cover [/.array_write /.array_read]
+ (|> (/.array java/lang/Long size)
+ (/.array_write idx value)
+ (/.array_read idx)
+ (:as Int)
+ (i.= (:as Int value))))
+ (_.cover [/.cannot_convert_to_jvm_type]
+ (let [array (:as (Array Nothing)
+ (array.new 1))]
+ (|> array
+ /.array_length
+ ..macro_error
+ (text.contains? (get@ #exception.label /.cannot_convert_to_jvm_type))))))))
- (_.test "Can set and get array values."
- (let [arr (/.array java/lang/Long size)]
- (exec (/.array_write idx value arr)
- (i.= (:as Int value)
- (:as Int (/.array_read idx arr)))))))))
+(def: miscellaneous
+ Test
+ (`` (do {! random.monad}
+ [sample (\ ! map (|>> (:as java/lang/Object))
+ (random.ascii 1))
+ boolean (\ ! map (|>> (:as /.Boolean)) random.bit)
+ byte (\ ! map (|>> (:as /.Long) /.long_to_byte) random.int)
+ short (\ ! map (|>> (:as /.Long) /.long_to_short) random.int)
+ integer (\ ! map (|>> (:as /.Long) /.long_to_int) random.int)
+ long (\ ! map (|>> (:as /.Long)) random.int)
+ float (\ ! map (|>> (:as /.Double) /.double_to_float) random.frac)
+ double (\ ! map (|>> (:as /.Double)) random.frac)
+ character (\ ! map (|>> (:as /.Long) /.long_to_int /.int_to_char) random.int)
+ string (\ ! map (|>> (:as java/lang/String))
+ (random.ascii 1))]
+ ($_ _.and
+ (_.cover [/.check]
+ (and (case (/.check java/lang/String sample) (#.Some _) true #.None false)
+ (case (/.check java/lang/Long sample) (#.Some _) false #.None true)
+ (case (/.check java/lang/Object sample) (#.Some _) true #.None false)
+ (case (/.check java/lang/Object (/.null)) (#.Some _) false #.None true)))
+ (_.cover [/.synchronized]
+ (/.synchronized sample #1))
+ (_.cover [/.class_for]
+ (text\= "java.lang.Class" (java/lang/Class::getName (/.class_for java/lang/Class))))
+ (_.cover [/.null /.null?]
+ (and (/.null? (/.null))
+ (not (/.null? sample))))
+ (_.cover [/.???]
+ (and (|> (/.??? (/.null))
+ (: (Maybe java/lang/Object))
+ (case> #.None #1
+ (#.Some _) #0))
+ (|> (/.??? sample)
+ (: (Maybe java/lang/Object))
+ (case> (#.Some _) #1
+ #.None #0))))
+ (_.cover [/.!!!]
+ (and (|> (/.??? (/.null))
+ /.!!!
+ /.null?)
+ (|> (/.??? sample)
+ /.!!!
+ /.null?
+ not)))
+ (~~ (template [<object> <primitive> <value> <=>]
+ [(|> <value>
+ (: <object>)
+ "jvm object cast"
+ (: <primitive>)
+ "jvm object cast"
+ (: <object>)
+ (<=> <value>)
+ (_.cover [<object> <primitive>]))]
+
+ [/.Boolean /.boolean boolean boolean\=]
+ [/.Byte /.byte byte byte\=]
+ [/.Short /.short short short\=]
+ [/.Integer /.int integer integer\=]
+ [/.Long /.long long long\=]
+ [/.Float /.float float float\=]
+ [/.Double /.double double double\=]
+ [/.Character /.char character character\=]
+ ))
+ (_.cover [/.cannot_cast_to_non_object]
+ (text.contains? (get@ #exception.label /.cannot_cast_to_non_object)
+ (macro_error (/.:cast boolean (: /.Boolean boolean)))))
+ (_.cover [/.:cast]
+ (|> string
+ (/.:cast java/lang/Object)
+ (is? (:as java/lang/Object string))))
+ (_.cover [/.type]
+ (and (and (type\= /.Boolean (/.type java/lang/Boolean))
+ (type\= /.Boolean (/.type boolean)))
+ (and (type\= /.Byte (/.type java/lang/Byte))
+ (type\= /.Byte (/.type byte)))
+ (and (type\= /.Short (/.type java/lang/Short))
+ (type\= /.Short (/.type short)))
+ (and (type\= /.Integer (/.type java/lang/Integer))
+ (type\= /.Integer (/.type int)))
+ (and (type\= /.Long (/.type java/lang/Long))
+ (type\= /.Long (/.type long)))
+ (and (type\= /.Float (/.type java/lang/Float))
+ (type\= /.Float (/.type float)))
+ (and (type\= /.Double (/.type java/lang/Double))
+ (type\= /.Double (/.type double)))
+ (and (type\= /.Character (/.type java/lang/Character))
+ (type\= /.Character (/.type char)))))
+ ))))
(def: #export test
- ($_ _.and
- (<| (_.context "Conversions.")
- ..conversions)
- (<| (_.context "Miscellaneous.")
- ..miscellaneous)
- (<| (_.context "Arrays.")
- ..arrays)))
+ (<| (_.covering /._)
+ ($_ _.and
+ ..conversions
+ ..arrays
+ ..miscellaneous)))
diff --git a/stdlib/source/test/lux/time/date.lux b/stdlib/source/test/lux/time/date.lux
index b8813ba77..fdf78d535 100644
--- a/stdlib/source/test/lux/time/date.lux
+++ b/stdlib/source/test/lux/time/date.lux
@@ -19,7 +19,8 @@
[math
["." random (#+ Random)]
[number
- ["n" nat]]]]
+ ["n" nat]
+ ["i" int]]]]
[\\
["." /]])
@@ -63,6 +64,10 @@
/.to_days
/.from_days
(\ /.equivalence = expected))))
+ (_.cover [/.epoch]
+ (|> /.epoch
+ /.to_days
+ (i.= +0)))
(do random.monad
[expected random.date]
(_.cover [/.parser]