Getting rid of *Array and replace with Vector * (SCL) 08/1408/4
authorjsimomaa <jani.simomaa@gmail.com>
Tue, 30 Jan 2018 11:39:17 +0000 (13:39 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Tue, 30 Jan 2018 14:56:02 +0000 (16:56 +0200)
refs #7734

Change-Id: Ibc97edbd65de8363dcd77e141ac518287a07bff2

bundles/org.simantics.modeling/src/org/simantics/modeling/SCLTypeUtils.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ReduceSerializable.java
bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java
bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/typeRegistry/TypeRegistry.java
bundles/org.simantics.scl.runtime/scl/Prelude.scl
bundles/org.simantics.scl.runtime/scl/Serialization.scl

index c94b1be1b2dbaeb43c96b934d551024bb5d2be8a..9632090e3acf342255dce3dc151ea9558479efc0 100644 (file)
@@ -57,8 +57,8 @@ public class SCLTypeUtils {
         TYPE_MAP.put("Vector Float", Types.vector(Types.FLOAT));
         TYPE_MAP.put("Vector Double", Types.vector(Types.DOUBLE));
         TYPE_MAP.put("Vector String", Types.vector(Types.STRING));
+        TYPE_MAP.put("ByteArray", Types.BYTE_ARRAY);
         
-        add(Types.BYTE_ARRAY);
         add((TCon)Types.RESOURCE);
         add(Types.con("Simantics/Variables", "VariableMap"));
     }
index 5004bc0556355e08e597073e4440dfa5e7761520..ec82b3e4a1aaff2c319c3c82be66b3e37c5d392d 100644 (file)
@@ -89,16 +89,7 @@ public class Builtins extends ConcreteModule {
                 "64-bit floating point number"));
         addTypeDescriptor("String", new StandardTypeConstructor(Types.STRING, Kinds.STAR, TypeDesc.STRING,
                 "Unicode string"));
-        
-        addTypeDescriptor("BooleanArray", new StandardTypeConstructor(Types.BOOLEAN_ARRAY, Kinds.STAR, TypeDesc.forClass(boolean[].class)));
-        addTypeDescriptor("ByteArray", new StandardTypeConstructor(Types.BYTE_ARRAY, Kinds.STAR, TypeDesc.forClass(byte[].class)));
-        addTypeDescriptor("CharacterArray", new StandardTypeConstructor(Types.CHARACTER_ARRAY, Kinds.STAR, TypeDesc.forClass(char[].class)));
-        addTypeDescriptor("ShortArray", new StandardTypeConstructor(Types.SHORT_ARRAY, Kinds.STAR, TypeDesc.forClass(short[].class)));
-        addTypeDescriptor("IntegerArray", new StandardTypeConstructor(Types.INTEGER_ARRAY, Kinds.STAR, TypeDesc.forClass(int[].class)));
-        addTypeDescriptor("LongArray", new StandardTypeConstructor(Types.LONG_ARRAY, Kinds.STAR, TypeDesc.forClass(long[].class)));
-        addTypeDescriptor("FloatArray", new StandardTypeConstructor(Types.FLOAT_ARRAY, Kinds.STAR, TypeDesc.forClass(float[].class)));
-        addTypeDescriptor("DoubleArray", new StandardTypeConstructor(Types.DOUBLE_ARRAY, Kinds.STAR, TypeDesc.forClass(double[].class)));
-        
+
         addTypeDescriptor("Array", new StandardTypeConstructor(Types.con(Types.BUILTIN, "Array"), Kinds.STAR_TO_STAR, TypeDesc.forClass(Object[].class)));
         
         addTypeDescriptor("Maybe", MaybeType.INSTANCE);
