Skip to content

Commit

Permalink
Added support for literal syntax for various numeric units.
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed Jan 24, 2024
1 parent 1f2aee6 commit 4f0d129
Show file tree
Hide file tree
Showing 16 changed files with 393 additions and 185 deletions.
14 changes: 10 additions & 4 deletions lux-mode/lux-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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:]")
Expand Down
10 changes: 5 additions & 5 deletions stdlib/source/library/lux/control/maybe.lux
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions stdlib/source/library/lux/control/scope.lux
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions stdlib/source/library/lux/control/writer.lux
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
202 changes: 122 additions & 80 deletions stdlib/source/library/lux/meta/compiler/language/lux/syntax.lux

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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)]]
Expand Down Expand Up @@ -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)]]
<fields>
["BB" new [[index (Index Class)]] [(///index.value index)]]
["BD" anewarray [[index (Index Class)]] [(///index.value index)]]
Expand Down
30 changes: 11 additions & 19 deletions stdlib/source/library/lux/meta/compiler/target/jvm/constant.lux
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

(.using
[library
[lux (.except Double
#Integer
integer)
[lux (.except #Integer)
["[0]" ffi (.only import)]
[abstract
[monad (.only do)]
Expand Down Expand Up @@ -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
Expand All @@ -45,16 +45,10 @@
[encoding
["[1][0]" unsigned]]]])

(import java/lang/Double
"[1]::[0]"
("static" doubleToRawLongBits [double] long))

(template.with [<type> <marker>]
[(every .public <type>
<marker>)]

[Long Integer]
[Double Decimal]
[String (Index UTF8)]
)

Expand All @@ -64,8 +58,6 @@
(`` (|>> (,, (template.spliced <write>))
(,, (template.spliced <injection>)))))]

[long_injection Long [] [binaryF.bits_64]]
[double_injection Double [[] java/lang/Double::doubleToRawLongBits ffi.of_long] [binaryF.bits_64]]
[string_injection String [] [//index.injection]]
)

Expand All @@ -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)}
Expand Down Expand Up @@ -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]
Expand All @@ -122,9 +114,9 @@
... ... #UTF8
... text.equivalence
... ... #Long
... integer.equivalence
... /long.equivalence
... ... #Double
... decimal.equivalence
... /double.equivalence
... ... #Class
... class.equivalence
... ... #String
Expand All @@ -148,8 +140,8 @@
(expansion.let [<constants> (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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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?)))
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down Expand Up @@ -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))))
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

(.using
[library
[lux (.except Double
integer)
[lux (.except integer)
["[0]" ffi]
[abstract
[equivalence (.only Equivalence)]
Expand All @@ -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
Expand Down Expand Up @@ -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]
)

Expand Down
2 changes: 1 addition & 1 deletion stdlib/source/test/lux/control/maybe.lux
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions stdlib/source/test/lux/control/scope.lux
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion stdlib/source/test/lux/control/writer.lux
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 4f0d129

Please sign in to comment.