aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/lux/data/text/encoding.lux17
-rw-r--r--stdlib/source/lux/debug.lux14
-rw-r--r--stdlib/source/lux/host.jvm.lux4
-rw-r--r--stdlib/source/lux/host.old.lux87
-rw-r--r--stdlib/source/lux/target/jvm/loader.lux (renamed from stdlib/source/lux/target/jvm/loader.old.lux)6
-rw-r--r--stdlib/source/lux/target/jvm/reflection.lux28
-rw-r--r--stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux22
-rw-r--r--stdlib/source/lux/world/binary.lux34
-rw-r--r--stdlib/source/lux/world/db/jdbc.lux (renamed from stdlib/source/lux/world/db/jdbc.old.lux)0
-rw-r--r--stdlib/source/lux/world/db/jdbc/input.lux (renamed from stdlib/source/lux/world/db/jdbc/input.old.lux)2
-rw-r--r--stdlib/source/lux/world/db/jdbc/output.lux (renamed from stdlib/source/lux/world/db/jdbc/output.old.lux)2
-rw-r--r--stdlib/source/lux/world/environment.lux (renamed from stdlib/source/lux/world/environment.old.lux)0
-rw-r--r--stdlib/source/lux/world/file.lux557
-rw-r--r--stdlib/source/lux/world/net/tcp.lux (renamed from stdlib/source/lux/world/net/tcp.old.lux)4
-rw-r--r--stdlib/source/lux/world/net/udp.lux (renamed from stdlib/source/lux/world/net/udp.old.lux)6
-rw-r--r--stdlib/source/lux/world/shell.lux4
16 files changed, 299 insertions, 488 deletions
diff --git a/stdlib/source/lux/data/text/encoding.lux b/stdlib/source/lux/data/text/encoding.lux
index e1066bbcd..2752903a7 100644
--- a/stdlib/source/lux/data/text/encoding.lux
+++ b/stdlib/source/lux/data/text/encoding.lux
@@ -171,15 +171,14 @@
(|>> :representation))
)
-(`` (for {(~~ (static @.old))
- (as-is (import: #long java/lang/String
- (new [(Array byte) java/lang/String])
- (getBytes [java/lang/String] (Array byte))))
-
- (~~ (static @.jvm))
- (as-is (import: #long java/lang/String
- (new [[byte] java/lang/String])
- (getBytes [java/lang/String] [byte])))}))
+(with-expansions [<for-jvm> (as-is (import: #long java/lang/String
+ (new [[byte] java/lang/String])
+ (getBytes [java/lang/String] [byte])))]
+ (`` (for {(~~ (static @.old))
+ (as-is <for-jvm>)
+
+ (~~ (static @.jvm))
+ (as-is <for-jvm>)})))
(def: #export (to-utf8 value)
(-> Text Binary)
diff --git a/stdlib/source/lux/debug.lux b/stdlib/source/lux/debug.lux
index 43d3f4762..59b35a223 100644
--- a/stdlib/source/lux/debug.lux
+++ b/stdlib/source/lux/debug.lux
@@ -38,13 +38,13 @@
(getClass [] (java/lang/Class java/lang/Object)))
(import: #long java/lang/Integer
- (longValue [] java/lang/Long))
+ (longValue [] long))
(import: #long java/lang/Long
- (intValue [] java/lang/Integer))
+ (intValue [] int))
(import: #long java/lang/Number
- (intValue [] java/lang/Integer)
+ (intValue [] int)
(longValue [] long)
(doubleValue [] double))
@@ -57,12 +57,12 @@
(`` (|> value (~~ (template.splice <processing>))))
#.None)]
- [java/lang/Boolean [%b]]
- [java/lang/String [%t]]
- [java/lang/Long [.int %i]]
+ [java/lang/Boolean [(:coerce .Bit) %b]]
+ [java/lang/String [(:coerce .Text) %t]]
+ [java/lang/Long [(:coerce .Int) %i]]
[java/lang/Number [java/lang/Number::doubleValue %f]]
))
- (case (host.check (Array java/lang/Object) object)
+ (case (host.check [java/lang/Object] object)
(#.Some value)
(let [value (:coerce (Array java/lang/Object) value)]
(case (array.read 0 value)
diff --git a/stdlib/source/lux/host.jvm.lux b/stdlib/source/lux/host.jvm.lux
index 88ffc16f6..d4bc8f3d1 100644
--- a/stdlib/source/lux/host.jvm.lux
+++ b/stdlib/source/lux/host.jvm.lux
@@ -1783,7 +1783,7 @@
"#io means the computation has side effects, and will be wrapped by the IO type."
"These options must show up in the following order [#io #try #?] (although, each option can be used independently)."
(import: java/lang/String
- (new [(Array byte)])
+ (new [[byte]])
(#static valueOf [char] String)
(#static valueOf #as int-valueOf [int] String))
@@ -1792,7 +1792,7 @@
(get [int] e))
(import: (java/util/ArrayList a)
- ([T] toArray [(Array T)] (Array T)))
+ ([T] toArray [[T]] [T]))
"#long makes it so the class-type that is generated is of the fully-qualified name."
"In this case, it avoids a clash between the java.util.List type, and Lux's own List type."
diff --git a/stdlib/source/lux/host.old.lux b/stdlib/source/lux/host.old.lux
index 32bb3887f..5c2ac40d9 100644
--- a/stdlib/source/lux/host.old.lux
+++ b/stdlib/source/lux/host.old.lux
@@ -669,47 +669,48 @@
(def: (generic-type^ imports type-vars)
(-> Class-Imports (List Type-Parameter) (Parser GenericType))
- ($_ p.either
- (do p.monad
- [_ (s.this! (' ?))]
- (wrap (#GenericWildcard #.None)))
- (s.tuple (do p.monad
- [_ (s.this! (' ?))
- bound-kind bound-kind^
- bound (generic-type^ imports type-vars)]
- (wrap (#GenericWildcard (#.Some [bound-kind bound])))))
- (do p.monad
- [name (full-class-name^ imports)
- _ (assert-no-periods name)]
- (if (list.member? text.equivalence (list@map product.left type-vars) name)
- (wrap (#GenericTypeVar name))
- (wrap (#GenericClass name (list)))))
- (s.form (do p.monad
- [name (s.this! (' Array))
- component (generic-type^ imports type-vars)]
- (case component
- (^template [<class> <name>]
- (#GenericClass <name> #.Nil)
- (wrap (#GenericClass <class> (list))))
- (["[Z" "boolean"]
- ["[B" "byte"]
- ["[S" "short"]
- ["[I" "int"]
- ["[J" "long"]
- ["[F" "float"]
- ["[D" "double"]
- ["[C" "char"])
-
- _
- (wrap (#GenericArray component)))))
- (s.form (do p.monad
- [name (full-class-name^ imports)
- _ (assert-no-periods name)
- params (p.some (generic-type^ imports type-vars))
- _ (p.assert (format name " cannot be a type-parameter!")
- (not (list.member? text.equivalence (list@map product.left type-vars) name)))]
- (wrap (#GenericClass name params))))
- ))
+ (p.rec
+ (function (_ recur^)
+ ($_ p.either
+ (do p.monad
+ [_ (s.this! (' ?))]
+ (wrap (#GenericWildcard #.None)))
+ (s.tuple (do p.monad
+ [_ (s.this! (' ?))
+ bound-kind bound-kind^
+ bound recur^]
+ (wrap (#GenericWildcard (#.Some [bound-kind bound])))))
+ (do p.monad
+ [name (full-class-name^ imports)
+ _ (assert-no-periods name)]
+ (if (list.member? text.equivalence (list@map product.left type-vars) name)
+ (wrap (#GenericTypeVar name))
+ (wrap (#GenericClass name (list)))))
+ (s.tuple (do p.monad
+ [component recur^]
+ (case component
+ (^template [<class> <name>]
+ (#GenericClass <name> #.Nil)
+ (wrap (#GenericClass <class> (list))))
+ (["[Z" "boolean"]
+ ["[B" "byte"]
+ ["[S" "short"]
+ ["[I" "int"]
+ ["[J" "long"]
+ ["[F" "float"]
+ ["[D" "double"]
+ ["[C" "char"])
+
+ _
+ (wrap (#GenericArray component)))))
+ (s.form (do p.monad
+ [name (full-class-name^ imports)
+ _ (assert-no-periods name)
+ params (p.some recur^)
+ _ (p.assert (format name " cannot be a type-parameter!")
+ (not (list.member? text.equivalence (list@map product.left type-vars) name)))]
+ (wrap (#GenericClass name params))))
+ ))))
(def: (type-param^ imports)
(-> Class-Imports (Parser Type-Parameter))
@@ -1816,7 +1817,7 @@
"#io means the computation has side effects, and will be wrapped by the IO type."
"These options must show up in the following order [#io #try #?] (although, each option can be used independently)."
(import: java/lang/String
- (new [(Array byte)])
+ (new [[byte]])
(#static valueOf [char] String)
(#static valueOf #as int-valueOf [int] String))
@@ -1825,7 +1826,7 @@
(get [int] e))
(import: (java/util/ArrayList a)
- ([T] toArray [(Array T)] (Array T)))
+ ([T] toArray [[T]] [T]))
"#long makes it so the class-type that is generated is of the fully-qualified name."
"In this case, it avoids a clash between the java.util.List type, and Lux's own List type."
diff --git a/stdlib/source/lux/target/jvm/loader.old.lux b/stdlib/source/lux/target/jvm/loader.lux
index 57a715107..ae4d0373c 100644
--- a/stdlib/source/lux/target/jvm/loader.old.lux
+++ b/stdlib/source/lux/target/jvm/loader.lux
@@ -42,12 +42,10 @@
(import: #long java/lang/String)
(import: #long java/lang/reflect/Method
- (invoke [java/lang/Object (Array java/lang/Object)]
- #try java/lang/Object))
+ (invoke [java/lang/Object [java/lang/Object]] #try java/lang/Object))
(import: #long (java/lang/Class a)
- (getDeclaredMethod [java/lang/String (Array (java/lang/Class java/lang/Object))]
- #try java/lang/reflect/Method))
+ (getDeclaredMethod [java/lang/String [(java/lang/Class java/lang/Object)]] #try java/lang/reflect/Method))
(import: #long java/lang/Integer
(#static TYPE (java/lang/Class java/lang/Integer)))
diff --git a/stdlib/source/lux/target/jvm/reflection.lux b/stdlib/source/lux/target/jvm/reflection.lux
index 4ae3ce64f..090c5948f 100644
--- a/stdlib/source/lux/target/jvm/reflection.lux
+++ b/stdlib/source/lux/target/jvm/reflection.lux
@@ -35,15 +35,15 @@
(import: #long java/lang/reflect/ParameterizedType
(getRawType [] java/lang/reflect/Type)
- (getActualTypeArguments [] (Array java/lang/reflect/Type)))
+ (getActualTypeArguments [] [java/lang/reflect/Type]))
(import: #long (java/lang/reflect/TypeVariable d)
(getName [] java/lang/String)
- (getBounds [] (Array java/lang/reflect/Type)))
+ (getBounds [] [java/lang/reflect/Type]))
(import: #long (java/lang/reflect/WildcardType d)
- (getLowerBounds [] (Array java/lang/reflect/Type))
- (getUpperBounds [] (Array java/lang/reflect/Type)))
+ (getLowerBounds [] [java/lang/reflect/Type])
+ (getUpperBounds [] [java/lang/reflect/Type]))
(import: #long java/lang/reflect/Modifier
(#static isStatic [int] boolean)
@@ -60,29 +60,29 @@
(getName [] java/lang/String)
(getModifiers [] int)
(getDeclaringClass [] (java/lang/Class java/lang/Object))
- (getTypeParameters [] (Array (java/lang/reflect/TypeVariable java/lang/reflect/Method)))
- (getGenericParameterTypes [] (Array java/lang/reflect/Type))
+ (getTypeParameters [] [(java/lang/reflect/TypeVariable java/lang/reflect/Method)])
+ (getGenericParameterTypes [] [java/lang/reflect/Type])
(getGenericReturnType [] java/lang/reflect/Type)
- (getGenericExceptionTypes [] (Array java/lang/reflect/Type)))
+ (getGenericExceptionTypes [] [java/lang/reflect/Type]))
(import: #long (java/lang/reflect/Constructor c)
(getModifiers [] int)
(getDeclaringClass [] (java/lang/Class c))
- (getTypeParameters [] (Array (java/lang/reflect/TypeVariable (java/lang/reflect/Constructor c))))
- (getGenericParameterTypes [] (Array java/lang/reflect/Type))
- (getGenericExceptionTypes [] (Array java/lang/reflect/Type)))
+ (getTypeParameters [] [(java/lang/reflect/TypeVariable (java/lang/reflect/Constructor c))])
+ (getGenericParameterTypes [] [java/lang/reflect/Type])
+ (getGenericExceptionTypes [] [java/lang/reflect/Type]))
(import: #long (java/lang/Class c)
(#static forName [java/lang/String] #try (java/lang/Class java/lang/Object))
(getName [] java/lang/String)
(getModifiers [] int)
(isAssignableFrom [(java/lang/Class java/lang/Object)] boolean)
- (getTypeParameters [] (Array (java/lang/reflect/TypeVariable (java/lang/Class c))))
- (getGenericInterfaces [] (Array java/lang/reflect/Type))
+ (getTypeParameters [] [(java/lang/reflect/TypeVariable (java/lang/Class c))])
+ (getGenericInterfaces [] [java/lang/reflect/Type])
(getGenericSuperclass [] #? java/lang/reflect/Type)
(getDeclaredField [java/lang/String] #try java/lang/reflect/Field)
- (getConstructors [] (Array (java/lang/reflect/Constructor java/lang/Object)))
- (getDeclaredMethods [] (Array java/lang/reflect/Method)))
+ (getConstructors [] [(java/lang/reflect/Constructor java/lang/Object)])
+ (getDeclaredMethods [] [java/lang/reflect/Method]))
(exception: #export (unknown-class {class Text})
(exception.report
diff --git a/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux b/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux
index 1f7cbe26e..616f030a9 100644
--- a/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux
+++ b/stdlib/source/lux/tool/compiler/phase/extension/analysis/jvm.lux
@@ -654,7 +654,7 @@
(import: #long (java/lang/reflect/TypeVariable d)
(getName [] java/lang/String)
- (getBounds [] (Array java/lang/reflect/Type)))
+ (getBounds [] [java/lang/reflect/Type]))
(import: #long java/lang/reflect/Modifier
(#static isStatic [int] boolean)
@@ -666,29 +666,29 @@
(getName [] java/lang/String)
(getModifiers [] int)
(getDeclaringClass [] (java/lang/Class java/lang/Object))
- (getTypeParameters [] (Array (java/lang/reflect/TypeVariable java/lang/reflect/Method)))
- (getGenericParameterTypes [] (Array java/lang/reflect/Type))
+ (getTypeParameters [] [(java/lang/reflect/TypeVariable java/lang/reflect/Method)])
+ (getGenericParameterTypes [] [java/lang/reflect/Type])
(getGenericReturnType [] java/lang/reflect/Type)
- (getGenericExceptionTypes [] (Array java/lang/reflect/Type)))
+ (getGenericExceptionTypes [] [java/lang/reflect/Type]))
(import: #long (java/lang/reflect/Constructor c)
(getModifiers [] int)
(getDeclaringClass [] (java/lang/Class c))
- (getTypeParameters [] (Array (java/lang/reflect/TypeVariable (java/lang/reflect/Constructor c))))
- (getGenericParameterTypes [] (Array java/lang/reflect/Type))
- (getGenericExceptionTypes [] (Array java/lang/reflect/Type)))
+ (getTypeParameters [] [(java/lang/reflect/TypeVariable (java/lang/reflect/Constructor c))])
+ (getGenericParameterTypes [] [java/lang/reflect/Type])
+ (getGenericExceptionTypes [] [java/lang/reflect/Type]))
(import: #long (java/lang/Class c)
(#static forName [java/lang/String] #try (java/lang/Class java/lang/Object))
(getName [] java/lang/String)
(getModifiers [] int)
(isAssignableFrom [(java/lang/Class java/lang/Object)] boolean)
- (getTypeParameters [] (Array (java/lang/reflect/TypeVariable (java/lang/Class c))))
- (getGenericInterfaces [] (Array java/lang/reflect/Type))
+ (getTypeParameters [] [(java/lang/reflect/TypeVariable (java/lang/Class c))])
+ (getGenericInterfaces [] [java/lang/reflect/Type])
(getGenericSuperclass [] #? java/lang/reflect/Type)
(getDeclaredField [java/lang/String] #try java/lang/reflect/Field)
- (getConstructors [] (Array (java/lang/reflect/Constructor java/lang/Object)))
- (getDeclaredMethods [] (Array java/lang/reflect/Method)))
+ (getConstructors [] [(java/lang/reflect/Constructor java/lang/Object)])
+ (getDeclaredMethods [] [java/lang/reflect/Method]))
(def: (reflection-type mapping typeJ)
(-> Mapping Type (Operation .Type))
diff --git a/stdlib/source/lux/world/binary.lux b/stdlib/source/lux/world/binary.lux
index 56bf01620..9599ae2f0 100644
--- a/stdlib/source/lux/world/binary.lux
+++ b/stdlib/source/lux/world/binary.lux
@@ -15,7 +15,7 @@
[text
format]
[collection
- [array (#+ Array)]]]])
+ [array (#+)]]]])
(exception: #export (index-out-of-bounds {size Nat} {index Nat})
(exception.report
@@ -33,29 +33,21 @@
[inverted-slice]
)
-(`` (for {(~~ (static @.old))
- (as-is (type: #export Binary (host.type (Array byte)))
+(with-expansions [<for-jvm> (as-is (type: #export Binary (host.type [byte]))
- (import: #long java/lang/Object)
+ (import: #long java/lang/Object)
+
+ (import: #long java/lang/System
+ (#static arraycopy [java/lang/Object int java/lang/Object int int] #try void))
- (import: #long java/lang/System
- (#static arraycopy [java/lang/Object int java/lang/Object int int] #try void))
-
- (import: #long java/util/Arrays
- (#static copyOfRange [(Array byte) int int] (Array byte))
- (#static equals [(Array byte) (Array byte)] boolean)))
-
- (~~ (static @.jvm))
- (as-is (type: #export Binary (host.type [byte]))
-
- (import: #long java/lang/Object)
-
- (import: #long java/lang/System
- (#static arraycopy [java/lang/Object int java/lang/Object int int] #try void))
+ (import: #long java/util/Arrays
+ (#static copyOfRange [[byte] int int] [byte])
+ (#static equals [[byte] [byte]] boolean)))]
+ (`` (for {(~~ (static @.old))
+ (as-is <for-jvm>)
- (import: #long java/util/Arrays
- (#static copyOfRange [[byte] int int] [byte])
- (#static equals [[byte] [byte]] boolean)))}))
+ (~~ (static @.jvm))
+ (as-is <for-jvm>)})))
(def: byte-mask
I64
diff --git a/stdlib/source/lux/world/db/jdbc.old.lux b/stdlib/source/lux/world/db/jdbc.lux
index 8fd0ecf4c..8fd0ecf4c 100644
--- a/stdlib/source/lux/world/db/jdbc.old.lux
+++ b/stdlib/source/lux/world/db/jdbc.lux
diff --git a/stdlib/source/lux/world/db/jdbc/input.old.lux b/stdlib/source/lux/world/db/jdbc/input.lux
index 68045b058..b160c5a5c 100644
--- a/stdlib/source/lux/world/db/jdbc/input.old.lux
+++ b/stdlib/source/lux/world/db/jdbc/input.lux
@@ -38,7 +38,7 @@
[setDouble double]
[setString java/lang/String]
- [setBytes (Array byte)]
+ [setBytes [byte]]
[setDate java/sql/Date]
[setTime java/sql/Time]
diff --git a/stdlib/source/lux/world/db/jdbc/output.old.lux b/stdlib/source/lux/world/db/jdbc/output.lux
index 39c4cb92b..8c461bb68 100644
--- a/stdlib/source/lux/world/db/jdbc/output.old.lux
+++ b/stdlib/source/lux/world/db/jdbc/output.lux
@@ -38,7 +38,7 @@
[getFloat float]
[getString java/lang/String]
- [getBytes (Array byte)]
+ [getBytes [byte]]
[getDate java/sql/Date]
[getTime java/sql/Time]
diff --git a/stdlib/source/lux/world/environment.old.lux b/stdlib/source/lux/world/environment.lux
index 8ad10f1f9..8ad10f1f9 100644
--- a/stdlib/source/lux/world/environment.old.lux
+++ b/stdlib/source/lux/world/environment.lux
diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux
index f25a372fc..f60bb6974 100644
--- a/stdlib/source/lux/world/file.lux
+++ b/stdlib/source/lux/world/file.lux
@@ -17,7 +17,7 @@
["." text
format]
[collection
- ["." array (#+ Array)]
+ ["." array]
["." list ("#;." functor)]]]
[time
["." instant (#+ Instant)]
@@ -185,373 +185,194 @@
["Instant" (%instant instant)]
["Path" file]))
-(`` (for {(~~ (static @.old))
- (as-is (import: #long java/lang/String)
-
- (import: #long java/io/File
- (new [java/lang/String])
- (~~ (template [<name>]
- [(<name> [] #io #try boolean)]
-
- [createNewFile] [mkdir]
- [exists] [delete]
- [isFile] [isDirectory]
- [canRead] [canWrite] [canExecute]))
-
- (length [] #io #try long)
- (listFiles [] #io #try #? (Array java/io/File))
- (getAbsolutePath [] #io #try java/lang/String)
- (renameTo [java/io/File] #io #try boolean)
- (lastModified [] #io #try long)
- (setLastModified [long] #io #try boolean)
- (#static separator java/lang/String))
-
- (template: (!delete path exception)
- (do io.monad
- [outcome (java/io/File::delete (java/io/File::new path))]
- (case outcome
- (#error.Success #1)
- (wrap (#error.Success []))
-
- _
- (io.io (exception.throw exception [path])))))
-
- (import: #long java/lang/AutoCloseable
- (close [] #io #try void))
-
- (import: java/io/OutputStream
- (write [(Array byte)] #io #try void)
- (flush [] #io #try void))
-
- (import: java/io/FileOutputStream
- (new [java/io/File boolean] #io #try))
-
- (import: java/io/InputStream
- (read [(Array byte)] #io #try int))
-
- (import: java/io/FileInputStream
- (new [java/io/File] #io #try))
-
- (structure: (file path)
- (-> Path (File IO))
-
- (~~ (template [<name> <flag>]
- [(def: <name>
- (..can-modify
- (function (<name> data)
- (do (error.with io.monad)
- [stream (FileOutputStream::new (java/io/File::new path) <flag>)
- _ (OutputStream::write data stream)
- _ (OutputStream::flush stream)]
- (java/lang/AutoCloseable::close stream)))))]
-
- [over-write #0]
- [append #1]
- ))
-
- (def: content
- (..can-query
- (function (content _)
- (do (error.with io.monad)
- [#let [file (java/io/File::new path)]
- size (java/io/File::length file)
- #let [data (binary.create (.nat size))]
- stream (FileInputStream::new file)
- bytes-read (InputStream::read data stream)
- _ (java/lang/AutoCloseable::close stream)]
- (if (i/= size bytes-read)
- (wrap data)
- (io.io (exception.throw cannot-read-all-data path)))))))
-
- (def: size
- (..can-query
- (function (size _)
- (|> path
- java/io/File::new
- java/io/File::length
- (:: (error.with io.monad) map .nat)))))
-
- (def: last-modified
- (..can-query
- (function (last-modified _)
- (|> path
- java/io/File::new
- (java/io/File::lastModified)
- (:: (error.with io.monad) map (|>> duration.from-millis instant.absolute))))))
-
- (def: can-execute?
- (..can-query
- (function (can-execute? _)
- (|> path
- java/io/File::new
- java/io/File::canExecute))))
-
- (def: move
- (..can-open
- (function (move destination)
- (do io.monad
- [outcome (java/io/File::renameTo (java/io/File::new destination)
- (java/io/File::new path))]
- (case outcome
- (#error.Success #1)
- (wrap (#error.Success (file destination)))
-
- _
- (io.io (exception.throw cannot-move [destination path])))))))
-
- (def: modify
- (..can-modify
- (function (modify time-stamp)
- (do io.monad
- [outcome (java/io/File::setLastModified (|> time-stamp instant.relative duration.to-millis)
- (java/io/File::new path))]
- (case outcome
- (#error.Success #1)
- (wrap (#error.Success []))
-
- _
- (io.io (exception.throw cannot-modify [time-stamp path])))))))
-
- (def: delete
- (..can-delete
- (function (delete _)
- (!delete path cannot-delete-file)))))
-
- (structure: (directory path)
- (-> Path (Directory IO))
-
- (~~ (template [<name> <method> <capability>]
- [(def: <name>
- (..can-query
- (function (<name> _)
- (do (error.with io.monad)
- [?children (java/io/File::listFiles (java/io/File::new path))]
- (case ?children
- (#.Some children)
- (|> children
- array.to-list
- (monad.filter @ (|>> <method>))
- (:: @ map (monad.map @ (|>> java/io/File::getAbsolutePath (:: @ map <capability>))))
- (:: @ join))
-
- #.None
- (io.io (exception.throw not-a-directory [path])))))))]
-
- [files java/io/File::isFile file]
- [directories java/io/File::isDirectory directory]
- ))
-
- (def: discard
- (..can-delete
- (function (discard _)
- (!delete path cannot-discard-directory)))))
-
- (structure: #export system (System IO)
- (~~ (template [<name> <method> <capability> <exception>]
- [(def: <name>
- (..can-open
- (function (<name> path)
- (do io.monad
- [#let [file (java/io/File::new path)]
- outcome (<method> file)]
- (case outcome
- (#error.Success #1)
- (wrap (#error.Success (<capability> path)))
-
- _
- (wrap (exception.throw <exception> [path])))))))]
-
- [file java/io/File::isFile ..file cannot-find-file]
- [create-file java/io/File::createNewFile ..file cannot-create-file]
- [directory java/io/File::isDirectory ..directory cannot-find-directory]
- [create-directory java/io/File::mkdir ..directory cannot-create-directory]
- ))
-
- (def: separator (java/io/File::separator))
- ))
-
- (~~ (static @.jvm))
- (as-is (import: #long java/lang/String)
- (import: #long java/lang/Boolean)
-
- (import: #long java/io/File
- (new [java/lang/String])
- (~~ (template [<name>]
- [(<name> [] #io #try boolean)]
-
- [createNewFile] [mkdir]
- [exists] [delete]
- [isFile] [isDirectory]
- [canRead] [canWrite] [canExecute]))
-
- (length [] #io #try long)
- (listFiles [] #io #try #? [java/io/File])
- (getAbsolutePath [] #io #try java/lang/String)
- (renameTo [java/io/File] #io #try boolean)
- (lastModified [] #io #try long)
- (setLastModified [long] #io #try boolean)
- (#static separator java/lang/String))
-
- (template: (!delete path exception)
- (do io.monad
- [outcome (java/io/File::delete (java/io/File::new path))]
- (case outcome
- (#error.Success #1)
- (wrap (#error.Success []))
-
- _
- (io.io (exception.throw exception [path])))))
-
- (import: #long java/lang/AutoCloseable
- (close [] #io #try void))
-
- (import: java/io/OutputStream
- (write [[byte]] #io #try void)
- (flush [] #io #try void))
-
- (import: java/io/FileOutputStream
- (new [java/io/File boolean] #io #try))
-
- (import: java/io/InputStream
- (read [[byte]] #io #try int))
-
- (import: java/io/FileInputStream
- (new [java/io/File] #io #try))
-
- (def: (file path)
- (-> Path (File IO))
- (structure
- (~~ (template [<name> <flag>]
- [(def: <name>
- (..can-modify
- (function (<name> data)
- (do (error.with io.monad)
- [stream (FileOutputStream::new (java/io/File::new path) <flag>)
- _ (OutputStream::write data stream)
- _ (OutputStream::flush stream)]
- (java/lang/AutoCloseable::close stream)))))]
-
- [over-write #0]
- [append #1]
- ))
-
- (def: content
- (..can-query
- (function (content _)
- (do (error.with io.monad)
- [#let [file (java/io/File::new path)]
- size (java/io/File::length file)
- #let [data (binary.create (.nat size))]
- stream (FileInputStream::new file)
- bytes-read (InputStream::read data stream)
- _ (java/lang/AutoCloseable::close stream)]
- (if (i/= size bytes-read)
- (wrap data)
- (io.io (exception.throw cannot-read-all-data path)))))))
-
- (def: size
- (..can-query
- (function (size _)
- (|> (java/io/File::new path)
- java/io/File::length
- (:: (error.with io.monad) map .nat)))))
-
- (def: last-modified
- (..can-query
- (function (last-modified _)
- (|> (java/io/File::new path)
- java/io/File::lastModified
- (:: (error.with io.monad) map (|>> duration.from-millis instant.absolute))))))
-
- (def: can-execute?
- (..can-query
- (function (can-execute? _)
- (java/io/File::canExecute (java/io/File::new path)))))
-
- (def: move
- (..can-open
- (function (move destination)
- (do io.monad
- [outcome (java/io/File::renameTo (java/io/File::new destination)
- (java/io/File::new path))]
- (case outcome
- (#error.Success #1)
- (wrap (#error.Success (file destination)))
-
- _
- (io.io (exception.throw cannot-move [destination path])))))))
-
- (def: modify
- (..can-modify
- (function (modify time-stamp)
- (do io.monad
- [outcome (java/io/File::setLastModified (|> time-stamp instant.relative duration.to-millis)
- (java/io/File::new path))]
- (case outcome
- (#error.Success #1)
- (wrap (#error.Success []))
-
- _
- (io.io (exception.throw cannot-modify [time-stamp path])))))))
-
- (def: delete
- (..can-delete
- (function (delete _)
- (!delete path cannot-delete-file))))))
-
- (structure: (directory path)
- (-> Path (Directory IO))
-
- (~~ (template [<name> <method> <capability>]
- [(def: <name>
- (..can-query
- (function (<name> _)
- (do (error.with io.monad)
- [?children (java/io/File::listFiles (java/io/File::new path))]
- (case ?children
- (#.Some children)
- (|> children
- array.to-list
- (monad.filter @ (|>> <method>))
- (:: @ map (monad.map @ (|>> java/io/File::getAbsolutePath
- (:: @ map <capability>))))
- (:: @ join))
-
- #.None
- (io.io (exception.throw not-a-directory [path])))))))]
-
- [files java/io/File::isFile file]
- [directories java/io/File::isDirectory directory]
- ))
-
- (def: discard
- (..can-delete
- (function (discard _)
- (!delete path cannot-discard-directory)))))
-
- (structure: #export system (System IO)
- (~~ (template [<name> <method> <capability> <exception>]
- [(def: <name>
- (..can-open
- (function (<name> path)
- (do io.monad
- [#let [file (java/io/File::new path)]
- outcome (<method> file)]
- (case outcome
- (#error.Success #1)
- (wrap (#error.Success (<capability> path)))
-
- _
- (wrap (exception.throw <exception> [path])))))))]
-
- [file java/io/File::isFile ..file cannot-find-file]
- [create-file java/io/File::createNewFile ..file cannot-create-file]
- [directory java/io/File::isDirectory ..directory cannot-find-directory]
- [create-directory java/io/File::mkdir ..directory cannot-create-directory]
- ))
-
- (def: separator (java/io/File::separator))
- ))}))
+(with-expansions [<for-jvm> (as-is (import: #long java/lang/String)
+
+ (import: #long java/io/File
+ (new [java/lang/String])
+ (~~ (template [<name>]
+ [(<name> [] #io #try boolean)]
+
+ [createNewFile] [mkdir]
+ [exists] [delete]
+ [isFile] [isDirectory]
+ [canRead] [canWrite] [canExecute]))
+
+ (length [] #io #try long)
+ (listFiles [] #io #try #? [java/io/File])
+ (getAbsolutePath [] #io #try java/lang/String)
+ (renameTo [java/io/File] #io #try boolean)
+ (lastModified [] #io #try long)
+ (setLastModified [long] #io #try boolean)
+ (#static separator java/lang/String))
+
+ (template: (!delete path exception)
+ (do io.monad
+ [outcome (java/io/File::delete (java/io/File::new path))]
+ (case outcome
+ (#error.Success #1)
+ (wrap (#error.Success []))
+
+ _
+ (io.io (exception.throw exception [path])))))
+
+ (import: #long java/lang/AutoCloseable
+ (close [] #io #try void))
+
+ (import: java/io/OutputStream
+ (write [[byte]] #io #try void)
+ (flush [] #io #try void))
+
+ (import: java/io/FileOutputStream
+ (new [java/io/File boolean] #io #try))
+
+ (import: java/io/InputStream
+ (read [[byte]] #io #try int))
+
+ (import: java/io/FileInputStream
+ (new [java/io/File] #io #try))
+
+ (structure: (file path)
+ (-> Path (File IO))
+
+ (~~ (template [<name> <flag>]
+ [(def: <name>
+ (..can-modify
+ (function (<name> data)
+ (do (error.with io.monad)
+ [stream (FileOutputStream::new (java/io/File::new path) <flag>)
+ _ (OutputStream::write data stream)
+ _ (OutputStream::flush stream)]
+ (java/lang/AutoCloseable::close stream)))))]
+
+ [over-write #0]
+ [append #1]
+ ))
+
+ (def: content
+ (..can-query
+ (function (content _)
+ (do (error.with io.monad)
+ [#let [file (java/io/File::new path)]
+ size (java/io/File::length file)
+ #let [data (binary.create (.nat size))]
+ stream (FileInputStream::new file)
+ bytes-read (InputStream::read data stream)
+ _ (java/lang/AutoCloseable::close stream)]
+ (if (i/= size bytes-read)
+ (wrap data)
+ (io.io (exception.throw cannot-read-all-data path)))))))
+
+ (def: size
+ (..can-query
+ (function (size _)
+ (|> path
+ java/io/File::new
+ java/io/File::length
+ (:: (error.with io.monad) map .nat)))))
+
+ (def: last-modified
+ (..can-query
+ (function (last-modified _)
+ (|> path
+ java/io/File::new
+ (java/io/File::lastModified)
+ (:: (error.with io.monad) map (|>> duration.from-millis instant.absolute))))))
+
+ (def: can-execute?
+ (..can-query
+ (function (can-execute? _)
+ (|> path
+ java/io/File::new
+ java/io/File::canExecute))))
+
+ (def: move
+ (..can-open
+ (function (move destination)
+ (do io.monad
+ [outcome (java/io/File::renameTo (java/io/File::new destination)
+ (java/io/File::new path))]
+ (case outcome
+ (#error.Success #1)
+ (wrap (#error.Success (file destination)))
+
+ _
+ (io.io (exception.throw cannot-move [destination path])))))))
+
+ (def: modify
+ (..can-modify
+ (function (modify time-stamp)
+ (do io.monad
+ [outcome (java/io/File::setLastModified (|> time-stamp instant.relative duration.to-millis)
+ (java/io/File::new path))]
+ (case outcome
+ (#error.Success #1)
+ (wrap (#error.Success []))
+
+ _
+ (io.io (exception.throw cannot-modify [time-stamp path])))))))
+
+ (def: delete
+ (..can-delete
+ (function (delete _)
+ (!delete path cannot-delete-file)))))
+
+ (structure: (directory path)
+ (-> Path (Directory IO))
+
+ (~~ (template [<name> <method> <capability>]
+ [(def: <name>
+ (..can-query
+ (function (<name> _)
+ (do (error.with io.monad)
+ [?children (java/io/File::listFiles (java/io/File::new path))]
+ (case ?children
+ (#.Some children)
+ (|> children
+ array.to-list
+ (monad.filter @ (|>> <method>))
+ (:: @ map (monad.map @ (|>> java/io/File::getAbsolutePath (:: @ map <capability>))))
+ (:: @ join))
+
+ #.None
+ (io.io (exception.throw not-a-directory [path])))))))]
+
+ [files java/io/File::isFile file]
+ [directories java/io/File::isDirectory directory]
+ ))
+
+ (def: discard
+ (..can-delete
+ (function (discard _)
+ (!delete path cannot-discard-directory)))))
+
+ (structure: #export system (System IO)
+ (~~ (template [<name> <method> <capability> <exception>]
+ [(def: <name>
+ (..can-open
+ (function (<name> path)
+ (do io.monad
+ [#let [file (java/io/File::new path)]
+ outcome (<method> file)]
+ (case outcome
+ (#error.Success #1)
+ (wrap (#error.Success (<capability> path)))
+
+ _
+ (wrap (exception.throw <exception> [path])))))))]
+
+ [file java/io/File::isFile ..file cannot-find-file]
+ [create-file java/io/File::createNewFile ..file cannot-create-file]
+ [directory java/io/File::isDirectory ..directory cannot-find-directory]
+ [create-directory java/io/File::mkdir ..directory cannot-create-directory]
+ ))
+
+ (def: separator (java/io/File::separator))
+ ))]
+ (`` (for {(~~ (static @.old))
+ (as-is <for-jvm>)
+
+ (~~ (static @.jvm))
+ (as-is <for-jvm>)})))
(template [<get> <signature> <create> <find> <exception>]
[(def: #export (<get> monad system path)
diff --git a/stdlib/source/lux/world/net/tcp.old.lux b/stdlib/source/lux/world/net/tcp.lux
index 85d306799..a0fa13c8a 100644
--- a/stdlib/source/lux/world/net/tcp.old.lux
+++ b/stdlib/source/lux/world/net/tcp.lux
@@ -43,10 +43,10 @@
(flush [] #io #try void))
(import: java/io/InputStream
- (read [(Array byte) int int] #io #try int))
+ (read [[byte] int int] #io #try int))
(import: java/io/OutputStream
- (write [(Array byte) int int] #io #try void))
+ (write [[byte] int int] #io #try void))
(import: java/net/Socket
(new [String int] #io #try)
diff --git a/stdlib/source/lux/world/net/udp.old.lux b/stdlib/source/lux/world/net/udp.lux
index 1f78f4b0d..df9244186 100644
--- a/stdlib/source/lux/world/net/udp.old.lux
+++ b/stdlib/source/lux/world/net/udp.lux
@@ -52,12 +52,12 @@
(flush [] #io #try void))
(import: java/net/InetAddress
- (#static getAllByName [String] #io #try (Array InetAddress))
+ (#static getAllByName [String] #io #try [InetAddress])
(getHostAddress [] String))
(import: java/net/DatagramPacket
- (new #as new|send [(Array byte) int int InetAddress int])
- (new #as new|receive [(Array byte) int int])
+ (new #as new|send [[byte] int int InetAddress int])
+ (new #as new|receive [[byte] int int])
(getAddress [] InetAddress)
(getPort [] int)
(getLength [] int))
diff --git a/stdlib/source/lux/world/shell.lux b/stdlib/source/lux/world/shell.lux
index d7fedc6d0..3f0ae519e 100644
--- a/stdlib/source/lux/world/shell.lux
+++ b/stdlib/source/lux/world/shell.lux
@@ -96,7 +96,7 @@
(new [java/io/InputStream]))
(import: #long java/io/OutputStream
- (write [(Array byte)] #io #try void))
+ (write [[byte]] #io #try void))
(import: #long java/lang/Process
(getInputStream [] #io #try java/io/InputStream)
@@ -139,7 +139,7 @@
java/lang/Process::destroy)))))))))
(import: #long java/lang/ProcessBuilder
- (new [(Array java/lang/String)])
+ (new [[java/lang/String]])
(environment [] #io #try (java/util/Map java/lang/String java/lang/String))
(start [] #io #try java/lang/Process))