aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/control
diff options
context:
space:
mode:
authorEduardo Julian2018-07-31 22:54:35 -0400
committerEduardo Julian2018-07-31 22:54:35 -0400
commit428965131e17d101a16e3ca60b3412101e216cd1 (patch)
tree2b74c5241ee117aa581f4ee7301fc1e5f1bfa6a8 /stdlib/source/lux/control
parent97ab1f076ac08992d6b64cd77bc0bef97b3fc50a (diff)
Now implementing box functionality in stdlib instead of the compiler.
Diffstat (limited to 'stdlib/source/lux/control')
-rw-r--r--stdlib/source/lux/control/thread.lux46
1 files changed, 29 insertions, 17 deletions
diff --git a/stdlib/source/lux/control/thread.lux b/stdlib/source/lux/control/thread.lux
index b7aac24d7..2e7942355 100644
--- a/stdlib/source/lux/control/thread.lux
+++ b/stdlib/source/lux/control/thread.lux
@@ -4,29 +4,41 @@
[functor (#+ Functor)]
[apply (#+ Apply)]
[monad (#+ Monad do)]]
+ [data
+ [collection
+ ["." array]]]
+ [type (#+ :share)
+ abstract]
+ [compiler
+ ["." host]]
[io (#+ IO)]])
(type: #export (Thread ! a)
(-> ! a))
-(type: #export (Box t v)
+(abstract: #export (Box t v)
{#.doc "A mutable box holding a value."}
- (#.Primitive "#Box" (#.Cons t (#.Cons v #.Nil))))
-
-(def: #export (box init)
- (All [a] (-> a (All [!] (Thread ! (Box ! a)))))
- (function (_ !)
- ("lux box new" init)))
-
-(def: #export (read box)
- (All [! a] (-> (Box ! a) (Thread ! a)))
- (function (_ !)
- ("lux box read" box)))
-
-(def: #export (write value box)
- (All [a] (-> a (All [!] (-> (Box ! a) (Thread ! Any)))))
- (function (_ !)
- ("lux box write" value box)))
+
+ (Array v)
+
+ (def: #export (box init)
+ (All [a] (-> a (All [!] (Thread ! (Box ! a)))))
+ (function (_ !)
+ (|> (array.new 1)
+ (array.write 0 init)
+ :abstraction)))
+
+ (def: #export (read box)
+ (All [! a] (-> (Box ! a) (Thread ! a)))
+ (function (_ !)
+ (`` (for {(~~ (static host.jvm))
+ ("jvm aaload" (:representation box) 0)}))))
+
+ (def: #export (write value box)
+ (All [a] (-> a (All [!] (-> (Box ! a) (Thread ! Any)))))
+ (function (_ !)
+ (|> box :representation (array.write 0 value) :abstraction)))
+ )
(def: #export (run thread)
(All [a]