From cc7c007fb930bb1453a529916f8cf2ba8d18f0e3 Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Tue, 30 Jan 2018 13:39:17 +0200 Subject: [PATCH] Getting rid of *Array and replace with Vector * (SCL) refs #7734 Change-Id: Ibc97edbd65de8363dcd77e141ac518287a07bff2 --- .../org/simantics/modeling/SCLTypeUtils.java | 2 +- .../compiler/elaboration/java/Builtins.java | 11 +---------- .../constraints/ReduceSerializable.java | 6 ------ .../simantics/scl/compiler/types/Types.java | 19 +++++++++---------- .../internal/typeRegistry/TypeRegistry.java | 10 +++++++--- .../org.simantics.scl.runtime/scl/Prelude.scl | 9 +++++++++ .../scl/Serialization.scl | 7 ------- 7 files changed, 27 insertions(+), 37 deletions(-) diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLTypeUtils.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLTypeUtils.java index c94b1be1b..9632090e3 100644 --- a/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLTypeUtils.java +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/SCLTypeUtils.java @@ -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")); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java index 5004bc055..ec82b3e4a 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/Builtins.java @@ -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); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ReduceSerializable.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ReduceSerializable.java index f849dcabc..e372a8083 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ReduceSerializable.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/elaboration/constraints/ReduceSerializable.java @@ -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 BINDING_CONSTANTS1 = new THashMap(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java index 5512f5e6e..a9d779bfd 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/types/Types.java @@ -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 diff --git a/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/typeRegistry/TypeRegistry.java b/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/typeRegistry/TypeRegistry.java index e7eb1486c..f09877021 100644 --- a/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/typeRegistry/TypeRegistry.java +++ b/bundles/org.simantics.scl.reflection/src/org/simantics/scl/reflection/internal/typeRegistry/TypeRegistry.java @@ -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> map = new ConcurrentHashMap>(); @@ -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); diff --git a/bundles/org.simantics.scl.runtime/scl/Prelude.scl b/bundles/org.simantics.scl.runtime/scl/Prelude.scl index bb6452429..cce906409 100644 --- a/bundles/org.simantics.scl.runtime/scl/Prelude.scl +++ b/bundles/org.simantics.scl.runtime/scl/Prelude.scl @@ -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 diff --git a/bundles/org.simantics.scl.runtime/scl/Serialization.scl b/bundles/org.simantics.scl.runtime/scl/Serialization.scl index 408de4d7e..ca5286b7a 100644 --- a/bundles/org.simantics.scl.runtime/scl/Serialization.scl +++ b/bundles/org.simantics.scl.runtime/scl/Serialization.scl @@ -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) -- 2.47.1