summaryrefslogtreecommitdiff
path: root/sources/scalac/backend
diff options
context:
space:
mode:
authorschinz <schinz@epfl.ch>2003-11-18 15:19:44 +0000
committerschinz <schinz@epfl.ch>2003-11-18 15:19:44 +0000
commit5fb655da1e4efa67f2b2fccdf87a45c0d88090e7 (patch)
treed5266f0f1f03f6137e2f5fde83d7ea7471f5365c /sources/scalac/backend
parente914e7a9dec02980cb7666e997793078d0694deb (diff)
downloadscala-5fb655da1e4efa67f2b2fccdf87a45c0d88090e7.tar.gz
scala-5fb655da1e4efa67f2b2fccdf87a45c0d88090e7.tar.bz2
scala-5fb655da1e4efa67f2b2fccdf87a45c0d88090e7.zip
- recognise scala.runtime.Runtime.oarray as a p...
- recognise scala.runtime.Runtime.oarray as a primitive and inline it.
Diffstat (limited to 'sources/scalac/backend')
-rw-r--r--sources/scalac/backend/jvm/GenJVM.java40
1 files changed, 34 insertions, 6 deletions
diff --git a/sources/scalac/backend/jvm/GenJVM.java b/sources/scalac/backend/jvm/GenJVM.java
index 692934092c..b3219ae93c 100644
--- a/sources/scalac/backend/jvm/GenJVM.java
+++ b/sources/scalac/backend/jvm/GenJVM.java
@@ -321,6 +321,12 @@ class GenJVM {
generatedType = expectedType;
break;
+ case NEW_OARRAY: {
+ assert args.length == 2;
+ genRefArrayCreate(ctx, args[0], args[1]);
+ generatedType = expectedType;
+ } break;
+
case NEW_ZARRAY : case NEW_BARRAY : case NEW_SARRAY :
case NEW_CARRAY : case NEW_IARRAY : case NEW_LARRAY :
case NEW_FARRAY : case NEW_DARRAY :
@@ -695,17 +701,17 @@ class GenJVM {
case ZOR:
case ZAND:
- JCode.Label afterLabel = ctx.code.newLabel();
if (when ^ (prim == Primitive.ZAND)) {
// x || y jump if true -or- x && y jump if false
genCond(ctx, unbox(allArgs[0]), target, when);
genCond(ctx, allArgs[1], target, when);
} else {
// x || y jump if false -or- x && y jump if true
+ JCode.Label afterLabel = ctx.code.newLabel();
genCond(ctx, unbox(allArgs[0]), afterLabel, !when);
genCond(ctx, allArgs[1], target, when);
+ afterLabel.anchorToNext();
}
- afterLabel.anchorToNext();
return;
}
}
@@ -967,8 +973,8 @@ class GenJVM {
//////////////////////////////////////////////////////////////////////
/**
- * Generate code to create an array, whose size will be
- * dynamically computed.
+ * Generate code to create an array of some basic type, whose size
+ * will be dynamically computed.
*/
protected void genArrayCreate(Context ctx, Primitive prim, Tree size) {
genLoad(ctx, size, JType.INT);
@@ -988,6 +994,29 @@ class GenJVM {
}
/**
+ * Generate code to create an array of references, whose size will
+ * be dynamically computed.
+ */
+ protected void genRefArrayCreate(Context ctx, Tree size, Tree classNameLit) {
+ genLoad(ctx, size, JType.INT);
+
+ String className;
+ switch (classNameLit) {
+ case Literal(Object name): className = (String)name; break;
+ default: throw global.fail("invalid argument for oarray " + classNameLit);
+ }
+
+ JReferenceType elemType;
+ switch (className.charAt(0)) {
+ case '[': case 'L':
+ elemType = (JReferenceType)JType.parseSignature(className); break;
+ default:
+ elemType = new JObjectType(className);
+ }
+ ctx.code.emitANEWARRAY(elemType);
+ }
+
+ /**
* Generate code to update an array.
*/
protected void genArrayUpdate(Context ctx, Tree array, Tree index, Tree value) {
@@ -1124,12 +1153,11 @@ class GenJVM {
case AS_CARRAY : case AS_IARRAY : case AS_LARRAY :
case AS_FARRAY : case AS_DARRAY : case AS_OARRAY :
case AS__ARRAY :
- case NEW_OARRAY :
case EQUALS :
case HASHCODE :
case TOSTRING :
case BOX :
- case APPLY : case UPDATE : case LENGTH :
+ case APPLY : case UPDATE : case LENGTH : case NEW_OARRAY :
return false;
default:
throw Debug.abort("unknown primitive", sym);