1 import "Prelude" hiding (readInteger, readLong, readFloat, readDouble, read)
4 import "ArrayList" as ArrayList
7 write :: OutputStream -> a -> <Proc> ()
8 read :: InputStream -> <Proc> a
9 ioSize :: a -> <Proc> Integer
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 a) => IO (Maybe a) where
68 ioSize (Just v) = 1 + ioSize v
70 instance (IO a, IO b) => IO (Either a b) where
77 write s (Right v) = do
80 ioSize (Left v) = 1 + ioSize v
81 ioSize (Right v) = 1 + ioSize v
88 instance (IO a, IO b) => IO (a, b) where
96 ioSize (a, b) = ioSize a + ioSize b
98 instance (IO a, IO b, IO c) => IO (a, b, c) where
104 write s (a, b, c) = do
108 ioSize (a, b, c) = ioSize a + ioSize b + ioSize c
110 instance (IO a, IO b, IO c, IO d) => IO (a, b, c, d) where
117 write s (a, b, c, d) = do
122 ioSize (a, b, c, d) = ioSize a + ioSize b + ioSize c + ioSize d
124 instance (IO a, IO b, IO c, IO d, IO e) => IO (a, b, c, d, e) where
132 write s (a, b, c, d, e) = do
138 ioSize (a, b, c, d, e) = ioSize a + ioSize b + ioSize c + ioSize d + ioSize e
140 instance (IO a) => IO [a] where
142 writeLength s (length v)
144 read s = ArrayList.freeze (read s)
145 ioSize vs = ioSizeLength (length vs) + sum [ioSize v | v <- vs]
147 instance (IO a) => IO (ArrayList.T a) where
149 writeLength s (ArrayList.length v)
150 ArrayList.for v (write s)
153 result = ArrayList.newC l
155 ArrayList.add result (read s)
160 instance (IO a, VecComp a) => IO (Vector a) where
165 forN l (\i -> write s (v ! i))
169 result = createMVector l
170 forN l (\i -> setMVector result i (read s))
174 readByteArray :: IO a => ByteArray -> a
175 readByteArray ar = runProc do
176 s = openForReading ar
181 writeByteArray :: IO a => a -> ByteArray
182 writeByteArray v = runProc do
189 importJava "org.simantics.scl.runtime.io.SclIO" where
190 writeBoolean :: OutputStream -> Boolean -> <Proc> ()
191 writeByte :: OutputStream -> Byte -> <Proc> ()
192 writeCharacter :: OutputStream -> Character -> <Proc> ()
193 writeShort :: OutputStream -> Short -> <Proc> ()
194 writeInteger :: OutputStream -> Integer -> <Proc> ()
195 writeLong :: OutputStream -> Long -> <Proc> ()
196 writeFloat :: OutputStream -> Float -> <Proc> ()
197 writeDouble :: OutputStream -> Double -> <Proc> ()
198 writeDoubleArray :: OutputStream -> DoubleArray -> <Proc> ()
199 writeString :: OutputStream -> String -> <Proc> ()
200 writeLength :: OutputStream -> Integer -> <Proc> ()
202 readBoolean :: InputStream -> <Proc> Boolean
203 readByte :: InputStream -> <Proc> Byte
204 readCharacter :: InputStream -> <Proc> Character
205 readShort :: InputStream -> <Proc> Short
206 readInteger :: InputStream -> <Proc> Integer
207 readLong :: InputStream -> <Proc> Long
208 readFloat :: InputStream -> <Proc> Float
209 readDouble :: InputStream -> <Proc> Double
210 readDoubleArray :: InputStream -> <Proc> DoubleArray
211 readString :: InputStream -> <Proc> String
212 readLength :: InputStream -> <Proc> Integer
214 ioSizeString :: String -> Integer
215 ioSizeLength :: Integer -> Integer
217 @JavaName readAllByteArrayAndClose
218 readAllByteArray :: InputStream -> <Proc> ByteArray
219 @JavaName readAllStringAndClose
220 readAllString :: InputStream -> <Proc> String