diff options
author | Eduardo Julian | 2018-12-06 23:04:41 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-12-06 23:04:41 -0400 |
commit | 9f07e772cd9758ca5f4c516e78d50a1db581c910 (patch) | |
tree | 12a736cb76b99972258d79867cf7ee53b0a1b48a /stdlib/source | |
parent | dbcf62dcd86798bc1ce2d3bb9c61dbb189fb8fc9 (diff) |
Adapted other world signatures to the capability model.
Diffstat (limited to 'stdlib/source')
-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 |
4 files changed, 43 insertions, 21 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))) |