diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/world/console.lux | 20 | ||||
-rw-r--r-- | stdlib/source/lux/world/net.lux | 16 | ||||
-rw-r--r-- | stdlib/source/lux/world/net/tcp.jvm.lux | 8 | ||||
-rw-r--r-- | stdlib/source/lux/world/net/udp.jvm.lux | 20 | ||||
-rw-r--r-- | stdlib/test/test/lux/world/net/udp.lux | 4 |
5 files changed, 45 insertions, 23 deletions
diff --git a/stdlib/source/lux/world/console.lux b/stdlib/source/lux/world/console.lux index 99d290479..209063dfd 100644 --- a/stdlib/source/lux/world/console.lux +++ b/stdlib/source/lux/world/console.lux @@ -4,7 +4,8 @@ [monad (#+ do)] ["ex" exception (#+ exception:)] [security - ["." taint (#+ Dirty taint)]]] + ["." taint (#+ Dirty taint)] + [capability (#+ Capability)]]] [data ["." error (#+ Error)] ["." text @@ -25,14 +26,23 @@ [cannot-close] ) +(type: #export (Can-Read ! o) + (Capability [] (! (Error (Dirty o))))) + +(type: #export (Can-Write ! i) + (Capability i (! (Error Any)))) + +(type: #export (Can-Close !) + (Capability [] (! (Error Any)))) + (signature: #export (Console !) - (: (-> Any (! (Error (Dirty Nat)))) + (: (Can-Read ! Nat) read) - (: (-> Any (! (Error (Dirty Text)))) + (: (Can-Read ! Text) read-line) - (: (-> Text (! (Error Any))) + (: (Can-Write ! Text) write) - (: (-> Any (! (Error Any))) + (: (Can-Close !) close)) (def: #export (async console) diff --git a/stdlib/source/lux/world/net.lux b/stdlib/source/lux/world/net.lux index 867430af0..a29df5f84 100644 --- a/stdlib/source/lux/world/net.lux +++ b/stdlib/source/lux/world/net.lux @@ -1,5 +1,10 @@ (.module: - lux) + [lux #* + [data + [error (#+ Error)]] + [control + [security + [capability (#+ Capability)]]]]) (type: #export Address Text) @@ -8,3 +13,12 @@ (type: #export Location {#address Address #port Port}) + +(type: #export (Can-Read ! o) + (Capability Nat (! (Error o)))) + +(type: #export (Can-Write ! i) + (Capability i (! (Error Any)))) + +(type: #export (Can-Close !) + (Capability [] (! (Error Any)))) diff --git a/stdlib/source/lux/world/net/tcp.jvm.lux b/stdlib/source/lux/world/net/tcp.jvm.lux index 329d256e0..add7427cb 100644 --- a/stdlib/source/lux/world/net/tcp.jvm.lux +++ b/stdlib/source/lux/world/net/tcp.jvm.lux @@ -17,7 +17,7 @@ [platform [compiler ["." host]]]] - ["." //]) + ["." // (#+ Can-Read Can-Write Can-Close)]) (import: java/lang/AutoCloseable (close [] #io #try void)) @@ -45,13 +45,13 @@ ############################################################ (signature: #export (TCP !) - (: (-> Nat (! (Error [Nat (Dirty Binary)]))) + (: (Can-Read ! [Nat (Dirty Binary)]) read) - (: (-> Binary (! (Error Any))) + (: (Can-Write ! Binary) write) - (: (-> Any (! (Error Any))) + (: (Can-Close !) close)) (def: #export (async tcp) diff --git a/stdlib/source/lux/world/net/udp.jvm.lux b/stdlib/source/lux/world/net/udp.jvm.lux index 842f1c969..f27ca1c5e 100644 --- a/stdlib/source/lux/world/net/udp.jvm.lux +++ b/stdlib/source/lux/world/net/udp.jvm.lux @@ -20,7 +20,7 @@ [platform [compiler ["." host]]]] - ["." // (#+ Location)]) + ["." // (#+ Location Can-Read Can-Write Can-Close)]) (import: java/lang/AutoCloseable (close [] #io #try void)) @@ -56,23 +56,21 @@ (ex.report ["Address" address])) (signature: #export (UDP !) - (: (-> Nat (! (Error [Nat Location (Dirty Binary)]))) + (: (Can-Read ! [Nat Location (Dirty Binary)]) read) - (: (-> Location Binary (! (Error Any))) + (: (Can-Write ! [Location Binary]) write) - (: (-> Any (! (Error Any))) + (: (Can-Close !) close)) (def: #export (async udp) (-> (UDP IO) (UDP Promise)) - (`` (structure (def: read (|>> (:: udp read) promise.future)) - - (def: (write location data) - (promise.future (:: udp write location data))) - - (def: close (|>> (:: udp close) promise.future))))) + (`` (structure (~~ (do-template [<name>] + [(def: <name> (|>> (:: udp <name>) promise.future))] + + [read] [write] [close]))))) (`` (for {(~~ (static host.jvm)) (as-is (def: (resolve address) @@ -98,7 +96,7 @@ #//.port (.nat (DatagramPacket::getPort packet))} (taint data)])))) - (def: (write location data) + (def: (write [location data]) (do io.Monad<Process> [address (resolve (get@ #//.address location))] (DatagramSocket::send (DatagramPacket::new|send data +0 (.int (binary.size data)) address (.int (get@ #//.port location))) diff --git a/stdlib/test/test/lux/world/net/udp.lux b/stdlib/test/test/lux/world/net/udp.lux index d630816d8..e41082d35 100644 --- a/stdlib/test/test/lux/world/net/udp.lux +++ b/stdlib/test/test/lux/world/net/udp.lux @@ -42,12 +42,12 @@ [server (@.server port) client @.client #################### - _ (:: client write [localhost port] from) + _ (:: client write [[localhost port] from]) [bytes-from [from-address from-port] temp] (:: server read size) #let [from-worked? (and (n/= size bytes-from) (:: binary.Equivalence<Binary> = from (taint.trust temp)))] #################### - _ (:: server write [from-address from-port] to) + _ (:: server write [[from-address from-port] to]) [bytes-to [to-address to-port] temp] (:: client read size) #let [to-worked? (and (n/= size bytes-to) (:: binary.Equivalence<Binary> = to (taint.trust temp)) |