diff options
author | paltherr <paltherr@epfl.ch> | 2003-03-28 16:02:40 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2003-03-28 16:02:40 +0000 |
commit | 5c24c955335d5dc2018042db5b0b0ee4a92663b6 (patch) | |
tree | d07749cc3c801eaeabefb16bcd4c7c4d50e500f0 /sources | |
parent | e189c7bacc64563eb4d0d359be061e42333a2887 (diff) | |
download | scala-5c24c955335d5dc2018042db5b0b0ee4a92663b6.tar.gz scala-5c24c955335d5dc2018042db5b0b0ee4a92663b6.tar.bz2 scala-5c24c955335d5dc2018042db5b0b0ee4a92663b6.zip |
- Added array length primitives
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/runtime/RunTime.java | 36 | ||||
-rw-r--r-- | sources/scalac/backend/Primitive.java | 45 | ||||
-rw-r--r-- | sources/scalac/backend/Primitives.java | 65 |
3 files changed, 128 insertions, 18 deletions
diff --git a/sources/scala/runtime/RunTime.java b/sources/scala/runtime/RunTime.java index c7f9ad88a4..d9f02392d3 100644 --- a/sources/scala/runtime/RunTime.java +++ b/sources/scala/runtime/RunTime.java @@ -481,6 +481,42 @@ public abstract class RunTime { } } + public static int zarray_length(boolean[] array) { + return array.length; + } + + public static int barray_length(byte[] array) { + return array.length; + } + + public static int sarray_length(short[] array) { + return array.length; + } + + public static int carray_length(char[] array) { + return array.length; + } + + public static int iarray_length(int[] array) { + return array.length; + } + + public static int larray_length(long[] array) { + return array.length; + } + + public static int farray_length(float[] array) { + return array.length; + } + + public static int darray_length(double[] array) { + return array.length; + } + + public static int oarray_length(Object[] array) { + return array.length; + } + public static boolean zarray_get(boolean[] array, int index) { return array[index]; } diff --git a/sources/scalac/backend/Primitive.java b/sources/scalac/backend/Primitive.java index e2c51289f7..c1b09fe36a 100644 --- a/sources/scalac/backend/Primitive.java +++ b/sources/scalac/backend/Primitive.java @@ -110,24 +110,33 @@ public class Primitive { public case NEW_FARRAY { tag = 59; } // RunTime.farray(x) public case NEW_DARRAY { tag = 60; } // RunTime.darray(x) public case NEW_OARRAY { tag = 61; } // RunTime.oarray(x) - public case ZARRAY_GET { tag = 62; } // RunTime.zarray_get(x,y) - public case BARRAY_GET { tag = 63; } // RunTime.barray_get(x,y) - public case SARRAY_GET { tag = 64; } // RunTime.sarray_get(x,y) - public case CARRAY_GET { tag = 65; } // RunTime.carray_get(x,y) - public case IARRAY_GET { tag = 66; } // RunTime.iarray_get(x,y) - public case LARRAY_GET { tag = 67; } // RunTime.larray_get(x,y) - public case FARRAY_GET { tag = 68; } // RunTime.farray_get(x,y) - public case DARRAY_GET { tag = 69; } // RunTime.darray_get(x,y) - public case OARRAY_GET { tag = 70; } // RunTime.oarray_get(x,y) - public case ZARRAY_SET { tag = 71; } // RunTime.zarray(x,y,z) - public case BARRAY_SET { tag = 72; } // RunTime.barray(x,y,z) - public case SARRAY_SET { tag = 73; } // RunTime.sarray(x,y,z) - public case CARRAY_SET { tag = 74; } // RunTime.carray(x,y,z) - public case IARRAY_SET { tag = 75; } // RunTime.iarray(x,y,z) - public case LARRAY_SET { tag = 76; } // RunTime.larray(x,y,z) - public case FARRAY_SET { tag = 77; } // RunTime.farray(x,y,z) - public case DARRAY_SET { tag = 78; } // RunTime.darray(x,y,z) - public case OARRAY_SET { tag = 79; } // RunTime.oarray(x,y,z) + public case ZARRAY_LENGTH { tag = 62; } // RunTime.zarray_length(x) + public case BARRAY_LENGTH { tag = 63; } // RunTime.barray_length(x) + public case SARRAY_LENGTH { tag = 64; } // RunTime.sarray_length(x) + public case CARRAY_LENGTH { tag = 65; } // RunTime.carray_length(x) + public case IARRAY_LENGTH { tag = 66; } // RunTime.iarray_length(x) + public case LARRAY_LENGTH { tag = 67; } // RunTime.larray_length(x) + public case FARRAY_LENGTH { tag = 68; } // RunTime.farray_length(x) + public case DARRAY_LENGTH { tag = 69; } // RunTime.darray_length(x) + public case OARRAY_LENGTH { tag = 70; } // RunTime.oarray_length(x) + public case ZARRAY_GET { tag = 71; } // RunTime.zarray_get(x,y) + public case BARRAY_GET { tag = 72; } // RunTime.barray_get(x,y) + public case SARRAY_GET { tag = 73; } // RunTime.sarray_get(x,y) + public case CARRAY_GET { tag = 74; } // RunTime.carray_get(x,y) + public case IARRAY_GET { tag = 75; } // RunTime.iarray_get(x,y) + public case LARRAY_GET { tag = 76; } // RunTime.larray_get(x,y) + public case FARRAY_GET { tag = 77; } // RunTime.farray_get(x,y) + public case DARRAY_GET { tag = 78; } // RunTime.darray_get(x,y) + public case OARRAY_GET { tag = 79; } // RunTime.oarray_get(x,y) + public case ZARRAY_SET { tag = 80; } // RunTime.zarray(x,y,z) + public case BARRAY_SET { tag = 81; } // RunTime.barray(x,y,z) + public case SARRAY_SET { tag = 82; } // RunTime.sarray(x,y,z) + public case CARRAY_SET { tag = 83; } // RunTime.carray(x,y,z) + public case IARRAY_SET { tag = 84; } // RunTime.iarray(x,y,z) + public case LARRAY_SET { tag = 85; } // RunTime.larray(x,y,z) + public case FARRAY_SET { tag = 86; } // RunTime.farray(x,y,z) + public case DARRAY_SET { tag = 87; } // RunTime.darray(x,y,z) + public case OARRAY_SET { tag = 88; } // RunTime.oarray(x,y,z) /** Return negated version of comparison primitive. */ public Primitive negate() { diff --git a/sources/scalac/backend/Primitives.java b/sources/scalac/backend/Primitives.java index 9ea139fe50..85633e6dce 100644 --- a/sources/scalac/backend/Primitives.java +++ b/sources/scalac/backend/Primitives.java @@ -45,6 +45,16 @@ public class Primitives { private static final Name DARRAY_N = Name.fromString("darray"); private static final Name OARRAY_N = Name.fromString("oarray"); + private static final Name ZARRAY_LENGTH_N=Name.fromString("zarray_length"); + private static final Name BARRAY_LENGTH_N=Name.fromString("barray_length"); + private static final Name SARRAY_LENGTH_N=Name.fromString("sarray_length"); + private static final Name CARRAY_LENGTH_N=Name.fromString("carray_length"); + private static final Name IARRAY_LENGTH_N=Name.fromString("iarray_length"); + private static final Name LARRAY_LENGTH_N=Name.fromString("larray_length"); + private static final Name FARRAY_LENGTH_N=Name.fromString("farray_length"); + private static final Name DARRAY_LENGTH_N=Name.fromString("darray_length"); + private static final Name OARRAY_LENGTH_N=Name.fromString("oarray_length"); + private static final Name ZARRAY_GET_N = Name.fromString("zarray_get"); private static final Name BARRAY_GET_N = Name.fromString("barray_get"); private static final Name SARRAY_GET_N = Name.fromString("sarray_get"); @@ -115,6 +125,16 @@ public class Primitives { public final Symbol NEW_DARRAY; public final Symbol NEW_OARRAY; + public final Symbol ZARRAY_LENGTH; + public final Symbol BARRAY_LENGTH; + public final Symbol SARRAY_LENGTH; + public final Symbol CARRAY_LENGTH; + public final Symbol IARRAY_LENGTH; + public final Symbol LARRAY_LENGTH; + public final Symbol FARRAY_LENGTH; + public final Symbol DARRAY_LENGTH; + public final Symbol OARRAY_LENGTH; + public final Symbol ZARRAY_GET; public final Symbol BARRAY_GET; public final Symbol SARRAY_GET; @@ -202,6 +222,15 @@ public class Primitives { this.NEW_FARRAY = getUniqueTerm(RUNTIME, FARRAY_N); this.NEW_DARRAY = getUniqueTerm(RUNTIME, DARRAY_N); this.NEW_OARRAY = getUniqueTerm(RUNTIME, OARRAY_N); + this.ZARRAY_LENGTH = getUniqueTerm(RUNTIME, ZARRAY_LENGTH_N); + this.BARRAY_LENGTH = getUniqueTerm(RUNTIME, BARRAY_LENGTH_N); + this.SARRAY_LENGTH = getUniqueTerm(RUNTIME, SARRAY_LENGTH_N); + this.CARRAY_LENGTH = getUniqueTerm(RUNTIME, CARRAY_LENGTH_N); + this.IARRAY_LENGTH = getUniqueTerm(RUNTIME, IARRAY_LENGTH_N); + this.LARRAY_LENGTH = getUniqueTerm(RUNTIME, LARRAY_LENGTH_N); + this.FARRAY_LENGTH = getUniqueTerm(RUNTIME, FARRAY_LENGTH_N); + this.DARRAY_LENGTH = getUniqueTerm(RUNTIME, DARRAY_LENGTH_N); + this.OARRAY_LENGTH = getUniqueTerm(RUNTIME, OARRAY_LENGTH_N); this.ZARRAY_GET = getUniqueTerm(RUNTIME, ZARRAY_GET_N); this.BARRAY_GET = getUniqueTerm(RUNTIME, BARRAY_GET_N); this.SARRAY_GET = getUniqueTerm(RUNTIME, SARRAY_GET_N); @@ -498,6 +527,15 @@ public class Primitives { addPrimitive(NEW_FARRAY, Primitive.NEW_FARRAY); addPrimitive(NEW_DARRAY, Primitive.NEW_DARRAY); addPrimitive(NEW_OARRAY, Primitive.NEW_OARRAY); + addPrimitive(ZARRAY_LENGTH, Primitive.ZARRAY_LENGTH); + addPrimitive(BARRAY_LENGTH, Primitive.BARRAY_LENGTH); + addPrimitive(SARRAY_LENGTH, Primitive.SARRAY_LENGTH); + addPrimitive(CARRAY_LENGTH, Primitive.CARRAY_LENGTH); + addPrimitive(IARRAY_LENGTH, Primitive.IARRAY_LENGTH); + addPrimitive(LARRAY_LENGTH, Primitive.LARRAY_LENGTH); + addPrimitive(FARRAY_LENGTH, Primitive.FARRAY_LENGTH); + addPrimitive(DARRAY_LENGTH, Primitive.DARRAY_LENGTH); + addPrimitive(OARRAY_LENGTH, Primitive.OARRAY_LENGTH); addPrimitive(ZARRAY_GET, Primitive.ZARRAY_GET); addPrimitive(BARRAY_GET, Primitive.BARRAY_GET); addPrimitive(SARRAY_GET, Primitive.SARRAY_GET); @@ -773,6 +811,33 @@ public class Primitives { //######################################################################## // Primitives interface - array get and set primitives + /** Return length method for arrays of the given type. */ + public Symbol getArrayLengthSymbol(Type type) { + switch (type) { + case UnboxedArrayType(UnboxedType(int kind)): + return getArrayLengthSymbol(kind); + case UnboxedArrayType(_): + return OARRAY_LENGTH; + default: + throw Debug.abort("illegal case", type); + } + } + + /** Return length method for arrays of elements of the given kind. */ + public Symbol getArrayLengthSymbol(int kind) { + switch (kind) { + case TypeTags.BOOLEAN: return ZARRAY_LENGTH; + case TypeTags.BYTE : return BARRAY_LENGTH; + case TypeTags.SHORT : return SARRAY_LENGTH; + case TypeTags.CHAR : return CARRAY_LENGTH; + case TypeTags.INT : return IARRAY_LENGTH; + case TypeTags.LONG : return LARRAY_LENGTH; + case TypeTags.FLOAT : return FARRAY_LENGTH; + case TypeTags.DOUBLE : return DARRAY_LENGTH; + default : throw Debug.abort("illegal kind " + kind); + } + } + /** Return get method for arrays of the given type. */ public Symbol getArrayGetSymbol(Type type) { switch (type) { |