index f849dcabc1d8d2c2b26e42329604d1a1cc62dda5..e372a808362cf4b0de6b3ec49485a3142259ecb2 100644 (file)
@@ -70,12 +70,6 @@ public class ReduceSerializable {
         BINDING_CONSTANTS0.put(Types.LONG,          new JavaStaticField("org/simantics/databoard/Bindings", "LONG",          Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/LongBinding"),    SERIALIZABLE_LONG, -1));
         BINDING_CONSTANTS0.put(Types.UNIT,          new JavaStaticField("org/simantics/databoard/Bindings", "VOID",          Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/Binding"),        SERIALIZABLE_TUPLE0, -1));
         BINDING_CONSTANTS0.put(Types.VARIANT,       new JavaStaticField("org/simantics/databoard/Bindings", "VARIANT",       Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/VariantBinding"), SERIALIZABLE_VARIANT, -1));
-        BINDING_CONSTANTS0.put(Types.DOUBLE_ARRAY,  new JavaStaticField("org/simantics/databoard/Bindings", "DOUBLE_ARRAY",  Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_DOUBLE_ARRAY, -1));
-        BINDING_CONSTANTS0.put(Types.INTEGER_ARRAY, new JavaStaticField("org/simantics/databoard/Bindings", "INTEGER_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_INTEGER_ARRAY, -1));
-        BINDING_CONSTANTS0.put(Types.BOOLEAN_ARRAY, new JavaStaticField("org/simantics/databoard/Bindings", "BOOLEAN_ARRAY", Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_BOOLEAN_ARRAY, -1));
-        BINDING_CONSTANTS0.put(Types.BYTE_ARRAY,    new JavaStaticField("org/simantics/databoard/Bindings", "BYTE_ARRAY",    Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_BYTE_ARRAY, -1));
-        BINDING_CONSTANTS0.put(Types.FLOAT_ARRAY,   new JavaStaticField("org/simantics/databoard/Bindings", "FLOAT_ARRAY",   Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_FLOAT_ARRAY, -1));
-        BINDING_CONSTANTS0.put(Types.LONG_ARRAY,    new JavaStaticField("org/simantics/databoard/Bindings", "LONG_ARRAY",    Types.NO_EFFECTS, TypeDesc.forClass("org/simantics/databoard/binding/ArrayBinding"),   SERIALIZABLE_LONG_ARRAY, -1));
     }
     
     private static final THashMap<TCon,Constant> BINDING_CONSTANTS1 = new THashMap<TCon,Constant>();
index 5512f5e6e10fedf946b6d10dc421e48490256c93..a9d779bfd81f83d856278ce8c7e76c68282397f9 100644 (file)
@@ -57,15 +57,6 @@ public class Types {
     public static final TCon LONG = con(BUILTIN, "Long");
     public static final TCon FLOAT = con(BUILTIN, "Float");
     public static final TCon DOUBLE = con(BUILTIN, "Double");
-    
-    public static final TCon BOOLEAN_ARRAY = con(BUILTIN, "BooleanArray");
-    public static final TCon BYTE_ARRAY = con(BUILTIN, "ByteArray");
-    public static final TCon CHARACTER_ARRAY = con(BUILTIN, "CharacterArray");
-    public static final TCon SHORT_ARRAY = con(BUILTIN, "ShortArray");
-    public static final TCon INTEGER_ARRAY = con(BUILTIN, "IntegerArray");
-    public static final TCon LONG_ARRAY = con(BUILTIN, "LongArray");
-    public static final TCon FLOAT_ARRAY = con(BUILTIN, "FloatArray");
-    public static final TCon DOUBLE_ARRAY = con(BUILTIN, "DoubleArray");
 
     public static final TCon STRING = con(BUILTIN, "String");
     public static final TCon ARROW = con(BUILTIN, "->");
@@ -117,7 +108,15 @@ public class Types {
     public static final TCon BRANCH_POINT = con(BUILTIN, "BranchPoint");
     
     public static final TCon CHRContext = con(BUILTIN, "CHRContext");
-    
+
+    public static final Type BOOLEAN_ARRAY = vector(BOOLEAN);
+    public static final Type BYTE_ARRAY = vector(BYTE);
+    public static final Type CHARACTER_ARRAY = vector(CHARACTER);
+    public static final Type SHORT_ARRAY = vector(SHORT);
+    public static final Type INTEGER_ARRAY = vector(INTEGER);
+    public static final Type LONG_ARRAY = vector(LONG);
+    public static final Type FLOAT_ARRAY = vector(FLOAT);
+    public static final Type DOUBLE_ARRAY = vector(DOUBLE);
 
     private volatile static TCon[] tupleCache = new TCon[] {
         UNIT, null
index e7eb1486c88d9ae4e908c9116cc6bf8f67606c23..f09877021806e4bfb6ab0a50f13aa72c1488cf61 100644 (file)
@@ -9,8 +9,13 @@ import org.simantics.scl.compiler.types.TCon;
 import org.simantics.scl.compiler.types.Types;
 import org.simantics.scl.reflection.TypeNotFoundException;
 import org.simantics.scl.reflection.internal.registry.BindingRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class TypeRegistry {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(TypeRegistry.class);
+
     private static final ConcurrentHashMap<TCon, Class<?>> map = 
             new ConcurrentHashMap<TCon, Class<?>>();
     
@@ -26,7 +31,6 @@ public class TypeRegistry {
         map.put(Types.FLOAT, Float.class);
         map.put(Types.DOUBLE, Double.class);
         map.put(Types.STRING, String.class);
-        map.put(Types.BYTE_ARRAY, byte[].class);
         
         map.put(Types.LIST, List.class);
         for(int i=0;i<8;++i)
@@ -35,7 +39,7 @@ public class TypeRegistry {
                     map.put(Types.tupleConstructor(i), 
                             Class.forName("org.simantics.scl.runtime.tuple.Tuple" + i));
                 } catch(ClassNotFoundException e) {
-                    e.printStackTrace();
+                    LOGGER.error("Could not find class for {}", i, e);
                 }
         
         for(TCon con : map.keySet())
@@ -48,7 +52,7 @@ public class TypeRegistry {
             try {
                 clazz = BindingRegistry.getClass(type);
             } catch(TypeNotFoundException e) {
-                e.printStackTrace();
+                LOGGER.error("Could not get class for type {}", type, e);
                 throw e;
             }
             map.put(type, clazz);
index bb6452429b39141a10a45ae19dbf4ad0736d0745..cce9064090ca123545e387b711e7cab902e95680 100644 (file)
@@ -38,6 +38,15 @@ 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
index 408de4d7ea39ced6ec5a58bb749a4abdaa28da42..ca5286b7af35d092c3078b7f40637d61b6df6b1c 100644 (file)
@@ -55,13 +55,6 @@ instance IO String where
     read = readString
     ioSize = ioSizeString
     
-instance IO DoubleArray where
-    write = writeDoubleArray
-    read = readDoubleArray
-    //ioSize v = do
-    //    l = length v
-    //    ioSizeLength l + 8 * l
-    
 instance (IO a) => IO (Maybe a) where
     read s = if read s 
              then Just (read s)