summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorschinz <schinz@epfl.ch>2004-10-26 13:10:13 +0000
committerschinz <schinz@epfl.ch>2004-10-26 13:10:13 +0000
commit5cedd7f04e3fd3fbab9db72b65bb8adbf958b3ff (patch)
tree0a7b72c11ae1f683576b585e0ecb97c2fff2520a /sources
parent55dc9426182208f9b606fc3145ddcd37e9f1ec20 (diff)
downloadscala-5cedd7f04e3fd3fbab9db72b65bb8adbf958b3ff.tar.gz
scala-5cedd7f04e3fd3fbab9db72b65bb8adbf958b3ff.tar.bz2
scala-5cedd7f04e3fd3fbab9db72b65bb8adbf958b3ff.zip
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/runtime/PearsonHash.java49
-rw-r--r--sources/scala/runtime/types/BasicType.java32
-rw-r--r--sources/scala/runtime/types/CompoundType.java85
-rw-r--r--sources/scala/runtime/types/MethodType.java77
-rw-r--r--sources/scala/runtime/types/Refinement.java68
5 files changed, 311 insertions, 0 deletions
diff --git a/sources/scala/runtime/PearsonHash.java b/sources/scala/runtime/PearsonHash.java
new file mode 100644
index 0000000000..41bc7d7085
--- /dev/null
+++ b/sources/scala/runtime/PearsonHash.java
@@ -0,0 +1,49 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id$
+
+package scala.runtime;
+
+/**
+ * Provide methods to compute Pearson's hash.
+ *
+ * @author Michel Schinz
+ */
+
+public class PearsonHash {
+ // some random permutation of [0;255]
+ private static int[] table = new int[] {
+ 251, 117, 191, 48, 37, 199, 178, 157, 9, 50, 183, 197, 42, 40, 104,
+ 83, 156, 250, 215, 14, 233, 33, 74, 253, 128, 10, 36, 73, 217, 224,
+ 116, 86, 132, 204, 20, 2, 80, 55, 222, 5, 207, 201, 129, 216, 165,
+ 155, 159, 236, 19, 146, 108, 124, 112, 0, 58, 92, 70, 152, 135, 88,
+ 97, 122, 61, 255, 184, 211, 214, 141, 67, 79, 18, 62, 101, 173,
+ 238, 154, 170, 164, 130, 229, 252, 205, 43, 81, 94, 149, 59, 151,
+ 93, 45, 25, 166, 139, 44, 143, 16, 188, 30, 91, 218, 77, 60, 142,
+ 168, 47, 176, 13, 49, 34, 102, 31, 65, 203, 76, 240, 78, 115, 84,
+ 244, 32, 11, 175, 247, 209, 242, 71, 163, 167, 35, 136, 22, 237,
+ 134, 56, 181, 17, 4, 24, 206, 192, 105, 63, 89, 239, 6, 72, 53,
+ 219, 69, 227, 133, 15, 161, 68, 120, 12, 111, 179, 245, 100, 103,
+ 8, 148, 107, 144, 127, 160, 26, 241, 162, 213, 1, 220, 150, 82,
+ 190, 96, 98, 137, 174, 145, 46, 243, 125, 198, 231, 66, 234, 177,
+ 212, 210, 226, 95, 228, 21, 254, 27, 28, 121, 196, 187, 54, 249,
+ 109, 208, 153, 232, 194, 113, 23, 140, 235, 158, 248, 182, 202,
+ 186, 147, 119, 225, 87, 126, 64, 221, 193, 246, 169, 189, 90, 180,
+ 138, 57, 38, 75, 230, 41, 123, 110, 223, 118, 106, 7, 172, 114,
+ 131, 99, 51, 185, 39, 171, 195, 52, 29, 200, 3, 85
+ };
+
+ /** Hash an integer to a single byte */
+ public static int hash8(int i) {
+ final int h1 = table[i & 0xFF];
+ final int h2 = table[h1 ^ ((i >>> 8) & 0xFF)];
+ final int h3 = table[h2 ^ ((i >>> 16) & 0xFF)];
+ return table[h3 ^ (i >>> 24)];
+ }
+}
diff --git a/sources/scala/runtime/types/BasicType.java b/sources/scala/runtime/types/BasicType.java
new file mode 100644
index 0000000000..8557cf9578
--- /dev/null
+++ b/sources/scala/runtime/types/BasicType.java
@@ -0,0 +1,32 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id$
+
+package scala.runtime.types;
+
+import scala.Type;
+
+/**
+ * Abstract superclass for all basic types.
+ *
+ * @author Michel Schinz
+ * @version 1.0
+ */
+
+abstract public class BasicType extends Type {
+ public boolean isInstance(Object o) {
+ throw new UnsupportedOperationException();
+ }
+ public boolean isSubType(Type that) {
+ return false; // TODO
+ }
+ public boolean isSameAs(Type that) {
+ return this == that;
+ }
+}
diff --git a/sources/scala/runtime/types/CompoundType.java b/sources/scala/runtime/types/CompoundType.java
new file mode 100644
index 0000000000..1436c6d77d
--- /dev/null
+++ b/sources/scala/runtime/types/CompoundType.java
@@ -0,0 +1,85 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id$
+
+package scala.runtime.types;
+
+import scala.Type;
+import scala.Array;
+import scala.ScalaObject;
+import scala.runtime.RunTime;
+
+/**
+ * Run-time representation for compound types.
+ *
+ * @author Michel Schinz
+ * @version 1.0
+ */
+
+public class CompoundType extends Type {
+ public final ClassType[] components;
+ public final Refinement[] refinements;
+
+ public CompoundType(ClassType[] components,
+ Refinement[] refinements) {
+ this.components = components;
+ this.refinements = refinements;
+ }
+
+ public Array newArray(int size) {
+ throw new Error(); // TODO
+ }
+
+ public Object defaultValue() {
+ return null;
+ }
+
+ public boolean isInstance(Object o) {
+ for (int i = 0; i < components.length; ++i) {
+ if (!components[i].isInstance(o))
+ return false;
+ }
+
+ return (refinements.length == 0)
+ || (o instanceof ScalaObject
+ && hasCoarserRefinements((((ScalaObject)o).getType())
+ .refinements));
+ }
+
+ private boolean hasCoarserRefinements(Refinement[] thatRefinements) {
+ return Refinement.isFiner(thatRefinements, this.refinements);
+ }
+
+ public boolean isSubType(Type that) {
+ throw new Error(); // TODO
+ }
+
+ public boolean isSameAs(Type that) {
+ if (that instanceof CompoundType) {
+ CompoundType thatCT = (CompoundType)that;
+
+ if ((components.length != thatCT.components.length)
+ || (refinements.length != thatCT.refinements.length))
+ return false;
+
+ for (int i = 0; i < components.length; ++i) {
+ if (!components[i].isSameAs(thatCT.components[i]))
+ return false;
+ }
+
+ for (int i = 0; i < refinements.length; ++i) {
+ if (!refinements[i].isSameAs(thatCT.refinements[i]))
+ return false;
+ }
+
+ return true;
+ } else
+ return false;
+ }
+}
diff --git a/sources/scala/runtime/types/MethodType.java b/sources/scala/runtime/types/MethodType.java
new file mode 100644
index 0000000000..08395bcba5
--- /dev/null
+++ b/sources/scala/runtime/types/MethodType.java
@@ -0,0 +1,77 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id$
+
+package scala.runtime.types;
+
+import scala.Type;
+import scala.Array;
+
+public class MethodType extends Type {
+ public final Type[] argTypes;
+ public final Type returnType;
+
+ public MethodType(Type[] argTypes, Type returnType) {
+ this.argTypes = argTypes;
+ this.returnType = returnType;
+ }
+
+ public Array newArray(int size) {
+ throw new Error(); // TODO provide a message (and maybe
+ // use a different exception)
+ }
+
+ public Object defaultValue() {
+ throw new Error(); // TODO provide a message (and maybe
+ // use a different exception)
+ }
+
+ public boolean isInstance(Object o) {
+ throw new Error(); // TODO provide a message (and maybe
+ // use a different exception)
+ }
+
+ public boolean isSubType(Type that) {
+ if (that instanceof MethodType) {
+ MethodType thatMT = (MethodType)that;
+
+ if (argTypes.length != thatMT.argTypes.length)
+ return false;
+
+ for (int i = 0; i < argTypes.length; ++i) {
+ if (! argTypes[i].isSameAs(thatMT.argTypes[i]))
+ return false;
+ }
+ return returnType.isSubType(thatMT.returnType);
+ } else
+ return false;
+ }
+
+ public boolean isSameAs(Type that) {
+ if (that instanceof MethodType) {
+ MethodType thatMT = (MethodType)that;
+
+ if (argTypes.length != thatMT.argTypes.length)
+ return false;
+
+ for (int i = 0; i < argTypes.length; ++i) {
+ if (! argTypes[i].isSameAs(thatMT.argTypes[i]))
+ return false;
+ }
+ return returnType.isSameAs(thatMT.returnType);
+ }
+ else
+ return false;
+ }
+
+ public int hashCode() {
+ throw new Error(); // TODO provide a message (and maybe
+ // use a different exception)
+ }
+}
diff --git a/sources/scala/runtime/types/Refinement.java b/sources/scala/runtime/types/Refinement.java
new file mode 100644
index 0000000000..0b32097868
--- /dev/null
+++ b/sources/scala/runtime/types/Refinement.java
@@ -0,0 +1,68 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2003, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id$
+
+package scala.runtime.types;
+
+import scala.Type;
+
+/**
+ * Refinement for a class member.
+ *
+ * @author Michel Schinz
+ * @version 1.0
+ */
+
+public class Refinement {
+ public final static Refinement[] EMPTY_ARRAY = new Refinement[0];
+
+ public final int hash;
+ public final Type type;
+
+ public Refinement(int hash, Type type) {
+ this.hash = hash;
+ this.type = type;
+ }
+
+ public boolean isSameAs(Refinement that) {
+ return (this.hash == that.hash) && this.type.isSameAs(that.type);
+ }
+
+ public boolean isFinerThan(Refinement that) {
+ return (this.hash == that.hash) && this.type.isSubType(that.type);
+ }
+
+ public static boolean isFiner(Refinement[] r1, Refinement[] r2) {
+ for (int i2 = 0, i1 = 0; i2 < r2.length; ++i2) {
+ Refinement r = r2[i2];
+ while (i1 < r1.length && r1[i1].hash != r.hash)
+ ++i1;
+
+ if (i1 == r1.length || !r1[i1].isFinerThan(r))
+ return false;
+ }
+ return true;
+ }
+
+ public static Refinement[] make(ScalaClassType[] parents,
+ Refinement[] base,
+ int[] code) {
+ int pc = 0;
+ int len = code[pc++];
+ Refinement[] result = new Refinement[len];
+ for (int i = 0; i < len; ++i) {
+ int par = code[pc++], idx = code[pc++];
+ result[i] = (par == -1)
+ ? base[idx]
+ : parents[par].refinements[idx];
+ }
+ assert pc == code.length;
+ return result;
+ }
+}