]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Prelude.scl
Fixed leftover problems in unification of *Array and Vector types
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Prelude.scl
index a926ae40ec3b0ca4ffb4c635132c3fa9eaa58f9e..7e558bdc4fd0c5d1216675919f5465b0042391b1 100644 (file)
@@ -38,11 +38,16 @@ class Serializable a
 binding :: Serializable a => Binding a
 ***********************************************************/
 
+type BooleanArray = Vector Boolean
+type ByteArray = Vector Byte
+type CharacterArray = Vector Character
+type ShortArray = Vector Short
+type IntegerArray = Vector Integer
+type LongArray = Vector Long
+type FloatArray = Vector Float
+type DoubleArray = Vector Double
+
 importJava "java.util.Arrays" where
-    @private
-    @JavaName toString
-    showDoubleArray :: DoubleArray -> String
-    
     "Converts an array to a list."
     @JavaName asList    
     arrayToList :: Array a -> [a]
@@ -52,9 +57,6 @@ importJava "java.util.List" where
     @JavaName toArray
     listToArray :: [a] -> Array a
 
-instance Show DoubleArray where
-    show = showDoubleArray
-
 importJava "org.simantics.scl.runtime.Coercion" where
     "Converts a list of doubles to a double array."
     toDoubleArray :: [Double] -> DoubleArray
@@ -1421,6 +1423,11 @@ importJava "java.lang.String" where
     "Creates a string from a vector of characters."
     @JavaName "<init>"
     string :: Vector Character -> String
+    
+    getBytes :: String -> String -> ByteArray
+
+getBytesUTF8 :: String -> ByteArray
+getBytesUTF8 str = getBytes str "UTF-8"
 
 instance Ord String where
     compare = compareString
@@ -2214,6 +2221,12 @@ importJava "java.lang.Throwable" where
     @private
     @JavaName toString
     showThrowable :: Throwable -> String
+    @private
+    @JavaName getMessage 
+    getMessageThrowable :: Throwable -> String
+    @private
+    @JavaName getCause 
+    getCauseThrowable :: Throwable -> Maybe Throwable
 importJava "java.lang.Exception" where
     data Exception
     @private
@@ -2225,6 +2238,20 @@ instance Show Throwable where
 instance Show Exception where
     show = showException
 
+class Throwable e where
+    toThrowable :: e -> Throwable
+
+messageOfException :: Throwable e => e -> String
+messageOfException = getMessageThrowable . toThrowable
+
+causeOfException :: Throwable e => e -> Maybe Throwable
+causeOfException = getCauseThrowable . toThrowable
+
+instance Throwable Throwable where
+    toThrowable = id
+instance Throwable Exception where
+    toThrowable = Java.unsafeCoerce
+
 "Prints the given value in the console."
 @inline
 print :: Show a => a -> <Proc> ()