aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2022-10-23 19:10:49 -0400
committerEduardo Julian2022-10-23 19:10:49 -0400
commit2fce6d44e0b4ada7ea270ff9a890504edbf8e3a3 (patch)
tree7fa035dd99c38400a354d61afb866bca1f4f8a2c /stdlib
parent8c63a525089597af1f9282c76daf97bf2b6058e0 (diff)
New Delay type with associated constants + compile-time warning for undefined computations.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/library/lux.lux9
-rw-r--r--stdlib/source/library/lux/control/concurrency/async.lux10
-rw-r--r--stdlib/source/library/lux/control/concurrency/frp.lux7
-rw-r--r--stdlib/source/library/lux/control/concurrency/structured.lux8
-rw-r--r--stdlib/source/library/lux/control/concurrency/thread.lux21
-rw-r--r--stdlib/source/library/lux/world/net/http/request.lux3
-rw-r--r--stdlib/source/library/lux/world/net/uri.lux7
-rw-r--r--stdlib/source/library/lux/world/net/uri/path.lux25
-rw-r--r--stdlib/source/test/lux/control/concurrency/thread.lux15
-rw-r--r--stdlib/source/test/lux/world/net.lux4
-rw-r--r--stdlib/source/test/lux/world/net/uri/path.lux35
-rw-r--r--stdlib/source/test/lux/world/output/video/resolution.lux25
12 files changed, 137 insertions, 32 deletions
diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux
index e6aae9218..026b11544 100644
--- a/stdlib/source/library/lux.lux
+++ b/stdlib/source/library/lux.lux
@@ -5459,8 +5459,10 @@
[location location
.let [[module line column] location
location (all .text_composite# (text#encoded module) "," (nat#encoded line) "," (nat#encoded column))
- message (all .text_composite# "Undefined behavior @ " location)]]
- (in (list (` (..panic! (, (text$ message)))))))
+ message (all .text_composite# "Undefined behavior at " location)]]
+ (exec
+ (.log# (all .text_composite# "WARNING: " message))
+ (in (list (` (..panic! (, (text$ message))))))))
_
(failure (..wrong_syntax_error (symbol ..undefined)))))))
@@ -5807,7 +5809,8 @@
g!dummy (generated_symbol "g!dummy")]
(when body'
(list body' labels)
- (in (list (recursive_type g!self g!dummy name body') labels))
+ (in (list (recursive_type g!self g!dummy name body')
+ labels))
(list body')
(in (list (recursive_type g!self g!dummy name body')))
diff --git a/stdlib/source/library/lux/control/concurrency/async.lux b/stdlib/source/library/lux/control/concurrency/async.lux
index 75bec2d4b..4285b3b82 100644
--- a/stdlib/source/library/lux/control/concurrency/async.lux
+++ b/stdlib/source/library/lux/control/concurrency/async.lux
@@ -19,7 +19,7 @@
[primitive (.except)]
["[0]" variance (.only Mutable)]]]]]
[//
- ["[0]" thread]
+ ["[0]" thread (.only Delay)]
["[0]" atom (.only Atom atom)]])
(def Value
@@ -202,7 +202,7 @@
left||right))))
(def .public (schedule! milli_seconds computation)
- (All (_ a) (-> Nat (IO a) (Async a)))
+ (All (_ a) (-> Delay (IO a) (Async a)))
(let [[!out resolve] (sharing [a]
(is (IO a)
computation)
@@ -221,14 +221,14 @@
(..schedule! 0))
(def .public (after milli_seconds value)
- (All (_ a) (-> Nat a (Async a)))
+ (All (_ a) (-> Delay a (Async a)))
(..schedule! milli_seconds (io value)))
(def .public (delay milli_seconds)
- (-> Nat (Async Any))
+ (-> Delay (Async Any))
(..after milli_seconds []))
(def .public (within milli_seconds async)
- (All (_ r w) (-> Nat (Async' r w) (Async (Maybe r))))
+ (All (_ r w) (-> Delay (Async' r w) (Async (Maybe r))))
(..or (..delay milli_seconds)
async))
diff --git a/stdlib/source/library/lux/control/concurrency/frp.lux b/stdlib/source/library/lux/control/concurrency/frp.lux
index b5005661a..e5fcac64d 100644
--- a/stdlib/source/library/lux/control/concurrency/frp.lux
+++ b/stdlib/source/library/lux/control/concurrency/frp.lux
@@ -14,6 +14,7 @@
[meta
["[0]" type (.only sharing)]]]]
[//
+ [thread (.only Delay)]
["[0]" atom (.only Atom)]
["[0]" async (.only Async Async') (.use "[1]#[0]" monad)]])
@@ -237,7 +238,7 @@
(def .public (poll milli_seconds action)
(All (_ a)
- (-> Nat (IO a) [(Channel a) (Sink a)]))
+ (-> Delay (IO a) [(Channel a) (Sink a)]))
(let [[output sink] (channel [])]
(exec
(io.run! (loop (again [_ []])
@@ -248,7 +249,7 @@
[output sink])))
(def .public (periodic milli_seconds)
- (-> Nat [(Channel Any) (Sink Any)])
+ (-> Delay [(Channel Any) (Sink Any)])
(..poll milli_seconds (io [])))
(def .public (iterations f init)
@@ -299,7 +300,7 @@
(in {.#End}))))
(def .public (sequential milli_seconds values)
- (All (_ a) (-> Nat (List a) (Channel a)))
+ (All (_ a) (-> Delay (List a) (Channel a)))
(when values
{.#End}
..empty
diff --git a/stdlib/source/library/lux/control/concurrency/structured.lux b/stdlib/source/library/lux/control/concurrency/structured.lux
index 8c0aab11b..69e58c9d0 100644
--- a/stdlib/source/library/lux/control/concurrency/structured.lux
+++ b/stdlib/source/library/lux/control/concurrency/structured.lux
@@ -18,7 +18,7 @@
[primitive (.except)]]]]]
["[0]" //
["[1]" async (.use "[1]#[0]" monad)]
- ["[0]" thread]
+ ["[0]" thread (.only Delay)]
["[0]" atom (.only Atom)]])
(primitive .public (Async value)
@@ -287,7 +287,7 @@
(def .public (schedule! scope milli_seconds action)
(All (_ value)
- (-> (Scope value) Nat (Action value)
+ (-> (Scope value) Delay (Action value)
(Async value)))
(let [[async resolve!] (sharing [value]
(is (Action value)
@@ -324,7 +324,7 @@
(def .public (after scope milli_seconds value)
(All (_ value)
- (-> (Scope value) Nat value
+ (-> (Scope value) Delay value
(Async value)))
(..schedule! scope milli_seconds
(function (_ _)
@@ -332,6 +332,6 @@
(def .public (delay scope milli_seconds)
(All (_ value)
- (-> (Scope value) Nat
+ (-> (Scope value) Delay
(Async Any)))
(..after scope milli_seconds []))
diff --git a/stdlib/source/library/lux/control/concurrency/thread.lux b/stdlib/source/library/lux/control/concurrency/thread.lux
index 1b752dea7..81b2f04c8 100644
--- a/stdlib/source/library/lux/control/concurrency/thread.lux
+++ b/stdlib/source/library/lux/control/concurrency/thread.lux
@@ -116,8 +116,27 @@
{try.#Success _}
[]))
+(type .public Delay
+ Nat)
+
+(def .public milli_second
+ Delay
+ 1)
+
+(with_template [<name> <scale> <base>]
+ [(def .public <name>
+ Delay
+ (n.* <scale> <base>))]
+
+ [second 1,000 milli_second]
+ [minute 60 second]
+ [hour 60 minute]
+ [day 24 hour]
+ [week 7 day]
+ )
+
(def .public (schedule! milli_seconds action)
- (-> Nat (IO Any) (IO Any))
+ (-> Delay (IO Any) (IO Any))
(with_expansions [<jvm> (let [runnable (ffi.object [] [java/lang/Runnable]
[]
(java/lang/Runnable [] (run self []) void
diff --git a/stdlib/source/library/lux/world/net/http/request.lux b/stdlib/source/library/lux/world/net/http/request.lux
index c69666791..26005abe2 100644
--- a/stdlib/source/library/lux/world/net/http/request.lux
+++ b/stdlib/source/library/lux/world/net/http/request.lux
@@ -52,7 +52,8 @@
[blobs (frp.list body)]
(in (at encoding.utf8 decoded (merge blobs)))))
-(def failure (//response.bad_request ""))
+(def failure
+ (//response.bad_request ""))
(def .public (json reader server)
(All (_ a) (-> (<json>.Reader a) (-> a Server) Server))
diff --git a/stdlib/source/library/lux/world/net/uri.lux b/stdlib/source/library/lux/world/net/uri.lux
index 0fb3ff834..c05a9e4d5 100644
--- a/stdlib/source/library/lux/world/net/uri.lux
+++ b/stdlib/source/library/lux/world/net/uri.lux
@@ -1,10 +1,7 @@
(.require
- [library
- [lux (.except)]])
+ [library
+ [lux (.except)]])
... https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
(type .public URI
Text)
-
-(def .public separator
- "/")
diff --git a/stdlib/source/library/lux/world/net/uri/path.lux b/stdlib/source/library/lux/world/net/uri/path.lux
new file mode 100644
index 000000000..f9ee860a3
--- /dev/null
+++ b/stdlib/source/library/lux/world/net/uri/path.lux
@@ -0,0 +1,25 @@
+(.require
+ [library
+ [lux (.except)
+ [data
+ [text
+ ["%" \\format]]
+ [collection
+ ["[0]" list (.use "[1]#[0]" mix)]]]]])
+
+(type .public Segment
+ Text)
+
+... https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
+(type .public Path
+ Text)
+
+(def .public separator
+ Text
+ "/")
+
+(def .public path
+ (-> (List Segment) Path)
+ (list#mix (function (_ head tail)
+ (%.format ..separator head tail))
+ ""))
diff --git a/stdlib/source/test/lux/control/concurrency/thread.lux b/stdlib/source/test/lux/control/concurrency/thread.lux
index 1dccae97f..8b2280e69 100644
--- a/stdlib/source/test/lux/control/concurrency/thread.lux
+++ b/stdlib/source/test/lux/control/concurrency/thread.lux
@@ -52,4 +52,19 @@
(n.= expected actual)]
(and expected_delay!
correct_value!)))))
+ (_.for [/.Delay]
+ (`` (all _.and
+ (,, (with_template [<delay> <duration>]
+ [(_.coverage [<delay>]
+ (i.= (duration.millis <duration>)
+ (.int <delay>)))]
+
+ [/.milli_second duration.milli_second]
+ [/.second duration.second]
+ [/.minute duration.minute]
+ [/.hour duration.hour]
+ [/.day duration.day]
+ [/.week duration.week]
+ ))
+ )))
))))
diff --git a/stdlib/source/test/lux/world/net.lux b/stdlib/source/test/lux/world/net.lux
index 252c6e077..53788fd79 100644
--- a/stdlib/source/test/lux/world/net.lux
+++ b/stdlib/source/test/lux/world/net.lux
@@ -16,7 +16,8 @@
["[1]/[0]" status]
["[1]/[0]" version]]
["[1][0]" uri
- ["[1]/[0]" scheme]]])
+ ["[1]/[0]" scheme]
+ ["[1]/[0]" path]]])
(def .public test
Test
@@ -39,4 +40,5 @@
/http/version.test
/uri/scheme.test
+ /uri/path.test
)))
diff --git a/stdlib/source/test/lux/world/net/uri/path.lux b/stdlib/source/test/lux/world/net/uri/path.lux
new file mode 100644
index 000000000..1a6c15a53
--- /dev/null
+++ b/stdlib/source/test/lux/world/net/uri/path.lux
@@ -0,0 +1,35 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]]
+ [data
+ ["[0]" text]
+ [collection
+ ["[0]" list]]]
+ [math
+ ["[0]" random (.only Random)]
+ [number
+ ["n" nat]]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" /]])
+
+(def .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [segments (at ! each (n.% 10) random.nat)
+ segments (random.list segments (random.lower_case 1))])
+ (_.for [/.Path])
+ (all _.and
+ (_.coverage [/.path /.Segment /.separator]
+ (let [path (/.path segments)]
+ (when (list.size segments)
+ 0 (text.empty? path)
+ _ (and (list.every? (function (_ it)
+ (text.contains? it path))
+ segments)
+ (text.contains? /.separator path)))))
+ )))
diff --git a/stdlib/source/test/lux/world/output/video/resolution.lux b/stdlib/source/test/lux/world/output/video/resolution.lux
index 80add1ed7..c5444497e 100644
--- a/stdlib/source/test/lux/world/output/video/resolution.lux
+++ b/stdlib/source/test/lux/world/output/video/resolution.lux
@@ -55,13 +55,20 @@
Test
(<| (_.covering /._)
(_.for [/.Resolution])
- (all _.and
- (_.for [/.equivalence]
- ($equivalence.spec /.equivalence ..random))
- (_.for [/.hash]
- ($hash.spec /.hash ..random))
+ (`` (all _.and
+ (_.for [/.equivalence]
+ ($equivalence.spec /.equivalence ..random))
+ (_.for [/.hash]
+ ($hash.spec /.hash ..random))
- (_.coverage [<resolutions>]
- (n.= (list.size ..listing)
- (set.size ..catalogue)))
- ))))
+ (_.coverage [<resolutions>]
+ (n.= (list.size ..listing)
+ (set.size ..catalogue)))
+ (,, (with_template [<slot>]
+ [(_.coverage [<slot>]
+ (list.every? (|>> (the <slot>) (n.> 0)) ..listing))]
+
+ [/.#width]
+ [/.#height]
+ ))
+ )))))