diff options
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/runtime/RunTime.java | 74 | ||||
-rw-r--r-- | sources/scala/tools/scalai/Constants.java | 2 | ||||
-rw-r--r-- | sources/scala/tools/scalai/Evaluator.java | 2 | ||||
-rw-r--r-- | sources/scalac/backend/Primitive.java | 4 | ||||
-rw-r--r-- | sources/scalac/backend/Primitives.java | 88 |
5 files changed, 80 insertions, 90 deletions
diff --git a/sources/scala/runtime/RunTime.java b/sources/scala/runtime/RunTime.java index 8207653827..d1c004fd7d 100644 --- a/sources/scala/runtime/RunTime.java +++ b/sources/scala/runtime/RunTime.java @@ -74,107 +74,107 @@ public abstract class RunTime { //######################################################################## // Public Functions - Boxing primitives - public static Unit box() { + public static Unit box_uvalue( ) { return uvalue; } - public static Boolean box(boolean x) { + public static Boolean box_zvalue(boolean x) { return x ? zvalue_t : zvalue_f; } - public static Byte box(byte x) { + public static Byte box_bvalue(byte x) { return bvalue[x & 0x000000FF]; } - public static Short box(short x) { + public static Short box_svalue(short x) { int c = x & CHECK_MASK; if (c == 0 || c == CHECK_MASK) return svalue[x & INDEX_MASK]; return new SValue(x); } - public static Char box(char x) { + public static Char box_cvalue(char x) { int c = (int)x & CHECK_MASK; if (c == 0) return cvalue[(int)x & INDEX_MASK]; return new CValue(x); } - public static Int box(int x) { + public static Int box_ivalue(int x) { int c = x & CHECK_MASK; if (c == 0 || c == CHECK_MASK) return ivalue[x & INDEX_MASK]; return new IValue(x); } - public static Long box(long x) { + public static Long box_lvalue(long x) { long c = x & CHECK_MASK; if (c == 0 || c == CHECK_MASK) return lvalue[(int)x & INDEX_MASK]; return new LValue(x); } - public static Float box(float x) { + public static Float box_fvalue(float x) { return new FValue(x); } - public static Double box(double x) { + public static Double box_dvalue(double x) { return new DValue(x); } /** @meta method (scala.Array[scala.Boolean]) scala.Array[scala.Boolean];*/ - public static Array box(boolean[] xs) { + public static Array box_zarray(boolean[] xs) { return new ZArray(xs); } /** @meta method (scala.Array[scala.Byte]) scala.Array[scala.Byte]; */ - public static Array box(byte[] xs) { + public static Array box_barray(byte [] xs) { return new BArray(xs); } /** @meta method (scala.Array[scala.Short]) scala.Array[scala.Short]; */ - public static Array box(short[] xs) { + public static Array box_sarray(short [] xs) { return new SArray(xs); } /** @meta method (scala.Array[scala.Char]) scala.Array[scala.Char]; */ - public static Array box(char[] xs) { + public static Array box_carray(char [] xs) { return new CArray(xs); } /** @meta method (scala.Array[scala.Int]) scala.Array[scala.Int]; */ - public static Array box(int[] xs) { + public static Array box_iarray(int [] xs) { return new IArray(xs); } /** @meta method (scala.Array[scala.Long]) scala.Array[scala.Long]; */ - public static Array box(long[] xs) { + public static Array box_larray(long [] xs) { return new LArray(xs); } /** @meta method (scala.Array[scala.Float]) scala.Array[scala.Float]; */ - public static Array box(float[] xs) { + public static Array box_farray(float [] xs) { return new FArray(xs); } /** @meta method (scala.Array[scala.Double]) scala.Array[scala.Double]; */ - public static Array box(double[] xs) { + public static Array box_darray(double [] xs) { return new DArray(xs); } /** @meta method [?T < scala.AnyRef](scala.Array[?T]) scala.Array[?T]; */ - public static Array box(Object[] xs) { + public static Array box_oarray(Object [] xs) { return new OArray(xs); } /** @meta method [?T](scala.Array[?T]) scala.Array[?T]; */ - public static Array box(Object xs) { - if (xs == null) return box((Object[])xs); - if (xs instanceof Object[]) return box((Object[])xs); - if (xs instanceof boolean[]) return box((boolean[])xs); - if (xs instanceof byte[]) return box((byte[])xs); - if (xs instanceof short[]) return box((short[])xs); - if (xs instanceof char[]) return box((char[])xs); - if (xs instanceof int[]) return box((int[])xs); - if (xs instanceof long[]) return box((long[])xs); - if (xs instanceof float[]) return box((float[])xs); - if (xs instanceof double[]) return box((double[])xs); + public static Array box__array(Object xs) { + if (xs == null ) return box_oarray((Object [])xs); + if (xs instanceof boolean[]) return box_zarray((boolean[])xs); + if (xs instanceof byte []) return box_barray((byte [])xs); + if (xs instanceof short []) return box_sarray((short [])xs); + if (xs instanceof char []) return box_carray((char [])xs); + if (xs instanceof int []) return box_iarray((int [])xs); + if (xs instanceof long []) return box_larray((long [])xs); + if (xs instanceof float []) return box_farray((float [])xs); + if (xs instanceof double []) return box_darray((double [])xs); + if (xs instanceof Object []) return box_oarray((Object [])xs); throw new ClassCastException(xs.getClass() + " is not an array class"); } @@ -440,7 +440,7 @@ class ZArray extends Array { public ZArray(boolean[] xs) { this.xs = xs; } public boolean[] asBooleanArray() { return xs; } public Object asArray() { return xs; } - public Object apply(int i) { return RunTime.box(xs[i]); } + public Object apply(int i) { return RunTime.box_zvalue(xs[i]); } public void update(int i, Object x) { xs[i] = ((Boolean)x).asBoolean(); } public int length() { return xs.length; } public String toString() { return String.valueOf(xs); } @@ -451,7 +451,7 @@ class BArray extends Array { public BArray(byte[] xs) { this.xs = xs; } public byte[] asByteArray() { return xs; } public Object asArray() { return xs; } - public Object apply(int i) { return RunTime.box(xs[i]); } + public Object apply(int i) { return RunTime.box_bvalue(xs[i]); } public void update(int i, Object x) { xs[i] = ((Byte)x).asByte(); } public int length() { return xs.length; } public String toString() { return String.valueOf(xs); } @@ -462,7 +462,7 @@ class SArray extends Array { public SArray(short[] xs) { this.xs = xs; } public short[] asShortArray() { return xs; } public Object asArray() { return xs; } - public Object apply(int i) { return RunTime.box(xs[i]); } + public Object apply(int i) { return RunTime.box_svalue(xs[i]); } public void update(int i, Object x) { xs[i] = ((Short)x).asShort(); } public int length() { return xs.length; } public String toString() { return String.valueOf(xs); } @@ -473,7 +473,7 @@ class CArray extends Array { public CArray(char[] xs) { this.xs = xs; } public char[] asCharArray() { return xs; } public Object asArray() { return xs; } - public Object apply(int i) { return RunTime.box(xs[i]); } + public Object apply(int i) { return RunTime.box_cvalue(xs[i]); } public void update(int i, Object x) { xs[i] = ((Char)x).asChar(); } public int length() { return xs.length; } public String toString() { return String.valueOf((Object)xs); } @@ -484,7 +484,7 @@ class IArray extends Array { public IArray(int[] xs) { this.xs = xs; } public int[] asIntArray() { return xs; } public Object asArray() { return xs; } - public Object apply(int i) { return RunTime.box(xs[i]); } + public Object apply(int i) { return RunTime.box_ivalue(xs[i]); } public void update(int i, Object x) { xs[i] = ((Int)x).asInt(); } public int length() { return xs.length; } public String toString() { return String.valueOf(xs); } @@ -495,7 +495,7 @@ class LArray extends Array { public LArray(long[] xs) { this.xs = xs; } public long[] asLongArray() { return xs; } public Object asArray() { return xs; } - public Object apply(int i) { return RunTime.box(xs[i]); } + public Object apply(int i) { return RunTime.box_lvalue(xs[i]); } public void update(int i, Object x) { xs[i] = ((Long)x).asLong(); } public int length() { return xs.length; } public String toString() { return String.valueOf(xs); } @@ -506,7 +506,7 @@ class FArray extends Array { public FArray(float[] xs) { this.xs = xs; } public float[] asFloatArray() { return xs; } public Object asArray() { return xs; } - public Object apply(int i) { return RunTime.box(xs[i]); } + public Object apply(int i) { return RunTime.box_fvalue(xs[i]); } public void update(int i, Object x) { xs[i] = ((Float)x).asFloat(); } public int length() { return xs.length; } public String toString() { return String.valueOf(xs); } @@ -517,7 +517,7 @@ class DArray extends Array { public DArray(double[] xs) { this.xs = xs; } public double[] asDoubleArray() { return xs; } public Object asArray() { return xs; } - public Object apply(int i) { return RunTime.box(xs[i]); } + public Object apply(int i) { return RunTime.box_dvalue(xs[i]); } public void update(int i, Object x) { xs[i] = ((Double)x).asDouble(); } public int length() { return xs.length; } public String toString() { return String.valueOf(xs); } diff --git a/sources/scala/tools/scalai/Constants.java b/sources/scala/tools/scalai/Constants.java index dfda06c436..7d87d3f6ab 100644 --- a/sources/scala/tools/scalai/Constants.java +++ b/sources/scala/tools/scalai/Constants.java @@ -37,7 +37,7 @@ public class Constants { // Public Methods - literal // !!! remove ? - public Object literal( ) { return RunTime.box ( ); } + public Object literal( ) { return RunTime.box_uvalue(); } public Object literal(boolean value) { return new Boolean (value); } public Object literal(byte value) { return new Byte (value); } public Object literal(short value) { return new Short (value); } diff --git a/sources/scala/tools/scalai/Evaluator.java b/sources/scala/tools/scalai/Evaluator.java index e940b7f194..9003ea47d9 100644 --- a/sources/scala/tools/scalai/Evaluator.java +++ b/sources/scala/tools/scalai/Evaluator.java @@ -174,7 +174,7 @@ public class Evaluator { case Store(Code target, Variable variable, Code expression): store(evaluate(target), variable, evaluate(expression)); - return RunTime.box(); + return RunTime.box_uvalue(); case Invoke(Code target, Function function, Code[] arguments, int pos): Object object = evaluate(target); diff --git a/sources/scalac/backend/Primitive.java b/sources/scalac/backend/Primitive.java index 68debab73d..3f8a658b3e 100644 --- a/sources/scalac/backend/Primitive.java +++ b/sources/scalac/backend/Primitive.java @@ -102,8 +102,8 @@ public class Primitive { public case THROW { tag = 51; } // throw x // RunTime operations - public case BOX { tag = 52; } // RunTime.box(x) - public case UNBOX { tag = 53; } // RunTime.<X>_unbox(x) + public case BOX { tag = 52; } // RunTime.box_<X>(x) + public case UNBOX { tag = 53; } // RunTime.unbox_<X>(x) public case NEW_ZARRAY { tag = 54; } // RunTime.zarray(x) public case NEW_BARRAY { tag = 55; } // RunTime.barray(x) public case NEW_SARRAY { tag = 56; } // RunTime.sarray(x) diff --git a/sources/scalac/backend/Primitives.java b/sources/scalac/backend/Primitives.java index 77224d4ffa..c21304de22 100644 --- a/sources/scalac/backend/Primitives.java +++ b/sources/scalac/backend/Primitives.java @@ -75,7 +75,26 @@ public class Primitives { private static final Name DARRAY_SET_N = Name.fromString("darray_set"); private static final Name OARRAY_SET_N = Name.fromString("oarray_set"); - private static final Name BOX_N = Name.fromString("box"); + private static final Name BOX_UVALUE_N = Name.fromString("box_uvalue"); + private static final Name BOX_ZVALUE_N = Name.fromString("box_zvalue"); + private static final Name BOX_BVALUE_N = Name.fromString("box_bvalue"); + private static final Name BOX_SVALUE_N = Name.fromString("box_svalue"); + private static final Name BOX_CVALUE_N = Name.fromString("box_cvalue"); + private static final Name BOX_IVALUE_N = Name.fromString("box_ivalue"); + private static final Name BOX_LVALUE_N = Name.fromString("box_lvalue"); + private static final Name BOX_FVALUE_N = Name.fromString("box_fvalue"); + private static final Name BOX_DVALUE_N = Name.fromString("box_dvalue"); + + private static final Name BOX_ZARRAY_N = Name.fromString("box_zarray"); + private static final Name BOX_BARRAY_N = Name.fromString("box_barray"); + private static final Name BOX_SARRAY_N = Name.fromString("box_sarray"); + private static final Name BOX_CARRAY_N = Name.fromString("box_carray"); + private static final Name BOX_IARRAY_N = Name.fromString("box_iarray"); + private static final Name BOX_LARRAY_N = Name.fromString("box_larray"); + private static final Name BOX_FARRAY_N = Name.fromString("box_farray"); + private static final Name BOX_DARRAY_N = Name.fromString("box_darray"); + private static final Name BOX_OARRAY_N = Name.fromString("box_oarray"); + private static final Name BOX__ARRAY_N = Name.fromString("box__array"); private static final Name UNBOX_UVALUE_N = Name.fromString("unbox_uvalue"); private static final Name UNBOX_ZVALUE_N = Name.fromString("unbox_zvalue"); @@ -375,26 +394,25 @@ public class Primitives { this.FARRAY_SET = getUniqueTerm(RUNTIME, FARRAY_SET_N); this.DARRAY_SET = getUniqueTerm(RUNTIME, DARRAY_SET_N); this.OARRAY_SET = getUniqueTerm(RUNTIME, OARRAY_SET_N); - Symbol[] boxes = getTerm(RUNTIME, BOX_N).alternativeSymbols(); - this.BOX_UVALUE = getBoxUnit(boxes); - this.BOX_ZVALUE = getBoxValue(boxes, definitions.BOOLEAN_TYPE()); - this.BOX_BVALUE = getBoxValue(boxes, definitions.BYTE_TYPE()); - this.BOX_SVALUE = getBoxValue(boxes, definitions.SHORT_TYPE()); - this.BOX_CVALUE = getBoxValue(boxes, definitions.CHAR_TYPE()); - this.BOX_IVALUE = getBoxValue(boxes, definitions.INT_TYPE()); - this.BOX_LVALUE = getBoxValue(boxes, definitions.LONG_TYPE()); - this.BOX_FVALUE = getBoxValue(boxes, definitions.FLOAT_TYPE()); - this.BOX_DVALUE = getBoxValue(boxes, definitions.DOUBLE_TYPE()); - this.BOX_ZARRAY = getBoxArray(boxes, definitions.BOOLEAN_TYPE()); - this.BOX_BARRAY = getBoxArray(boxes, definitions.BYTE_TYPE()); - this.BOX_SARRAY = getBoxArray(boxes, definitions.SHORT_TYPE()); - this.BOX_CARRAY = getBoxArray(boxes, definitions.CHAR_TYPE()); - this.BOX_IARRAY = getBoxArray(boxes, definitions.INT_TYPE()); - this.BOX_LARRAY = getBoxArray(boxes, definitions.LONG_TYPE()); - this.BOX_FARRAY = getBoxArray(boxes, definitions.FLOAT_TYPE()); - this.BOX_DARRAY = getBoxArray(boxes, definitions.DOUBLE_TYPE()); - this.BOX_OARRAY = getBoxArray(boxes, definitions.JAVA_OBJECT_TYPE()); - this.BOX__ARRAY = getBoxArray(boxes, definitions.ANY_TYPE()); + this.BOX_UVALUE = getUniqueTerm(RUNTIME, BOX_UVALUE_N); + this.BOX_ZVALUE = getUniqueTerm(RUNTIME, BOX_ZVALUE_N); + this.BOX_BVALUE = getUniqueTerm(RUNTIME, BOX_BVALUE_N); + this.BOX_SVALUE = getUniqueTerm(RUNTIME, BOX_SVALUE_N); + this.BOX_CVALUE = getUniqueTerm(RUNTIME, BOX_CVALUE_N); + this.BOX_IVALUE = getUniqueTerm(RUNTIME, BOX_IVALUE_N); + this.BOX_LVALUE = getUniqueTerm(RUNTIME, BOX_LVALUE_N); + this.BOX_FVALUE = getUniqueTerm(RUNTIME, BOX_FVALUE_N); + this.BOX_DVALUE = getUniqueTerm(RUNTIME, BOX_DVALUE_N); + this.BOX_ZARRAY = getUniqueTerm(RUNTIME, BOX_ZARRAY_N); + this.BOX_BARRAY = getUniqueTerm(RUNTIME, BOX_BARRAY_N); + this.BOX_SARRAY = getUniqueTerm(RUNTIME, BOX_SARRAY_N); + this.BOX_CARRAY = getUniqueTerm(RUNTIME, BOX_CARRAY_N); + this.BOX_IARRAY = getUniqueTerm(RUNTIME, BOX_IARRAY_N); + this.BOX_LARRAY = getUniqueTerm(RUNTIME, BOX_LARRAY_N); + this.BOX_FARRAY = getUniqueTerm(RUNTIME, BOX_FARRAY_N); + this.BOX_DARRAY = getUniqueTerm(RUNTIME, BOX_DARRAY_N); + this.BOX_OARRAY = getUniqueTerm(RUNTIME, BOX_OARRAY_N); + this.BOX__ARRAY = getUniqueTerm(RUNTIME, BOX__ARRAY_N); this.UNBOX_UVALUE = getUniqueTerm(RUNTIME, UNBOX_UVALUE_N); this.UNBOX_ZVALUE = getUniqueTerm(RUNTIME, UNBOX_ZVALUE_N); this.UNBOX_BVALUE = getUniqueTerm(RUNTIME, UNBOX_BVALUE_N); @@ -488,34 +506,6 @@ public class Primitives { //######################################################################## // Private interface - private Symbol getBoxUnit(Symbol[] alts) { - for (int i = 0; i < alts.length; i++) { - switch (alts[i].type()) { - case MethodType(Symbol[] vparams, _): - if (vparams.length == 0) - return alts[i]; - } - } - throw Debug.abort("not found:" + BOX_N + "()"); - } - - private Symbol getBoxValue(Symbol[] alts, Type type) { - for (int i = 0; i < alts.length; i++) { - Type result = alts[i].type().resultType(); - switch (alts[i].type()) { - case PolyType(Symbol[] tparams, _): - result = result.subst(tparams, Symbol.info(tparams)); - } - if (result.equals(type)) return alts[i]; - } - throw Debug.abort("not found: def " +BOX_N+ "(" +type+ "): " +type); - } - - private Symbol getBoxArray(Symbol[] alts, Type type) { - Type array = definitions.ARRAY_CLASS.type(); - return getBoxValue(alts, Type.appliedType(array, new Type[]{type})); - } - private Symbol getUniqueTerm(Symbol owner, Name name) { Symbol symbol = getTerm(owner, name); assert !symbol.isOverloaded() : |