]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Prelude.scl
Merge commit '53059ca'
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Prelude.scl
index 0dcd1b7507d6ee99ee2866c174f5b987ee1e77e0..21658862db66f34262c1852603872ff5f25291ef 100644 (file)
@@ -558,6 +558,43 @@ importJava "java.lang.Math" where
 
 /// Integer ///
 
 
 /// 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
 @private
 importJava "java.lang.Short" where
     @JavaName toString
@@ -1266,7 +1303,7 @@ instance MonadZero Maybe where
     mzero = Nothing
 
 instance MonadOr Maybe where
     mzero = Nothing
 
 instance MonadOr Maybe where
-    morelse (Just a) _ = Just a
+    morelse a@(Just _) _ = a
     morelse _ b = b
 
 "`execJust v f` executes the function `f` with parameter value `x`, if `v=Just x`. If `v=Nothing`, the function does nothing."
     morelse _ b = b
 
 "`execJust v f` executes the function `f` with parameter value `x`, if `v=Just x`. If `v=Nothing`, the function does nothing."
@@ -2240,45 +2277,7 @@ instance Show TypeRep where
         isSpecialType (TCon "Builtin" "(,,,)") = True
         isSpecialType (TApply a _) = isSpecialType a
 */
         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
 // ByteArray
 
 importJava "java.util.Arrays" where
@@ -2289,53 +2288,6 @@ importJava "java.util.Arrays" where
 instance Show ByteArray where
     show = byteArrayToString
 
 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
-    @JavaName "<init>"
-    variantOfWithBinding :: Binding a -> a -> Variant
-    @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
 // Type
 
 @private