1 import "Prelude" hiding (readInteger, readLong, readFloat, readDouble, read)
4 import "ArrayList" as ArrayList
7 write :: OutputStream -> a -> <Proc> ()
8 read :: InputStream -> <Proc> a
11 ioSize _ = fail "ioSize not implemented"
13 instance IO Boolean where
18 instance IO Byte where
23 instance IO Character where
24 write = writeCharacter
28 instance IO Short where
33 instance IO Integer where
38 instance IO Long where
43 instance IO Float where
48 instance IO Double where
53 instance IO String where
58 instance IO DoubleArray where
59 write = writeDoubleArray
60 read = readDoubleArray
63 // ioSizeLength l + 8 * l
65 instance (IO a) => IO (Maybe a) where
75 ioSize (Just v) = 1 + ioSize v
77 instance (IO a, IO b) => IO (Either a b) where
84 write s (Right v) = do
87 ioSize (Left v) = 1 + ioSize v
88 ioSize (Right v) = 1 + ioSize v
95 instance (IO a, IO b) => IO (a, b) where
103 ioSize (a, b) = ioSize a + ioSize b
105 instance (IO a, IO b, IO c) => IO (a, b, c) where
111 write s (a, b, c) = do
115 ioSize (a, b, c) = ioSize a + ioSize b + ioSize c
117 instance (IO a, IO b, IO c, IO d) => IO (a, b, c, d) where
124 write s (a, b, c, d) = do
129 ioSize (a, b, c, d) = ioSize a + ioSize b + ioSize c + ioSize d
131 instance (IO a, IO b, IO c, IO d, IO e) => IO (a, b, c, d, e) where
139 write s (a, b, c, d, e) = do
145 ioSize (a, b, c, d, e) = ioSize a + ioSize b + ioSize c + ioSize d + ioSize e
147 instance (IO a) => IO [a] where
149 writeLength s (length v)
151 read s = ArrayList.freeze (read s)
152 ioSize vs = ioSizeLength (length vs) + sum [ioSize v | v <- vs]
154 instance (IO a) => IO (ArrayList.T a) where
156 writeLength s (ArrayList.length v)
157 ArrayList.for v (write s)
160 result = ArrayList.newC l
162 ArrayList.add result (read s)
167 instance (IO a, VecComp a) => IO (Vector a) where
172 forN l (\i -> write s (v ! i))
176 result = createMVector l
177 forN l (\i -> setMVector result i (read s))
181 readByteArray :: IO a => ByteArray -> a
182 readByteArray ar = runProc do
183 s = openForReading ar
188 writeByteArray :: IO a => a -> ByteArray
189 writeByteArray v = runProc do
196 importJava "org.simantics.scl.runtime.io.SclIO" where
197 writeBoolean :: OutputStream -> Boolean -> <Proc> ()
198 writeByte :: OutputStream -> Byte -> <Proc> ()
199 writeCharacter :: OutputStream -> Character -> <Proc> ()
200 writeShort :: OutputStream -> Short -> <Proc> ()
201 writeInteger :: OutputStream -> Integer -> <Proc> ()
202 writeLong :: OutputStream -> Long -> <Proc> ()
203 writeFloat :: OutputStream -> Float -> <Proc> ()
204 writeDouble :: OutputStream -> Double -> <Proc> ()
205 writeDoubleArray :: OutputStream -> DoubleArray -> <Proc> ()
206 writeString :: OutputStream -> String -> <Proc> ()
207 writeLength :: OutputStream -> Integer -> <Proc> ()
209 readBoolean :: InputStream -> <Proc> Boolean
210 readByte :: InputStream -> <Proc> Byte
211 readCharacter :: InputStream -> <Proc> Character
212 readShort :: InputStream -> <Proc> Short
213 readInteger :: InputStream -> <Proc> Integer
214 readLong :: InputStream -> <Proc> Long
215 readFloat :: InputStream -> <Proc> Float
216 readDouble :: InputStream -> <Proc> Double
217 readDoubleArray :: InputStream -> <Proc> DoubleArray
218 readString :: InputStream -> <Proc> String
219 readLength :: InputStream -> <Proc> Integer
221 ioSizeString :: String -> Integer
222 ioSizeLength :: Integer -> Integer
224 @JavaName readAllByteArrayAndClose
225 readAllByteArray :: InputStream -> <Proc> ByteArray
226 @JavaName readAllStringAndClose
227 readAllString :: InputStream -> <Proc> String