/// Integer ///
+@private
+importJava "java.lang.Byte" where
+ @JavaName toString
+ showByte :: Byte -> String
+
+ @JavaName parseByte
+ readByte :: String -> Byte
+
+instance Eq Byte where
+ (==) = Java.bcmpeq
+ (!=) = Java.bcmpne
+
+instance Ord Byte where
+ (<) = Java.bcmplt
+ (<=) = Java.bcmple
+ (>) = Java.bcmpgt
+ (>=) = Java.bcmpge
+
+instance Additive Byte where
+ zero = Java.i2b Java.iconst_0
+ (+) = Java.badd
+
+instance Ring Byte where
+ neg = Java.bneg
+ (-) = Java.bsub
+ one = Java.i2b Java.iconst_1
+ (*) = Java.bmul
+ fromInteger = Java.i2b
+
+instance Show Byte where
+ show = showByte
+ precedence v = if v >= 0 then 0 else 100
+
+instance Read Byte where
+ read = readByte
+
+
@private
importJava "java.lang.Short" where
@JavaName toString
maybeToList (Just a) = [a]
maybeToList _ = []
+"""
+`takeWhile p l`, returns the longest prefix (possibly empty) of list `l` of elements that satisfy `p`
+"""
+takeWhile :: (a -> <e> Boolean) -> [a] -> <e> [a]
+takeWhile f l = loop 0
+ where
+ len = length l
+ loop i | i == len = l
+ | f (l!i) = loop (i+1)
+ | otherwise = take i l
+
partition :: (a -> <e> Boolean) -> [a] -> <e> ([a], [a])
partition p l = runProc do
res1 = newArrayList
isSpecialType (TCon "Builtin" "(,,,)") = True
isSpecialType (TApply a _) = isSpecialType a
*/
-// Serializable
-importJava "org.simantics.databoard.serialization.Serializer" where
- data Serializer a
-
- @private
- @JavaName "serialize"
- serialize_ :: Serializer a -> a -> ByteArray
-
- @private
- @JavaName "deserialize"
- deserialize_ :: Serializer a -> ByteArray -> a
-
-importJava "org.simantics.databoard.Bindings" where
- @private
- @JavaName "getSerializer"
- serializerOf :: Binding a -> Serializer a
-
- @private
- @JavaName toString
- bindingToString :: Binding a -> String
-
- @JavaName adapt
- adapt_ :: a -> Binding a -> Binding b -> b
-
-adapt :: Serializable a => Serializable b => a -> b
-adapt x = adapt_ x binding binding
-
-instance Show (Binding a) where
- show = bindingToString
-
-"Serializes a value to a byte array."
-serialize :: Serializable a => a -> ByteArray
-serialize v = serialize_ (serializerOf binding) v
-
-"Deserializes a value from a byte array."
-deserialize :: Serializable a => ByteArray -> a
-deserialize ba = deserialize_ (serializerOf binding) ba
-
// ByteArray
importJava "java.util.Arrays" where
instance Show ByteArray where
show = byteArrayToString
-importJava "org.simantics.databoard.binding.mutable.Variant" where
- // data Variant (in Builtins)
- @JavaName getValue
- rawVariantValue :: Variant -> a
- @JavaName ofInstance
- variantOf :: a -> Variant\r
- @JavaName "<init>"
- variantOfWithBinding :: Binding a -> a -> Variant\r
- @JavaName getValue
- variantValue_ :: Variant -> Binding a -> a
- @JavaName toString
- showVariant :: Variant -> String
-
- @JavaName getComponent
- variantComponent :: Variant -> ChildReference -> Variant
-
-variantValue :: Serializable a => Variant -> a
-variantValue v = variantValue_ v binding
-
-instance Show Variant where
- show = showVariant
-
-variantElement :: Serializable a => Variant -> Integer -> a
-variantElement v i = variantValue (variantComponent v (indexReference i))
-
-importJava "org.simantics.databoard.accessor.reference.ChildReference" where
- data ChildReference
-
- @JavaName compile
- compileReference :: [ChildReference] -> ChildReference
-
-importJava "org.simantics.databoard.accessor.reference.IndexReference" where
- @JavaName "<init>"
- indexReference :: Integer -> ChildReference
-
-importJava "org.simantics.databoard.accessor.reference.KeyReference" where
- @JavaName "<init>"
- keyReference :: Variant -> ChildReference
-
-importJava "org.simantics.databoard.accessor.reference.NameReference" where
- @JavaName "<init>"
- nameReference :: String -> ChildReference
-
-importJava "org.simantics.databoard.accessor.reference.LabelReference" where
- @JavaName "<init>"
- labelReference :: String -> ChildReference
-
// Type
@private