diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el index fa4b42bfe0..e9e8b8d9e6 100644 --- a/lux-mode/lux-mode.el +++ b/lux-mode/lux-mode.el @@ -347,18 +347,24 @@ Called by `imenu--generic-function'." ;; https://www.emacswiki.org/emacs/RegularExpression (defconst lux-font-lock-keywords (eval-when-compile - (let* ((natural "[0-9][0-9,]*") + (let* ((unit "[°g%‰‱]") + + (natural "[0-9][0-9,]*") (sign (altRE "-" "\\+")) (integer (concat sign natural)) (decimal_separator "\\.") (revolution (concat decimal_separator natural)) - (decimal (concat integer revolution "\\(\\(e\\|E\\)" integer "\\)?")) + (decimal (concat integer revolution + "\\(\\(e\\|E\\)" integer "\\)?" + unit "?")) (fraction_separator "/") - (fraction (concat natural fraction_separator natural)) - (rational (concat integer fraction_separator natural)) + (fraction (altRE (concat natural fraction_separator natural) + (concat natural unit))) + (rational (altRE (concat integer fraction_separator natural) + (concat integer unit))) (identifier_h|label "#") (identifier_h|type "[:upper:]") diff --git a/stdlib/source/library/lux/control/maybe.lux b/stdlib/source/library/lux/control/maybe.lux index d2eefdc44e..814f2ec096 100644 --- a/stdlib/source/library/lux/control/maybe.lux +++ b/stdlib/source/library/lux/control/maybe.lux @@ -115,12 +115,12 @@ (the .public (with monad) (for_any (_ !) (-> (Monad !) - (Monad (for_any (_ of) - (! (Maybe of)))))) + (Monad (With !)))) (implementation - (the functor - (functor.composite (its monad.functor monad) - ..functor)) + (the (functor it) + (|> it + (of ..functor each) + (of monad each))) (the in (|>> (of ..monad in) diff --git a/stdlib/source/library/lux/control/scope.lux b/stdlib/source/library/lux/control/scope.lux index 84c5013386..21a42cea74 100644 --- a/stdlib/source/library/lux/control/scope.lux +++ b/stdlib/source/library/lux/control/scope.lux @@ -71,11 +71,12 @@ (for_any (_ !) (-> (Monad !) (for_any (_ context) - (Monad (for_any (_ of) - (Scope context (! of))))))) + (Monad (With ! context))))) (implementation - (the functor - (functor.composite ..functor (its monad.functor monad))) + (the (functor it) + (|> it + (of monad each) + (of ..functor each))) (the in (|>> (of monad in) diff --git a/stdlib/source/library/lux/control/writer.lux b/stdlib/source/library/lux/control/writer.lux index 3c0c8face0..c3243e1af8 100644 --- a/stdlib/source/library/lux/control/writer.lux +++ b/stdlib/source/library/lux/control/writer.lux @@ -61,12 +61,12 @@ (the .public (with monoid monad) (for_any (_ ! trace) (-> (Monoid trace) (Monad !) - (Monad (for_any (_ of) - (! (Writer trace of)))))) + (Monad (With ! trace)))) (implementation - (the functor - (functor.composite (its monad.functor monad) - ..functor)) + (the (functor it) + (|> it + (of ..functor each) + (of monad each))) (the in (let [writer (..monad monoid)] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/syntax.lux b/stdlib/source/library/lux/meta/compiler/language/lux/syntax.lux index 23f9d6db81..847dd4054f 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/syntax.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/syntax.lux @@ -47,6 +47,7 @@ [meta ["[0]" symbol] ["[0]" module] + ["[0]" static] ["[0]" code ["<[1]>" \\projection]] [macro @@ -54,6 +55,7 @@ ["[0]" template] ["[0]" expansion]]] [math + ["[0]" unit] [number ["n" natural] ["[0]" integer] @@ -170,7 +172,9 @@ (inlined (input_at start input) (-> Offset Source_Code Text) - (let [end (|> start (!n/+ amount_of_input_shown) (n.min (.text_size# input)))] + (let [end (|> start + (!n/+ amount_of_input_shown) + (n.min (.text_size# input)))] (!clip start end input))) (exception.the .public (unrecognized_input [[file line column] offset input]) @@ -218,7 +222,7 @@ (-> Source (Result of))) -(the !with_character+ +(the with_character (template.macro (_ @source_code_size @source_code @offset @character @else @body) [(if (!i/< (as Integer @source_code_size) (as Integer @offset)) @@ -226,10 +230,6 @@ @body) @else)])) -(the !with_character - (template.macro (_ @source_code @offset @character @else @body) - [(!with_character+ (.text_size# @source_code) @source_code @offset @character @else @body)])) - (the !letE (template.macro (_ ) [(when @@ -406,7 +406,7 @@ (-> Length Offset Location Offset Source_Code (Result Nat)) (loop (next ['end offset]) - (<| (!with_character+ source_code_size source_code 'end 'character (..value where source_code start 'end n.base_10)) + (<| (with_character source_code_size source_code 'end 'character (..value where source_code start 'end n.base_10)) (!if_digit?+ 'character (next (after 'end)) [] @@ -426,30 +426,44 @@ [..positive_sign] [..negative_sign])] - (these (inlined (decimal_projection source_code_size start where offset source_code) + (these (the (decimal_projection source_code_size start where offset source_code) (-> Length Offset Location Offset Source_Code (Result Code)) (loop (again [end offset exponent (static ..no_exponent)]) - (<| (!with_character+ source_code_size source_code end character/0 ) - (!if_digit?+ character/0 - (again (after end) exponent) - - [["e" "E"] - (if (same? (static ..no_exponent) exponent) - (<| (!with_character+ source_code_size source_code (after end) character/1 ) - (`` (.when_char# character/1 - [[] - (<| (!with_character+ source_code_size source_code (!n/+ 2 end) character/2 ) - (!if_digit?+ character/2 - (again (!n/+ 3 end) character/0) - [] - ))] - ... else - ))) - )] - - )))) + (<| (with_character source_code_size source_code end character/0 ) + (`` (`` (!if_digit?+ character/0 + (again (after end) exponent) + + [["e" "E"] + (if (same? (static ..no_exponent) exponent) + (<| (with_character source_code_size source_code (after end) character/1 ) + (`` (.when_char# character/1 + [[] + (<| (with_character source_code_size source_code (!n/+ 2 end) character/2 ) + (!if_digit?+ character/2 + (again (!n/+ 3 end) character/0) + [] + ))] + ... else + ))) + ) + + (,, (template.with [,unit] + [[(,, (static.text (its unit.#suffix ,unit)))] + (<| (!letE [[where' numerator_end source_code'] numerator] (..value where source_code start end decimal.base_10)) + (let [denominator (n.decimal (its unit.#factor ,unit))]) + (..success [where' (after numerator_end) source_code'] + [where {.#Decimal (decimal./ denominator numerator)}]))] + + [unit.degree] + [unit.gradian] + [unit.percentage] + [unit.permille] + [unit.permyriad] + ))] + + )))))) (inlined (as_rational where numerator denominator) (-> Location Integer Natural @@ -469,18 +483,31 @@ (-> Length Offset Location Offset Source_Code (Result Code)) (loop (again [end offset]) - (<| (!with_character+ source_code_size source_code end character ) - (!if_digit?+ character - (again (after end)) - - [[] - (decimal_projection source_code_size start where (after end) source_code) - - [,rational_separator] - (!letE [_ numerator] (..value where source_code start end integer.base_10) - (..rational numerator source_code_size (after end) where source_code))] - - )))) + (<| (with_character source_code_size source_code end character ) + (`` (`` (!if_digit?+ character + (again (after end)) + + [[] + (decimal_projection source_code_size start where (after end) source_code) + + [(,, (static rational.separator))] + (!letE [_ numerator] (..value where source_code start end integer.base_10) + (..rational numerator source_code_size (after end) where source_code)) + + (,, (template.with [,unit] + [[(,, (static.text (its unit.#suffix ,unit)))] + (!letE [[where' numerator_end source_code'] numerator] (..value where source_code start end integer.base_10) + (..success [where' (after numerator_end) source_code'] + (..as_rational where numerator (its unit.#factor ,unit))))] + + [unit.degree] + [unit.gradian] + [unit.percentage] + [unit.permille] + [unit.permyriad] + ))] + + )))))) )) (template.with [ ] @@ -488,7 +515,7 @@ (-> Length Offset Location Offset Source_Code (Result Code)) (loop ( ['end offset]) - (<| (!with_character+ source_code_size source_code 'end 'character (!number_output source_code start 'end )) + (<| (with_character source_code_size source_code 'end 'character (!number_output source_code start 'end )) (!if_digit?+ 'character ( (after 'end)) [] @@ -516,53 +543,67 @@ (Result Code)) (<| (!letE [[where' numerator_end _] numerator] (..natural source_code_size start where offset source_code)) (expansion.let [,natural (!number_output source_code start numerator_end n.base_10 .#Natural)]) - (!with_character source_code numerator_end potential_separator ,natural) - (if (!n/= (`` (character (,, (static fraction.separator)))) - potential_separator) - (..fraction numerator source_code_size (after numerator_end) where' source_code) - ,natural))) + (with_character source_code_size source_code numerator_end potential_separator ,natural) + (`` (`` (.when_char# potential_separator + [[(,, (static fraction.separator))] + (..fraction numerator source_code_size (after numerator_end) where' source_code) + + (,, (template.with [,unit] + [[(,, (static.text (its unit.#suffix ,unit)))] + (..success [where' (after numerator_end) source_code] + (..as_fraction where' numerator (its unit.#factor ,unit)))] + + [unit.degree] + [unit.gradian] + [unit.percentage] + [unit.permille] + [unit.permyriad] + ))] + + ... else + ,natural + ))))) (the !signed_projection (template.macro (_ source_code_size offset where source_code @aliases @end) [(<| (let ['offset/1 (after offset)]) - (!with_character+ source_code_size source_code 'offset/1 'character/1 @end) + (with_character source_code_size source_code 'offset/1 'character/1 @end) (!if_digit? 'character/1 (signed_projection source_code_size offset where (after/2 offset) source_code) - (!full_symbol_projection offset [where (after offset) source_code] where @aliases .#Symbol)))])) + (!full_symbol_projection source_code_size offset [where (after offset) source_code] where @aliases .#Symbol)))])) (expansion.let [ (..success [(revised .#column (|>> (!n/+ (!n/- start end))) where) end source_code] (!clip start end source_code))] - (inlined (symbol_part_projection start where offset source_code) - (-> Offset Location Offset Source_Code + (inlined (symbol_part_projection source_code_size start where offset source_code) + (-> Length Offset Location Offset Source_Code (Result Text)) - (let [source_code_size (.text_size# source_code)] - (loop (again [end offset]) - (<| (!with_character+ source_code_size source_code end character ) - (!if_symbol_character?|tail character - (again (after end)) - )))))) + (loop (again [end offset]) + (<| (with_character source_code_size source_code end character ) + (!if_symbol_character?|tail character + (again (after end)) + ))))) (the !half_symbol_projection - (template.macro (_ @offset @character @module) + (template.macro (_ source_code_size @offset @character @module) [(!if_symbol_character?|head @character - (!letE [source' symbol] (..symbol_part_projection @offset (!forward 1 where) (after @offset) source_code) + (!letE [source' symbol] (..symbol_part_projection source_code_size @offset (!forward 1 where) (after @offset) source_code) (..success source' [@module symbol])) (!failure where @offset source_code))])) (`` (the (short_symbol_projection source_code_size current_module [where offset/0 source_code]) (-> Length module.Name (Projection Symbol)) - (<| (!with_character+ source_code_size source_code offset/0 character/0 - (!end_of_file where offset/0 source_code current_module)) + (<| (with_character source_code_size source_code offset/0 character/0 + (!end_of_file where offset/0 source_code current_module)) (if (!n/= (character (,, (static symbol.separator))) character/0) (<| (let [offset/1 (after offset/0)]) - (!with_character+ source_code_size source_code offset/1 character/1 - (!end_of_file where offset/1 source_code current_module)) - (!half_symbol_projection offset/1 character/1 current_module)) - (!half_symbol_projection offset/0 character/0 (static .prelude)))))) + (with_character source_code_size source_code offset/1 character/1 + (!end_of_file where offset/1 source_code current_module)) + (!half_symbol_projection source_code_size offset/1 character/1 current_module)) + (!half_symbol_projection source_code_size offset/0 character/0 (static .prelude)))))) (the !short_symbol_projection (template.macro (_ source_code_size @current_module @source @where @tag) @@ -570,16 +611,17 @@ (..success source' [@where {@tag symbol}]))])) (expansion.let [ (..success source' ["" simple])] - (`` (the (full_symbol_projection aliases start source) - (-> Aliases Offset (Projection Symbol)) + (`` (the (full_symbol_projection source_code_size aliases start source) + (-> Length Aliases Offset + (Projection Symbol)) (<| (!letE [source' simple] (let [[where offset source_code] source] - (..symbol_part_projection start where offset source_code))) + (..symbol_part_projection source_code_size start where offset source_code))) (let [[where' offset' source_code'] source']) - (!with_character source_code' offset' character/separator ) + (with_character (.text_size# source_code') source_code' offset' character/separator ) (if (!n/= (character (,, (static symbol.separator))) character/separator) (<| (let [offset'' (after offset')]) - (!letE [source'' complex] (..symbol_part_projection offset'' (!forward 1 where') offset'' source_code')) + (!letE [source'' complex] (..symbol_part_projection source_code_size offset'' (!forward 1 where') offset'' source_code')) (if (.text_=# "" complex) (let [[where offset source_code] source] (!failure where offset source_code)) @@ -590,8 +632,8 @@ ))))) (the !full_symbol_projection - (template.macro (_ @offset @source @where @aliases @tag) - [(!letE [source' full_symbol] (..full_symbol_projection @aliases @offset @source) + (template.macro (_ source_code_size @offset @source @where @aliases @tag) + [(!letE [source' full_symbol] (..full_symbol_projection source_code_size @aliases @offset @source) (..success source' [@where {@tag full_symbol}]))])) ... TODO: Grammar macro for specifying syntax. @@ -624,8 +666,8 @@ (exec [] (function (again [where offset/0 source_code]) - (<| (!with_character+ source_code_size source_code offset/0 character/0 - (!end_of_file where offset/0 source_code current_module)) + (<| (with_character source_code_size source_code offset/0 character/0 + (!end_of_file where offset/0 source_code current_module)) (expansion.let [ (template.with [ ] [[(,, (static ))] ( ) @@ -666,8 +708,8 @@ _ (!end_of_file where offset/1 source_code current_module))] (<| (let [offset/1 (after offset/0)]) - (!with_character+ source_code_size source_code offset/1 character/1 - (!end_of_file where offset/1 source_code current_module)) + (with_character source_code_size source_code offset/1 character/1 + (!end_of_file where offset/1 source_code current_module)) (!if_digit? character/1 ... It's a Revolution. @@ -676,8 +718,8 @@ [[(,, (static symbol.separator))] ... It's either a symbol, or a comment. (<| (let [offset/2 (after offset/1)]) - (!with_character+ source_code_size source_code offset/2 character/2 - (!end_of_file where offset/2 source_code current_module)) + (with_character source_code_size source_code offset/2 character/2 + (!end_of_file where offset/2 source_code current_module)) (.when_char# character/2 [[(,, (static symbol.separator))] ... It's a comment. @@ -694,8 +736,8 @@ [(,, (static ..sigil))] (<| (let [offset/1 (after offset/0)]) - (!with_character+ source_code_size source_code offset/1 character/1 - (!end_of_file where offset/1 source_code current_module)) + (with_character source_code_size source_code offset/1 character/1 + (!end_of_file where offset/1 source_code current_module)) (.when_char# character/1 [(,, (template.with [ ] [[] @@ -705,14 +747,14 @@ ["1" #1]))] ... else - (!full_symbol_projection offset/0 [] where aliases .#Symbol)))] + (!full_symbol_projection source_code_size offset/0 [] where aliases .#Symbol)))] ... else (!if_digit? character/0 ... Natural number (..positive source_code_size offset/0 where (after offset/0) source_code) ... Symbol - (!full_symbol_projection offset/0 [] where aliases .#Symbol)) + (!full_symbol_projection source_code_size offset/0 [] where aliases .#Symbol)) ))) ))))) ) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/instruction.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/instruction.lux index 6e3b3886d7..7609219645 100644 --- a/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/instruction.lux +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/bytecode/instruction.lux @@ -40,7 +40,9 @@ [class (.only Class)] [reference (.only Reference)] [integer (.only Integer)] - [float (.only Float)]] + [float (.only Float)] + [long (.only Long)] + ["[2][0]" double]] [encoding ["[1][0]" unsigned (.only U1 U2 U4)] ["[1][0]" signed (.only S1 S2 S4)]] @@ -545,8 +547,8 @@ [["13" ldc_w/integer [[index (Index Integer)]] [(///index.value index)]] ["13" ldc_w/float [[index (Index Float)]] [(///index.value index)]] ["13" ldc_w/string [[index (Index ///constant.String)]] [(///index.value index)]] - ["14" ldc2_w/long [[index (Index ///constant.Long)]] [(///index.value index)]] - ["14" ldc2_w/double [[index (Index ///constant.Double)]] [(///index.value index)]] + ["14" ldc2_w/long [[index (Index Long)]] [(///index.value index)]] + ["14" ldc2_w/double [[index (Index ///double.Double)]] [(///index.value index)]] ["BB" new [[index (Index Class)]] [(///index.value index)]] ["BD" anewarray [[index (Index Class)]] [(///index.value index)]] diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/constant.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/constant.lux index b21da63db6..a955955ac9 100644 --- a/stdlib/source/library/lux/meta/compiler/target/jvm/constant.lux +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/constant.lux @@ -3,9 +3,7 @@ (.using [library - [lux (.except Double - #Integer - integer) + [lux (.except #Integer) ["[0]" ffi (.only import)] [abstract [monad (.only do)] @@ -37,6 +35,8 @@ ["[0]" reference (.only Reference)] ["[1][0]" integer] ["[1][0]" float] + ["[1][0]" long] + ["[1][0]" double] ["/[1]" // ["[1][0]" index (.only Index)] [type @@ -45,16 +45,10 @@ [encoding ["[1][0]" unsigned]]]]) -(import java/lang/Double - "[1]::[0]" - ("static" doubleToRawLongBits [double] long)) - (template.with [ ] [(every .public )] - [Long Integer] - [Double Decimal] [String (Index UTF8)] ) @@ -64,8 +58,6 @@ (`` (|>> (,, (template.spliced )) (,, (template.spliced )))))] - [long_injection Long [] [binaryF.bits_64]] - [double_injection Double [[] java/lang/Double::doubleToRawLongBits ffi.of_long] [binaryF.bits_64]] [string_injection String [] [//index.injection]] ) @@ -74,8 +66,8 @@ {#UTF8 UTF8} {#Integer /integer.Integer} {#Float /float.Float} - {#Long Long} - {#Double Double} + {#Long /long.Long} + {#Double /double.Double} {#Class Class} {#String String} {#Field (Reference //category.Value)} @@ -106,9 +98,9 @@ [#UTF8 text.equivalence] [#Integer /integer.equivalence] - [#Long integer.equivalence] + [#Long /long.equivalence] [#Float /float.equivalence] - [#Double decimal.equivalence] + [#Double /double.equivalence] [#Class class.equivalence] [#String //index.equivalence] [#Field reference.equivalence] @@ -122,9 +114,9 @@ ... ... #UTF8 ... text.equivalence ... ... #Long - ... integer.equivalence + ... /long.equivalence ... ... #Double - ... decimal.equivalence + ... /double.equivalence ... ... #Class ... class.equivalence ... ... #String @@ -148,8 +140,8 @@ (expansion.let [ (these [#UTF8 /tag.utf8 /utf8.injection] [#Integer /tag.integer /integer.as_binary] [#Float /tag.float /float.as_binary] - [#Long /tag.long ..long_injection] - [#Double /tag.double ..double_injection] + [#Long /tag.long /long.as_binary] + [#Double /tag.double /double.as_binary] [#Class /tag.class class.as_binary] [#String /tag.string ..string_injection] [#Field /tag.field reference.as_binary] diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/constant/double.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/constant/double.lux new file mode 100644 index 0000000000..d6bb222671 --- /dev/null +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/constant/double.lux @@ -0,0 +1,43 @@ +... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +(.using + [library + [lux (.except Double) + [abstract + [equivalence (.only Equivalence)]] + [data + ["[0]" binary + ["[1]" \\injection (.only Injection)]]] + [math + ["[0]" random (.only Random)] + [number + ["[0]" decimal]]]]]) + +(every .public Double + Decimal) + +(the .public equivalence + (Equivalence Double) + decimal.equivalence) + +(alias [=] + ..equivalence) + +(the .public as_binary + (Injection Double) + (|>> decimal.bits + binary.bits_64)) + +(the .public positive_zero + Double + +0.0) + +(the .public negative_zero + Double + -0.0) + +(the .public random + (Random Double) + (|> random.decimal + (random.only decimal.number?))) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/constant/float.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/constant/float.lux index 8175d61a71..7b042ef20f 100644 --- a/stdlib/source/library/lux/meta/compiler/target/jvm/constant/float.lux +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/constant/float.lux @@ -13,7 +13,8 @@ [math ["[0]" random (.only Random) (.use "[1]#[0]" functor)] [number - ["[0]" i32]]]]]) + ["[0]" i32] + ["[0]" decimal]]]]]) (ffi.import java/lang/Float "[1]::[0]" @@ -51,5 +52,6 @@ (the .public random (Random Float) - (random#each (|>> ffi.as_float) - random.decimal)) + (|> random.decimal + (random.only decimal.number?) + (random#each (|>> ffi.as_float)))) diff --git a/stdlib/source/library/lux/meta/compiler/target/jvm/constant/pool.lux b/stdlib/source/library/lux/meta/compiler/target/jvm/constant/pool.lux index 74868677eb..a27254af7b 100644 --- a/stdlib/source/library/lux/meta/compiler/target/jvm/constant/pool.lux +++ b/stdlib/source/library/lux/meta/compiler/target/jvm/constant/pool.lux @@ -3,8 +3,7 @@ (.using [library - [lux (.except Double - integer) + [lux (.except integer) ["[0]" ffi] [abstract [equivalence (.only Equivalence)] @@ -30,13 +29,15 @@ [macro ["[0]" expansion] ["[0]" template]]]]] - ["[0]" // (.only String Long Double Constant) + ["[0]" // (.only String Constant) [utf8 (.only UTF8)] ["[0]" name_and_type (.only Name_And_Type)] ["[0]" class (.only Class)] ["[0]" reference (.only Reference)] ["[1][0]" integer] ["[1][0]" float] + ["[1][0]" long] + ["[1][0]" double] [// ["[1][0]" index (.only Index)] [encoding @@ -163,8 +164,8 @@ [integer //integer.Integer //.#Integer //integer.equivalence] [float //float.Float //.#Float //float.equivalence] - [long Long //.#Long integer.equivalence] - [double Double //.#Double decimal.equivalence] + [long //long.Long //.#Long integer.equivalence] + [double //double.Double //.#Double decimal.equivalence] [utf8 UTF8 //.#UTF8 text.equivalence] ) diff --git a/stdlib/source/test/lux/control/maybe.lux b/stdlib/source/test/lux/control/maybe.lux index a1c35c9ca5..eabf59f279 100644 --- a/stdlib/source/test/lux/control/maybe.lux +++ b/stdlib/source/test/lux/control/maybe.lux @@ -59,7 +59,7 @@ right random.natural .let [expected (n.+ left right)]] (let [lifted (/.lifted io.monad)] - (_.coverage [/.with /.lifted] + (_.coverage [/.With /.with /.lifted] (|> (io.value (do (/.with io.monad) [a (lifted (io#in left)) b (in right)] diff --git a/stdlib/source/test/lux/control/scope.lux b/stdlib/source/test/lux/control/scope.lux index 1447c340ba..d80182307d 100644 --- a/stdlib/source/test/lux/control/scope.lux +++ b/stdlib/source/test/lux/control/scope.lux @@ -56,8 +56,8 @@ (n.= (n.* factor sample) (/.value sample (/.local (n.* factor) /.read)))) (let [(open "io#[0]") io.monad] - (_.coverage [/.with /.lifted] - (|> (is (/.Scope Any (IO Natural)) + (_.coverage [/.With /.with /.lifted] + (|> (is (/.With IO Any Natural) (do (/.with io.monad) [a (/.lifted (io#in sample)) b (in factor)] diff --git a/stdlib/source/test/lux/control/writer.lux b/stdlib/source/test/lux/control/writer.lux index 3ed2255c58..1218f91905 100644 --- a/stdlib/source/test/lux/control/writer.lux +++ b/stdlib/source/test/lux/control/writer.lux @@ -58,7 +58,7 @@ (_.coverage [/.write] (text.= trace (its /.#trace (/.write trace)))) - (_.coverage [/.with /.lifted] + (_.coverage [/.With /.with /.lifted] (let [lifted (/.lifted text.monoid io.monad) (open "io#[0]") io.monad] (|> (do (/.with text.monoid io.monad) diff --git a/stdlib/source/test/lux/meta/compiler/language/lux/syntax.lux b/stdlib/source/test/lux/meta/compiler/language/lux/syntax.lux index 86e95dcf79..5c93ef0b5c 100644 --- a/stdlib/source/test/lux/meta/compiler/language/lux/syntax.lux +++ b/stdlib/source/test/lux/meta/compiler/language/lux/syntax.lux @@ -13,8 +13,11 @@ ["[0]" dictionary]]] [math ["[0]" random (.only Random) (.use "[1]#[0]" functor)] + ["[0]" unit] [number ["n" natural] + ["i" integer] + ["d" decimal] ["[0]" fraction (.only) ["[1]T" \\test]] ["[0]" rational (.only) @@ -22,7 +25,9 @@ [meta ["[0]" code] ["[0]" location] - ["[0]" symbol]] + ["[0]" symbol] + [macro + ["[0]" template]]] [test ["_" property (.only Test)]]]] [\\library @@ -82,63 +87,117 @@ (do [! random.monad] [sample code^ expected_fraction fractionT.random - expected_rational rationalT.random] - (all _.and - (_.test "Can parse Lux code." - (when (let [source_code (code.as_text sample)] - (/.parse "" (dictionary.empty text.hash) (text.size source_code) - [location.dummy 0 source_code])) - {.#Left error} - false + expected_rational rationalT.random - {.#Right [_ parsed]} - (of code.equivalence = parsed sample))) - (do ! - [other code^] - (_.test "Can parse multiple Lux code nodes." - (let [source_code (%.message (code.as_text sample) " " (code.as_text other)) - source_code//size (text.size source_code)] - (when (/.parse "" (dictionary.empty text.hash) source_code//size - [location.dummy 0 source_code]) + natural_numerator random.natural + integer_numerator random.integer + decimal_numerator random.safe_decimal] + (`` (all _.and + (_.test "Can parse Lux code." + (when (let [source_code (code.as_text sample)] + (/.parse "" (dictionary.empty text.hash) (text.size source_code) + [location.dummy 0 source_code])) {.#Left error} false - {.#Right [remaining =sample]} - (when (/.parse "" (dictionary.empty text.hash) source_code//size - remaining) - {.#Left error} - false - - {.#Right [_ =other]} - (and (of code.equivalence = sample =sample) - (of code.equivalence = other =other))))))) - (_.coverage [fraction.extension] - (when (let [source_code (of fraction.format injection expected_fraction)] - (/.parse "" (dictionary.empty text.hash) (text.size source_code) - [location.dummy 0 source_code])) - {.#Left _} - false + {.#Right [_ parsed]} + (of code.equivalence = parsed sample))) + (do ! + [other code^] + (_.test "Can parse multiple Lux code nodes." + (let [source_code (%.message (code.as_text sample) " " (code.as_text other)) + source_code//size (text.size source_code)] + (when (/.parse "" (dictionary.empty text.hash) source_code//size + [location.dummy 0 source_code]) + {.#Left error} + false - {.#Right [_ actual]} - (of code.equivalence = - (` ((, (code.symbol [.prelude fraction.extension])) - (, (code.natural (its fraction.#numerator expected_fraction))) - (, (code.natural (its fraction.#denominator expected_fraction))))) - actual))) - (_.coverage [rational.extension] - (when (let [source_code (of rational.format injection expected_rational)] - (/.parse "" (dictionary.empty text.hash) (text.size source_code) - [location.dummy 0 source_code])) - {.#Left _} - false + {.#Right [remaining =sample]} + (when (/.parse "" (dictionary.empty text.hash) source_code//size + remaining) + {.#Left error} + false - {.#Right [_ actual]} - (of code.equivalence = - (` ((, (code.symbol [.prelude rational.extension])) - (, (code.integer (its rational.#numerator expected_rational))) - (, (code.natural (its rational.#denominator expected_rational))))) - actual))) - ))) + {.#Right [_ =other]} + (and (of code.equivalence = sample =sample) + (of code.equivalence = other =other))))))) + (_.coverage [fraction.extension] + (when (let [source_code (of fraction.format injection expected_fraction)] + (/.parse "" (dictionary.empty text.hash) (text.size source_code) + [location.dummy 0 source_code])) + {.#Left _} + false + + {.#Right [_ actual]} + (of code.equivalence = + (` ((, (code.symbol [.prelude fraction.extension])) + (, (code.natural (its fraction.#numerator expected_fraction))) + (, (code.natural (its fraction.#denominator expected_fraction))))) + actual))) + (_.coverage [rational.extension] + (when (let [source_code (of rational.format injection expected_rational)] + (/.parse "" (dictionary.empty text.hash) (text.size source_code) + [location.dummy 0 source_code])) + {.#Left _} + false + + {.#Right [_ actual]} + (of code.equivalence = + (` ((, (code.symbol [.prelude rational.extension])) + (, (code.integer (its rational.#numerator expected_rational))) + (, (code.natural (its rational.#denominator expected_rational))))) + actual))) + (,, (template.with [,unit] + [(_.coverage [,unit] + (and (when (let [source_code (%.message (of n.base_10 injection natural_numerator) + (its unit.#suffix ,unit))] + (/.parse "" (dictionary.empty text.hash) (text.size source_code) + [location.dummy 0 source_code])) + {.#Left _} + false + + {.#Right [_ actual]} + (of code.equivalence = + (` ((, (code.symbol [.prelude fraction.extension])) + (, (code.natural natural_numerator)) + (, (code.natural (its unit.#factor ,unit))))) + actual)) + (when (let [source_code (%.message (of i.base_10 injection integer_numerator) + (its unit.#suffix ,unit))] + (/.parse "" (dictionary.empty text.hash) (text.size source_code) + [location.dummy 0 source_code])) + {.#Left _} + false + + {.#Right [_ actual]} + (of code.equivalence = + (` ((, (code.symbol [.prelude rational.extension])) + (, (code.integer integer_numerator)) + (, (code.natural (its unit.#factor ,unit))))) + actual)) + (when (let [source_code (%.message (of d.base_10 injection decimal_numerator) + (its unit.#suffix ,unit))] + (/.parse "" (dictionary.empty text.hash) (text.size source_code) + [location.dummy 0 source_code])) + {.#Left _} + false + + {.#Right [_ actual]} + (let [expected (code.decimal (d./ (n.decimal (its unit.#factor ,unit)) + decimal_numerator))] + (of code.equivalence = + (code.decimal (d./ (n.decimal (its unit.#factor ,unit)) + decimal_numerator)) + actual))) + ))] + + [unit.degree] + [unit.gradian] + [unit.percentage] + [unit.permille] + [unit.permyriad] + )) + )))) (the comment_text^ (Random Text) diff --git a/stdlib/source/test/lux/meta/compiler/target/jvm.lux b/stdlib/source/test/lux/meta/compiler/target/jvm.lux index 11d2d063e6..ea35a12598 100644 --- a/stdlib/source/test/lux/meta/compiler/target/jvm.lux +++ b/stdlib/source/test/lux/meta/compiler/target/jvm.lux @@ -85,7 +85,8 @@ ["[1][0]" reference] ["[1][0]" integer] ["[1][0]" float] - ["[1][0]" long]]]) + ["[1][0]" long] + ["[1][0]" double]]]) (the method_modifier (all /modifier#composite @@ -1745,4 +1746,5 @@ /integer.test /float.test /long.test + /double.test ))) diff --git a/stdlib/source/test/lux/meta/compiler/target/jvm/constant/double.lux b/stdlib/source/test/lux/meta/compiler/target/jvm/constant/double.lux new file mode 100644 index 0000000000..a414fe1827 --- /dev/null +++ b/stdlib/source/test/lux/meta/compiler/target/jvm/constant/double.lux @@ -0,0 +1,58 @@ +... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +(.using + [library + [lux (.except) + [abstract + [monad (.only do)] + ["[0]" equivalence + ["[1]T" \\test]]] + [data + ["[0]" bit] + ["[0]" binary (.only) + ["![1]" \\injection]]] + [math + ["[0]" random]] + [meta + ["[0]" static]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" /]]) + +(the .public test + Test + (<| (_.covering /._) + (_.for [/.Double /.random]) + (all _.and + (_.for [/.equivalence /.=] + (static.when (same? /.equivalence /.=) + (equivalenceT.spec /.equivalence /.random))) + + (do [! random.monad] + [sample_0 /.random + sample_1 /.random] + (_.coverage [/.as_binary] + (let [both_zeroes! + (or (and (/.= /.positive_zero sample_0) + (/.= /.negative_zero sample_1)) + (and (/.= /.negative_zero sample_0) + (/.= /.positive_zero sample_1))) + + equal_values! + (/.= sample_0 + sample_1) + + equal_binaries! + (binary.= (!binary.value /.as_binary sample_0) + (!binary.value /.as_binary sample_1))] + (or both_zeroes! + (bit.= equal_values! + equal_binaries!))))) + (_.coverage [/.positive_zero /.negative_zero] + (bit.= (/.= /.positive_zero + /.negative_zero) + (not (binary.= (!binary.value /.as_binary /.positive_zero) + (!binary.value /.as_binary /.negative_zero))))) + )))