aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--documentation/bookmark/compilation/target/c++.md6
-rw-r--r--lux-c++/source/program.lux28
-rw-r--r--lux-lua/source/program.lux3
-rw-r--r--stdlib/source/library/lux/control/security/policy.lux12
-rw-r--r--stdlib/source/library/lux/ffi.lux2
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lua.lux5
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/common.lux5
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/host.lux23
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/primitive.lux28
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux30
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua.lux8
-rw-r--r--stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux28
-rw-r--r--stdlib/source/library/lux/meta/target/c++.lux114
-rw-r--r--stdlib/source/library/lux/meta/target/lua.lux26
-rw-r--r--stdlib/source/specification/lux/world/console.lux60
-rw-r--r--stdlib/source/specification/lux/world/environment.lux34
-rw-r--r--stdlib/source/test/lux.lux1
-rw-r--r--stdlib/source/test/lux/control/security/policy.lux5
-rw-r--r--stdlib/source/test/lux/meta.lux4
-rw-r--r--stdlib/source/test/lux/meta/compiler/language/lux/phase.lux4
-rw-r--r--stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux7
-rw-r--r--stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux51
-rw-r--r--stdlib/source/test/lux/meta/compiler/meta.lux6
-rw-r--r--stdlib/source/test/lux/world/console.lux56
-rw-r--r--stdlib/source/test/lux/world/environment.lux27
-rw-r--r--stdlib/source/test/lux/world/finance/money.lux8
26 files changed, 383 insertions, 198 deletions
diff --git a/documentation/bookmark/compilation/target/c++.md b/documentation/bookmark/compilation/target/c++.md
index 1a82f8212..c31acb441 100644
--- a/documentation/bookmark/compilation/target/c++.md
+++ b/documentation/bookmark/compilation/target/c++.md
@@ -59,12 +59,16 @@
# String
-0. []()
0. [CsString (intro to unicode)](https://www.youtube.com/watch?v=nYzi0-VAXQM)
0. [CsString (library design)](https://www.youtube.com/watch?v=w_kD-qAkoH0)
0. [char8_t](https://www.youtube.com/watch?v=vOOLXvu-xtU)
0. [std::u32string](https://www.cplusplus.com/reference/string/u32string/)
+# Integer
+
+0. [Fixed width integer types (since C++11)](https://en.cppreference.com/w/cpp/types/integer)
+0. [Standard library header <cstdint> (C++11)](https://en.cppreference.com/w/cpp/header/cstdint)
+
# Variadic functions
0. []()
diff --git a/lux-c++/source/program.lux b/lux-c++/source/program.lux
index 6bfa65d4f..cb2b96029 100644
--- a/lux-c++/source/program.lux
+++ b/lux-c++/source/program.lux
@@ -11,10 +11,7 @@
["[0]" maybe (.use "[1]#[0]" monad)]
["[0]" try (.only Try)]
["[0]" exception (.only Exception)]
- ["[0]" io (.only IO io)]
- ["[0]" function]
- [concurrency
- ["[0]" async (.only Async)]]]
+ ["[0]" io (.only IO io)]]
[data
["[0]" product]
[text
@@ -32,8 +29,8 @@
["[0]" file]
["[1]/[0]" environment]]
[meta
- ["@" target (.only)
- ["_" js]]
+ [target
+ ["_" c++]]
[macro
["^" pattern]
["[0]" template]]
@@ -54,9 +51,8 @@
["[1]" js]]]
[translation
["[0]" reference]
- ["[0]" js (.only)
- ["[0]" runtime]
- ["[1]/[0]" reference]]]]]]
+ [c++
+ ["[0]" primitive]]]]]]
[default
["[0]" platform (.only Platform)]]
[meta
@@ -74,10 +70,22 @@
("static" cppdef [Text] "io" Bit)
("static" gbl (ffi.Object Any)))
+(def (print it)
+ (-> _.Expression
+ Text)
+ (%.format "std::cout << "
+ (_.code it)
+ " << std::endl;"))
+
(def _
(program []
(do io.monad
- [? (cppyy::cppdef ["void say_hello() { std::cout << 123 << std::endl; }"])
+ [? (cppyy::cppdef [(%.format "void say_hello() { "
+ (print (primitive.bit true))
+ (print (primitive.i64 +123))
+ (print (primitive.f64 -456.789))
+ (print (primitive.text "YOLO"))
+ " }")])
.let [_ (debug.log! (%.format "BEFORE " (%.bit ?)))]
global (cppyy::gbl)
.let [say_hello (as ffi.Function
diff --git a/lux-lua/source/program.lux b/lux-lua/source/program.lux
index a1760781c..8f2017512 100644
--- a/lux-lua/source/program.lux
+++ b/lux-lua/source/program.lux
@@ -34,7 +34,6 @@
["@" target (.only)
["_" lua]]
["[0]" compiler
- ["[0]" phase (.only Operation Phase)]
[reference
[variable (.only Register)]]
[language
@@ -43,7 +42,7 @@
[translation (.only Host)]
[analysis
[macro (.only Expander)]]
- [phase
+ ["[0]" phase (.only Operation Phase)
["[0]" extension (.only Extender Handler)
["[0]" analysis
["[1]" lua]]
diff --git a/stdlib/source/library/lux/control/security/policy.lux b/stdlib/source/library/lux/control/security/policy.lux
index 517d60638..9d8059b01 100644
--- a/stdlib/source/library/lux/control/security/policy.lux
+++ b/stdlib/source/library/lux/control/security/policy.lux
@@ -13,10 +13,12 @@
value
(type .public (Can_Upgrade brand label value)
- (-> value (Policy brand value label)))
+ (-> value
+ (Policy brand value label)))
(type .public (Can_Downgrade brand label value)
- (-> (Policy brand value label) value))
+ (-> (Policy brand value label)
+ value))
(type .public (Privilege brand label)
(Record
@@ -51,9 +53,11 @@
(context ..privilege))
(def (of_policy constructor)
- (-> Type Type)
+ (-> Type
+ Type)
(type_literal (All (_ brand label)
- (constructor (All (_ value) (Policy brand value label))))))
+ (constructor (All (_ value)
+ (Policy brand value label))))))
(def .public functor
(, (..of_policy Functor))
diff --git a/stdlib/source/library/lux/ffi.lux b/stdlib/source/library/lux/ffi.lux
index 0ad5a846f..261e555ba 100644
--- a/stdlib/source/library/lux/ffi.lux
+++ b/stdlib/source/library/lux/ffi.lux
@@ -1,6 +1,6 @@
(.require
[library
- [lux (.except Symbol Alias Global Declaration global function type_of undefined)
+ [lux (.except Symbol Alias Global Declaration global function type_of undefined alias)
[abstract
["[0]" monad (.only do)]]
[control
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lua.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lua.lux
index 06a60ef41..092ca0575 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lua.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lua.lux
@@ -23,10 +23,9 @@
[///
["[0]" extension]
[//
+ ["[0]" phase]
["[0]" analysis (.only Analysis Operation Phase Handler Bundle)
- ["[1]/[0]" type]]
- [///
- ["[0]" phase]]]]])
+ ["[1]/[0]" type]]]]])
(def Nil
(for @.lua ffi.Nil
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/common.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/common.lux
index 31f782b48..e9a458146 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/common.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/common.lux
@@ -40,11 +40,10 @@
["[1][0]" loop]
["[1][0]" function]]]
[//
+ ["[0]" phase (.use "[1]#[0]" monad)]
["[0]" translation]
["[0]" synthesis (.only %synthesis)
- ["?[1]" \\parser (.only Parser)]]
- [///
- ["[0]" phase (.use "[1]#[0]" monad)]]]])
+ ["?[1]" \\parser (.only Parser)]]]])
(def .public (custom [parser handler])
(All (_ s)
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/host.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/host.lux
index b69079a05..d27a45487 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/host.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/translation/lua/host.lux
@@ -27,11 +27,10 @@
["[1][0]" runtime (.only Operation Phase Handler Bundle
with_vars)]]]
["/[1]" //
+ ["[0]" phase]
["[0]" translation]
[synthesis
- ["<s>" \\parser (.only Parser)]]
- ["//[1]" ///
- ["[1][0]" phase]]]]])
+ ["<s>" \\parser (.only Parser)]]]]])
(def array::new
(Unary Expression)
@@ -67,7 +66,7 @@
(custom
[(all <>.and <s>.text <s>.any)
(function (_ phase archive [fieldS objectS])
- (do ////////phase.monad
+ (do phase.monad
[objectG (phase archive objectS)]
(in (_.the fieldS objectG))))]))
@@ -76,7 +75,7 @@
(custom
[(all <>.and <s>.text <s>.any (<>.some <s>.any))
(function (_ phase archive [methodS objectS inputsS])
- (do [! ////////phase.monad]
+ (do [! phase.monad]
[objectG (phase archive objectS)
inputsG (monad.each ! (phase archive) inputsS)]
(in (_.do methodS inputsG objectG))))]))
@@ -103,7 +102,7 @@
(custom
[<s>.any
(function (_ phase archive inputS)
- (do [! ////////phase.monad]
+ (do [! phase.monad]
[inputG (phase archive inputS)]
(in (<| (_.apply (list inputG))
(_.closure (list $input))
@@ -115,7 +114,7 @@
(custom
[<s>.any
(function (_ phase archive inputS)
- (do [! ////////phase.monad]
+ (do [! phase.monad]
[inputG (phase archive inputS)]
(in (_.apply (list (_.apply (list inputG)
(_.var "table.unpack")))
@@ -131,13 +130,13 @@
(custom
[<s>.text
(function (_ phase archive name)
- (of ////////phase.monad in (_.var name)))]))
+ (of phase.monad in (_.var name)))]))
(def lua::apply
(custom
[(all <>.and <s>.any (<>.some <s>.any))
(function (_ phase archive [abstractionS inputsS])
- (do [! ////////phase.monad]
+ (do [! phase.monad]
[abstractionG (phase archive abstractionS)
inputsG (monad.each ! (phase archive) inputsS)]
(in (_.apply inputsG abstractionG))))]))
@@ -146,7 +145,7 @@
(custom
[(all <>.and <s>.any <s>.any)
(function (_ phase archive [powerS baseS])
- (do [! ////////phase.monad]
+ (do [! phase.monad]
[powerG (phase archive powerS)
baseG (phase archive baseS)]
(in (_.^ powerG baseG))))]))
@@ -155,14 +154,14 @@
(custom
[<s>.text
(function (_ phase archive module)
- (of ////////phase.monad in
+ (of phase.monad in
(_.require/1 (_.string module))))]))
(def lua::function
(custom
[(all <>.and <s>.i64 <s>.any)
(function (_ phase archive [arity abstractionS])
- (do [! ////////phase.monad]
+ (do [! phase.monad]
[abstractionG (phase archive abstractionS)
.let [variable (is (-> Text (Operation Var))
(|>> translation.symbol
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/primitive.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/primitive.lux
new file mode 100644
index 000000000..6deddbdd5
--- /dev/null
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/c++/primitive.lux
@@ -0,0 +1,28 @@
+(.require
+ [library
+ [lux (.except i64)
+ [meta
+ [target
+ ["_" c++ (.only Literal Expression)]]]]])
+
+(def .public bit
+ (-> Bit
+ Literal)
+ _.bool)
+
+(def .public i64
+ (-> (I64 Any)
+ Expression)
+ (|>> .int
+ _.int
+ _.int64_t))
+
+(def .public f64
+ (-> Frac
+ Literal)
+ _.double)
+
+(def .public text
+ (-> Text
+ Literal)
+ _.u32string)
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux
index 5c9677bb7..db64e3fa0 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux
@@ -17,23 +17,23 @@
["_" bytecode (.only Bytecode)]
["[0]" type]
[encoding
- ["[0]" signed]]]]]]]
- ["[0]" //
- ["[1][0]" runtime]])
+ ["[0]" signed]]]]]]])
(def $Boolean (type.class "java.lang.Boolean" (list)))
(def $Long (type.class "java.lang.Long" (list)))
(def $Double (type.class "java.lang.Double" (list)))
(def .public (bit value)
- (-> Bit (Bytecode Any))
+ (-> Bit
+ (Bytecode Any))
(_.getstatic $Boolean (if value "TRUE" "FALSE") $Boolean))
(def wrap_i64
(_.invokestatic $Long "valueOf" (type.method [(list) (list type.long) $Long (list)])))
(def .public (i64 value)
- (-> (I64 Any) (Bytecode Any))
+ (-> (I64 Any)
+ (Bytecode Any))
(when (.int value)
(^.with_template [<int> <instruction>]
[<int>
@@ -83,14 +83,21 @@
(import java/lang/Double
"[1]::[0]"
- ("static" doubleToRawLongBits "manual" [double] int))
+ ("static" doubleToRawLongBits [double] long))
+
+(def double_bits
+ (-> Frac
+ Int)
+ (|>> java/lang/Double::doubleToRawLongBits
+ ffi.of_long))
(def d0_bits
Int
- (java/lang/Double::doubleToRawLongBits +0.0))
+ (double_bits +0.0))
(def .public (f64 value)
- (-> Frac (Bytecode Any))
+ (-> Frac
+ (Bytecode Any))
(when value
(^.with_template [<int> <instruction>]
[<int>
@@ -122,10 +129,11 @@
[+5.0 _.iconst_5])
_
- (let [constantI (if (i.= ..d0_bits
- (java/lang/Double::doubleToRawLongBits (as java/lang/Double value)))
+ (let [constantI (if (|> value
+ ..double_bits
+ (i.= ..d0_bits))
_.dconst_0
- (_.double value))]
+ (_.double (as java/lang/Double value)))]
(do _.monad
[_ constantI]
..wrap_f64))))
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua.lux
index b39309d74..3f428775f 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua.lux
@@ -27,9 +27,9 @@
["[1]/[0]" common]]]]
["/[1]" //
[analysis (.only)]
+ ["[0]" phase (.use "[1]#[0]" monad)]
["[0]" synthesis]
- ["//[1]" ///
- ["[1][0]" phase (.use "[1]#[0]" monad)]
+ [///
[reference (.only)
[variable (.only)]]]]]]])
@@ -41,7 +41,7 @@
(when synthesis
(^.with_template [<tag> <translator>]
[(<tag> @ value)
- (//////phase#in (<translator> value))])
+ (phase#in (<translator> value))])
([synthesis.bit /primitive.bit]
[synthesis.i64 /primitive.i64]
[synthesis.f64 /primitive.f64]
@@ -75,7 +75,7 @@
(/loop.scope ///extension/common.statement expression archive scope)
(synthesis.loop/again @ updates)
- (//////phase.except ..cannot_recur_as_an_expression [])
+ (phase.except ..cannot_recur_as_an_expression [])
(synthesis.function/abstraction @ abstraction)
(/function.function ///extension/common.statement expression archive abstraction)
diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux
index 2ff224e3b..78741fe06 100644
--- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux
+++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux
@@ -250,14 +250,26 @@
(runtime
(lux//try risky)
- (with_vars [success value]
- (all _.then
- (_.let (list success value) (|> risky (_.apply (list ..unit))
- _.return (_.closure (list))
- list _.apply (|> (_.var "pcall"))))
- (_.if success
- (_.return (..right value))
- (_.return (..left value))))))
+ (let [closure (|> risky
+ (_.apply (list ..unit))
+ _.return
+ (_.closure (list)))
+ $debug (_.var "debug")
+ $xpcall (_.var "xpcall")]
+ (with_vars [success value]
+ (_.if (_.and $debug $xpcall)
+ (all _.then
+ (_.let (list success value) (_.apply (list closure (_.the "traceback" $debug))
+ $xpcall))
+ (_.if success
+ (_.return (..right value))
+ (_.return (..left value))))
+ (all _.then
+ (_.let (list success value) (_.apply (list closure)
+ (_.var "pcall")))
+ (_.if success
+ (_.return (..right value))
+ (_.return (..left value))))))))
(runtime
(lux//program_args raw)
diff --git a/stdlib/source/library/lux/meta/target/c++.lux b/stdlib/source/library/lux/meta/target/c++.lux
new file mode 100644
index 000000000..b8c2414f4
--- /dev/null
+++ b/stdlib/source/library/lux/meta/target/c++.lux
@@ -0,0 +1,114 @@
+(.require
+ [library
+ [lux (.except Code Type int)
+ [control
+ ["|" pipe]]
+ [data
+ ["[0]" text (.only)
+ ["%" \\format]]
+ [collection
+ ["[0]" list (.use "[1]#[0]" functor)]]]
+ [math
+ [number
+ ["f" frac]]]
+ [meta
+ [macro
+ ["[0]" template]]
+ [type
+ ["[0]" nominal]]]]])
+
+(nominal.def .public (Code of)
+ Text
+
+ (def .public code
+ (-> (Code Any)
+ Text)
+ (|>> nominal.representation))
+
+ (with_template [<type> <super>+]
+ [(with_expansions [<of> (template.symbol [<type> "'"])]
+ (nominal.def (<of> of)
+ Any)
+ (`` (type .public <type>
+ (|> Any <of> (,, (template.spliced <super>+))))))]
+
+ [Type [Code]]
+ [Expression [Code]]
+ [Computation [Expression' Code]]
+ )
+
+ (with_template [<type> <super>+]
+ [(with_expansions [<brand> (template.symbol [<type> "'"])]
+ (nominal.def <brand> Any)
+ (`` (type .public <type> (|> <brand> (,, (template.spliced <super>+))))))]
+
+ [Literal [Computation' Expression' Code]]
+ )
+
+ (def .public bool
+ (-> Bit
+ Literal)
+ (|>> (|.when
+ .false "false"
+ .true "true")
+ nominal.abstraction))
+
+ (def .public double
+ (-> Frac
+ Literal)
+ (|>> (|.cond [(f.= f.positive_infinity)]
+ [(|.new "(+1.0/0.0)" [])]
+
+ [(f.= f.negative_infinity)]
+ [(|.new "(-1.0/0.0)" [])]
+
+ [(f.= f.not_a_number)]
+ [(|.new "(0.0/0.0)" [])]
+
+ ... else
+ [%.frac])
+ nominal.abstraction))
+
+ (def .public (cast type term)
+ (-> Type Expression
+ Computation)
+ (nominal.abstraction
+ (%.format "(" (nominal.representation type) ")"
+ " " (nominal.representation term))))
+
+ (def .public int
+ (-> Int
+ Literal)
+ (|>> %.int
+ nominal.abstraction))
+
+ (def .public (on parameters function)
+ (-> (List Expression) Expression
+ Expression)
+ (nominal.abstraction
+ (%.format (nominal.representation function)
+ "("
+ (|> parameters
+ (list#each (|>> nominal.representation))
+ (text.interposed ", "))
+ ")")))
+
+ ... https://en.cppreference.com/w/cpp/types/integer
+ (with_template [<name>]
+ [(def .public (<name> it)
+ (-> Expression
+ Expression)
+ (..on (list it)
+ (nominal.abstraction (template.text [<name>]))))]
+
+ [int64_t]
+ )
+
+ ... https://en.cppreference.com/w/cpp/string/basic_string
+ (def .public u32string
+ (-> Text
+ Literal)
+ (|>> %.text
+ (%.format "U")
+ nominal.abstraction))
+ )
diff --git a/stdlib/source/library/lux/meta/target/lua.lux b/stdlib/source/library/lux/meta/target/lua.lux
index 84a566839..bc5ead9aa 100644
--- a/stdlib/source/library/lux/meta/target/lua.lux
+++ b/stdlib/source/library/lux/meta/target/lua.lux
@@ -6,7 +6,7 @@
[hash (.only Hash)]
["[0]" enum]]
[control
- ["[0]" pipe]]
+ ["|" pipe]]
[data
["[0]" text (.only)
["%" \\format (.only format)]]
@@ -91,7 +91,7 @@
(def .public boolean
(-> Bit Literal)
- (|>> (pipe.when
+ (|>> (|.when
#0 "false"
#1 "true")
abstraction))
@@ -108,17 +108,17 @@
(def .public float
(-> Frac Literal)
- (|>> (pipe.cond [(f.= f.positive_infinity)]
- [(pipe.new "(1.0/0.0)" [])]
-
- [(f.= f.negative_infinity)]
- [(pipe.new "(-1.0/0.0)" [])]
-
- [(f.= f.not_a_number)]
- [(pipe.new "(0.0/0.0)" [])]
-
- ... else
- [%.frac (text.replaced "+" "")])
+ (|>> (|.cond [(f.= f.positive_infinity)]
+ [(|.new "(1.0/0.0)" [])]
+
+ [(f.= f.negative_infinity)]
+ [(|.new "(-1.0/0.0)" [])]
+
+ [(f.= f.not_a_number)]
+ [(|.new "(0.0/0.0)" [])]
+
+ ... else
+ [%.frac (text.replaced "+" "")])
abstraction))
(def safe
diff --git a/stdlib/source/specification/lux/world/console.lux b/stdlib/source/specification/lux/world/console.lux
deleted file mode 100644
index c941d4da7..000000000
--- a/stdlib/source/specification/lux/world/console.lux
+++ /dev/null
@@ -1,60 +0,0 @@
-(.require
- [library
- [lux (.except)
- [abstract
- [monad (.only do)]]
- [control
- [io (.only IO)]
- ["[0]" try]
- [concurrency
- ["[0]" async (.only Async)]]]
- [data
- ["[0]" text (.only)
- ["%" \\format (.only format)]]]
- [math
- ["[0]" random]]
- [test
- ["_" property (.only Test)]
- ["[0]" unit]]]]
- [\\library
- ["[0]" /]])
-
-(def .public (spec console)
- (-> (IO (/.Console Async)) Test)
- (do random.monad
- [message (random.alphabetic 10)]
- (in (do async.monad
- [console (async.future console)
- ?write (of console write (format message text.new_line))
- ?read (of console read [])
- ?read_line (of console read_line [])
- ?close/good (of console close [])
- ?close/bad (of console close [])
-
- .let [can_write!
- (when ?write
- {try.#Success _}
- true
-
- _
- false)
-
- can_read!
- (when [?read ?read_line]
- [{try.#Success _} {try.#Success _}]
- true
-
- _
- false)
-
- can_close!
- (when [?close/good ?close/bad]
- [{try.#Success _} {try.#Failure _}]
- true
-
- _
- false)]]
- (unit.coverage [/.Console]
- (and can_write!
- can_read!
- can_close!))))))
diff --git a/stdlib/source/specification/lux/world/environment.lux b/stdlib/source/specification/lux/world/environment.lux
deleted file mode 100644
index 1a586c554..000000000
--- a/stdlib/source/specification/lux/world/environment.lux
+++ /dev/null
@@ -1,34 +0,0 @@
-(.require
- [library
- [lux (.except)
- [abstract
- [monad (.only do)]]
- [control
- ["[0]" try]
- [concurrency
- ["[0]" async (.only Async)]]]
- [data
- ["[0]" text]
- [collection
- ["[0]" dictionary]
- ["[0]" list]]]
- [math
- ["[0]" random]]
- [test
- ["_" property (.only Test)]
- ["[0]" unit]]]]
- [\\library
- ["[0]" /]])
-
-(def .public (spec subject)
- (-> (/.Environment Async) Test)
- (do random.monad
- [exit random.int]
- (in (do [! async.monad]
- [environment (/.environment ! subject)]
- (unit.coverage [/.Environment]
- (and (not (dictionary.empty? environment))
- (list.every? (|>> text.empty? not)
- (dictionary.keys environment))
- (not (text.empty? (of subject home)))
- (not (text.empty? (of subject directory)))))))))
diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux
index bda6c17fc..be6350aa8 100644
--- a/stdlib/source/test/lux.lux
+++ b/stdlib/source/test/lux.lux
@@ -6,7 +6,6 @@
[monad (.only do)]]
[control
["[0]" io]
- ["[0]" try]
["[0]" maybe (.use "[1]#[0]" functor)]
[concurrency
["[0]" atom (.only Atom)]]]
diff --git a/stdlib/source/test/lux/control/security/policy.lux b/stdlib/source/test/lux/control/security/policy.lux
index 59f6968e3..0919d422a 100644
--- a/stdlib/source/test/lux/control/security/policy.lux
+++ b/stdlib/source/test/lux/control/security/policy.lux
@@ -92,7 +92,10 @@
(_.for [/.monad]
(monadT.spec (..injection (of policy_0 #can_upgrade)) (..comparison (of policy_0 #can_downgrade)) /.monad))))
- (_.coverage [/.Privilege /.Context /.with_policy]
+ (_.coverage [/.Privilege
+ /.#can_upgrade /.#can_downgrade
+
+ /.Context /.with_policy]
(and (of policy_0 = password password)
(n.= (of text.hash hash raw_password)
(of policy_0 hash password))))
diff --git a/stdlib/source/test/lux/meta.lux b/stdlib/source/test/lux/meta.lux
index 477d1e31e..1043b77c2 100644
--- a/stdlib/source/test/lux/meta.lux
+++ b/stdlib/source/test/lux/meta.lux
@@ -57,8 +57,6 @@
["[1][0]" compiler
... ["[1]/[0]" phase]
... ["[1]/[0]" meta
- ... ["[1]/[0]" cli]
- ... ["[1]/[0]" export]
... ["[1]/[0]" import]
... ["[1]/[0]" context]
... ["[1]/[0]" cache]]
@@ -1067,8 +1065,6 @@
/global.test
/compiler.test
- ... /compiler/meta/cli.test
- ... /compiler/meta/export.test
... /compiler/meta/import.test
... /compiler/meta/context.test
... /compiler/meta/cache.test
diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/phase.lux b/stdlib/source/test/lux/meta/compiler/language/lux/phase.lux
index c0ceabbd7..ce1def236 100644
--- a/stdlib/source/test/lux/meta/compiler/language/lux/phase.lux
+++ b/stdlib/source/test/lux/meta/compiler/language/lux/phase.lux
@@ -28,7 +28,8 @@
["[0]" /
["[1][0]" translation
["[1]/[0]" jvm
- ["[1]/[0]" host]]]])
+ ["[1]/[0]" host]
+ ["[1]/[0]" primitive]]]])
(def (injection value)
(All (_ of)
@@ -213,4 +214,5 @@
..test|phase)
/translation/jvm/host.test
+ /translation/jvm/primitive.test
)))
diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux b/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux
index c311d107a..698a6d326 100644
--- a/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux
+++ b/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/host.lux
@@ -14,8 +14,7 @@
[meta
[target
[jvm
- ["[0]" bytecode]
- ["[0]" type]]]]
+ ["[0]" bytecode]]]]
[test
["_" property (.only Test)]]]]
[\\library
@@ -25,9 +24,7 @@
Test
(<| (_.covering /._)
(do [! random.monad]
- [$module random.nat
- $artifact random.nat
- .let [$unit [$module $artifact]]
+ [.let [$unit [0 0]]
expected (random.upper_cased 1)])
(all _.and
(_.coverage [/.host]
diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux b/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux
new file mode 100644
index 000000000..de32bc4a0
--- /dev/null
+++ b/stdlib/source/test/lux/meta/compiler/language/lux/phase/translation/jvm/primitive.lux
@@ -0,0 +1,51 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]]
+ [control
+ ["[0]" io]
+ ["[0]" try]]
+ [data
+ ["[0]" bit (.use "[1]#[0]" equivalence)]
+ ["[0]" text (.use "[1]#[0]" equivalence)]]
+ [math
+ ["[0]" random (.only Random)]
+ [number
+ ["[0]" int (.use "[1]#[0]" equivalence)]
+ ["[0]" frac (.use "[1]#[0]" equivalence)]]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" / (.only)
+ [//
+ ["[0]" host]]]])
+
+(def .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [expected_bit random.bit
+ expected_i64 random.i64
+ expected_f64 random.frac
+ expected_text (random.lower_cased 1)
+
+ .let [$unit [0 0]]])
+ (`` (all _.and
+ (,, (with_template [<constructor> <expected> <type> <=>]
+ [(_.coverage [<constructor>]
+ (io.run! (do io.monad
+ [[class_loader host] host.host]
+ (in (when (of host evaluate $unit [{.#None} (<constructor> <expected>)])
+ {try.#Success actual}
+ (<=> <expected> (as <type> actual))
+
+ {try.#Failure error}
+ false)))))]
+
+ [/.bit expected_bit Bit bit#=]
+ [/.i64 expected_i64 Int int#=]
+ [/.f64 expected_f64 Frac frac#=]
+ [/.text expected_text Text text#=]
+ ))
+ ))))
diff --git a/stdlib/source/test/lux/meta/compiler/meta.lux b/stdlib/source/test/lux/meta/compiler/meta.lux
index c2d1ac5c6..e127adcbc 100644
--- a/stdlib/source/test/lux/meta/compiler/meta.lux
+++ b/stdlib/source/test/lux/meta/compiler/meta.lux
@@ -15,7 +15,9 @@
["[0]" /]]
["[0]" /
["[1][0]" io]
- ["[1][0]" archive]])
+ ["[1][0]" archive]
+ ["[1][0]" cli]
+ ["[1][0]" export]])
(def .public test
Test
@@ -29,4 +31,6 @@
/io.test
/archive.test
+ /cli.test
+ /export.test
)))
diff --git a/stdlib/source/test/lux/world/console.lux b/stdlib/source/test/lux/world/console.lux
index 7d933d926..4e26b107c 100644
--- a/stdlib/source/test/lux/world/console.lux
+++ b/stdlib/source/test/lux/world/console.lux
@@ -4,20 +4,62 @@
[abstract
[monad (.only do)]]
[control
- ["[0]" io]
+ ["[0]" io (.only IO)]
["[0]" try (.only Try)]
- ["[0]" exception]]
+ ["[0]" exception]
+ [concurrency
+ ["[0]" async (.only Async)]]]
[data
["[0]" text (.use "[1]#[0]" equivalence)
["%" \\format (.only format)]]]
[math
["[0]" random]]
[test
- ["_" property (.only Test)]]]]
+ ["_" property (.only Test)]
+ ["[0]" unit]]]]
[\\library
- ["[0]" /]]
- [\\specification
- ["$[0]" /]])
+ ["[0]" /]])
+
+(def .public (spec console)
+ (-> (IO (/.Console Async))
+ Test)
+ (do random.monad
+ [message (random.alphabetic 10)]
+ (in (do async.monad
+ [console (async.future console)
+ ?write (of console write (format message text.new_line))
+ ?read (of console read [])
+ ?read_line (of console read_line [])
+ ?close/good (of console close [])
+ ?close/bad (of console close [])
+
+ .let [can_write!
+ (when ?write
+ {try.#Success _}
+ true
+
+ _
+ false)
+
+ can_read!
+ (when [?read ?read_line]
+ [{try.#Success _} {try.#Success _}]
+ true
+
+ _
+ false)
+
+ can_close!
+ (when [?close/good ?close/bad]
+ [{try.#Success _} {try.#Failure _}]
+ true
+
+ _
+ false)]]
+ (unit.coverage [/.Console]
+ (and can_write!
+ can_read!
+ can_close!))))))
(exception.def dead)
@@ -54,7 +96,7 @@
(<| (_.covering /._)
(all _.and
(_.for [/.async /.mock /.Mock]
- ($/.spec (io.io (/.async (/.mock ..mock [false ""])))))
+ (..spec (io.io (/.async (/.mock ..mock [false ""])))))
(do random.monad
[expected (random.alphabetic 10)
.let [console (/.mock ..mock [false ""])]]
diff --git a/stdlib/source/test/lux/world/environment.lux b/stdlib/source/test/lux/world/environment.lux
index 8c2484e7b..c6b2e95e2 100644
--- a/stdlib/source/test/lux/world/environment.lux
+++ b/stdlib/source/test/lux/world/environment.lux
@@ -9,7 +9,9 @@
["[0]" io]
["[0]" maybe (.use "[1]#[0]" functor)]
["[0]" try]
- ["[0]" exception]]
+ ["[0]" exception]
+ [concurrency
+ ["[0]" async (.only Async)]]]
[data
["[0]" text (.use "[1]#[0]" equivalence)]
[collection
@@ -20,14 +22,27 @@
[number
["n" nat]]]
[test
- ["_" property (.only Test)]]]]
+ ["_" property (.only Test)]
+ ["[0]" unit]]]]
["[0]" \\parser (.only Environment)]
[\\library
["[0]" / (.only)
[//
- [file (.only Path)]]]]
- [\\specification
- ["$[0]" /]])
+ [file (.only Path)]]]])
+
+(def .public (spec subject)
+ (-> (/.Environment Async)
+ Test)
+ (do random.monad
+ [exit random.int]
+ (in (do [! async.monad]
+ [environment (/.environment ! subject)]
+ (unit.coverage [/.Environment]
+ (and (not (dictionary.empty? environment))
+ (list.every? (|>> text.empty? not)
+ (dictionary.keys environment))
+ (not (text.empty? (of subject home)))
+ (not (text.empty? (of subject directory)))))))))
(def \\parser
Test
@@ -84,7 +99,7 @@
unknown (random.alphabetic 1)]
(all _.and
(_.for [/.mock /.async]
- ($/.spec (/.async (/.mock environment home directory))))
+ (..spec (/.async (/.mock environment home directory))))
(_.coverage [/.environment]
(let [it (/.mock environment home directory)]
(io.run!
diff --git a/stdlib/source/test/lux/world/finance/money.lux b/stdlib/source/test/lux/world/finance/money.lux
index 872414dbf..cc798afdd 100644
--- a/stdlib/source/test/lux/world/finance/money.lux
+++ b/stdlib/source/test/lux/world/finance/money.lux
@@ -90,12 +90,8 @@
(bit#= (/.<= expected_parameter expected_subject)
(/.>= expected_subject expected_parameter)))
))
- (_.coverage [/.units /.sub_units]
- (let [expected (/.money currency.usd expected_amount)
- actual (/.money currency.usd (n.+ (/.units expected)
- (/.sub_units expected)))]
- (/.= expected actual)))
- (_.coverage [/.of_units /.of_sub_units]
+ (_.coverage [/.units /.sub_units
+ /.of_units /.of_sub_units]
(let [expected (/.money currency.usd expected_amount)
actual (/.+ (/.of_units currency.usd (/.units expected))
(/.of_sub_units currency.usd (/.sub_units expected)))]