Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
stack.pop()

(code: @switch) match {
case ADD => bc add resKind
case SUB => bc sub resKind
case MUL => bc mul resKind
case DIV => bc div resKind
case MOD => bc rem resKind
case ADD => bc.add(resKind)
case SUB => bc.sub(resKind)
case MUL => bc.mul(resKind)
case DIV => bc.div(resKind)
case MOD => bc.rem(resKind)

case OR | XOR | AND => bc.genPrimitiveLogical(code, resKind)

Expand Down Expand Up @@ -271,11 +271,11 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
genCond(tree, success, failure, targetIfNoJump = success)
// success block
markProgramPoint(success)
bc boolconst true
bc goTo after
bc.boolconst(true)
bc.goTo(after)
// failure block
markProgramPoint(failure)
bc boolconst false
bc.boolconst(false)
// after
markProgramPoint(after)

Expand Down Expand Up @@ -501,16 +501,16 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
val stackDiff = stack.heightDiffWrt(targetStackSize)
if stackDiff != 0 then
if expectedType == UNIT then
bc dropMany stackDiff
bc.dropMany(stackDiff)
else
val loc = locals.makeTempLocal(expectedType)
bc.store(loc.idx, expectedType)
bc dropMany stackDiff
bc.dropMany(stackDiff)
bc.load(loc.idx, expectedType)
end if
bc goTo label
bc.goTo(label)
case LoadDestination.Return =>
bc emitRETURN returnType
bc.emitRETURN(returnType)
case LoadDestination.Throw =>
val thrownType = expectedType
// `throw null` is valid although scala.Null (as defined in src/libray-aux) isn't a subtype of Throwable.
Expand Down Expand Up @@ -634,7 +634,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
}
locals.store(earlyReturnVar)
}
bc goTo nextCleanup
bc.goTo(nextCleanup)
shouldEmitCleanup = true
}
} else {
Expand Down Expand Up @@ -697,20 +697,20 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
if (l.isPrimitive && r.isPrimitive)
genConversion(l, r, cast)
else if (l.isPrimitive) {
bc drop l
bc.drop(l)
if (cast) {
mnode.visitTypeInsn(asm.Opcodes.NEW, jlClassCastExceptionRef.internalName)
bc dup ObjectRef
bc.dup(ObjectRef)
emit(asm.Opcodes.ATHROW)
} else {
bc boolconst false
bc.boolconst(false)
}
}
else if (r.isPrimitive && cast) {
abort(s"Erasure should have added an unboxing operation to prevent this cast. Tree: $t")
}
else if (r.isPrimitive) {
bc isInstance boxedClassOfPrimitive(r.asPrimitiveBType)
bc.isInstance(boxedClassOfPrimitive(r.asPrimitiveBType))
}
else {
assert(r.isRef, r) // ensure that it's not a method
Expand All @@ -737,7 +737,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
}
genLoadArguments(args, List.fill(args.size)(INT))
(argsSize /*: @switch*/) match {
case 1 => bc newarray elemKind
case 1 => bc.newarray(elemKind)
case _ =>
val descr = ("[" * argsSize) + elemKind.descriptor // denotes the same as: arrayN(elemKind, argsSize).descriptor
mnode.visitMultiANewArrayInsn(descr, argsSize)
Expand Down Expand Up @@ -792,7 +792,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
case rt: ClassBType =>
assert(classBTypeFromSymbol(ctor.owner) == rt, s"Symbol ${ctor.owner.showFullName} is different from $rt")
mnode.visitTypeInsn(asm.Opcodes.NEW, rt.internalName)
bc dup generatedType
bc.dup(generatedType)
stack.push(rt)
stack.push(rt)
genLoadArguments(args, paramTKs(app))
Expand Down Expand Up @@ -888,8 +888,8 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
val elmKind = toTypeKind(elemType)
val generatedType = ArrayBType(elmKind)

bc iconst elems.length
bc newarray elmKind
bc.iconst(elems.length)
bc.newarray(elmKind)

// during the genLoad below, there is the result, its dup, and the index
stack.push(generatedType)
Expand All @@ -899,10 +899,10 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
var i = 0
var rest = elems
while (!rest.isEmpty) {
bc dup generatedType
bc iconst i
bc.dup( generatedType)
bc.iconst( i)
genLoad(rest.head, elmKind)
bc astore elmKind
bc.astore( elmKind)
rest = rest.tail
i = i + 1
}
Expand Down Expand Up @@ -1070,7 +1070,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
}
markProgramPoint(keepGoing)
}
bc goTo default
bc.goTo(default)
}

// emit blocks for common patterns
Expand Down Expand Up @@ -1111,7 +1111,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
def adapt(from: BType, to: BType): Unit = {
if (!from.conformsTo(to)) {
to match {
case UNIT => bc drop from
case UNIT => bc.drop(from)
case _ => bc.emitT2T(from, to)
}
} else if (from.isNothingType) {
Expand Down Expand Up @@ -1174,7 +1174,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
* inserted instead - after all, an expression of type scala.runtime.Null$ can only be null.
*/
if (lastInsn.getOpcode != asm.Opcodes.ACONST_NULL) {
bc drop from
bc.drop(from)
emit(asm.Opcodes.ACONST_NULL)
}
}
Expand Down Expand Up @@ -1248,14 +1248,14 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
def genConversion(from: BType, to: BType, cast: Boolean): Unit = {
if (cast) { bc.emitT2T(from, to) }
else {
bc drop from
bc boolconst (from == to)
bc.drop(from)
bc.boolconst(from == to)
}
}

def genCast(to: RefBType, cast: Boolean): Unit = {
if (cast) { bc checkCast to }
else { bc isInstance to }
if cast then bc.checkCast(to)
else bc.isInstance(to)
}

/* Is the given symbol a primitive operation? */
Expand Down Expand Up @@ -1504,7 +1504,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
}
bc.emitIF(op, success)
}
if (targetIfNoJump != failure) bc goTo failure
if (targetIfNoJump != failure) bc.goTo(failure)
}
}

Expand All @@ -1517,8 +1517,8 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
bc.emitIF(op, success)
} else if (tk.isRef) { // REFERENCE(_) | ARRAY(_)
(op: @unchecked) match { // references are only compared with EQ and NE
case EQ => bc emitIFNULL success
case NE => bc emitIFNONNULL success
case EQ => bc.emitIFNULL( success)
case NE => bc.emitIFNONNULL(success)
}
} else {
def useCmpG = if (negated) op == GT || op == GE else op == LT || op == LE
Expand All @@ -1535,7 +1535,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
}
bc.emitIF(op, success)
}
if (targetIfNoJump != failure) bc goTo failure
if (targetIfNoJump != failure) bc.goTo(failure)
}
}

Expand Down Expand Up @@ -1663,12 +1663,12 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
val areSameFinals = l.tpe.typeSymbol.is(Final) && r.tpe.typeSymbol.is(Final) && (l.tpe =:= r.tpe)
// todo: remove
def isMaybeBoxed(sym: Symbol): Boolean = {
(sym == defn.ObjectClass) ||
(sym == defn.JavaSerializableClass) ||
(sym == defn.ComparableClass) ||
(sym derivesFrom defn.BoxedNumberClass) ||
(sym derivesFrom defn.BoxedCharClass) ||
(sym derivesFrom defn.BoxedBooleanClass)
sym == defn.ObjectClass
|| sym == defn.JavaSerializableClass
|| sym == defn.ComparableClass
|| sym.derivesFrom(defn.BoxedNumberClass)
|| sym.derivesFrom(defn.BoxedCharClass)
|| sym.derivesFrom(defn.BoxedBooleanClass)
}
!areSameFinals && isMaybeBoxed(l.tpe.typeSymbol) && isMaybeBoxed(r.tpe.typeSymbol)
}
Expand Down Expand Up @@ -1722,11 +1722,11 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
genLoad(r, ObjectRef)
stack.pop()
locals.store(eqEqTempLocal)
bc dup ObjectRef
bc.dup(ObjectRef)
genCZJUMP(lNull, lNonNull, Primitives.EQ, ObjectRef, targetIfNoJump = lNull)

markProgramPoint(lNull)
bc drop ObjectRef
bc.drop(ObjectRef)
locals.load(eqEqTempLocal)
genCZJUMP(success, failure, Primitives.EQ, ObjectRef, targetIfNoJump = lNonNull)

Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ trait BCodeHelpers extends BCodeIdiomatic {
val versionPickle = {
val vp = new PickleBuffer(new Array[Byte](16), -1, 0)
assert(vp.writeIndex == 0, vp)
vp writeNat PickleFormat.MajorVersion
vp writeNat PickleFormat.MinorVersion
vp writeNat 0
vp.writeNat(PickleFormat.MajorVersion)
vp.writeNat(PickleFormat.MinorVersion)
vp.writeNat(0)
vp
}

Expand Down Expand Up @@ -531,7 +531,7 @@ trait BCodeHelpers extends BCodeIdiomatic {
val buffer = mutable.ListBuffer[Symbol]()
names.foreach { name =>
buffer ++= tp.memberBasedOnFlags(name, required, excluded)
.alternatives.sortBy(_.signature)(Signature.lexicographicOrdering).map(_.symbol)
.alternatives.sortBy(_.signature)(using Signature.lexicographicOrdering).map(_.symbol)
}
buffer.toList
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,13 @@ trait BCodeSkelBuilder extends BCodeHelpers {
case labnode: asm.tree.LabelNode => labnode.getLabel
case _ =>
val pp = new asm.Label
mnode visitLabel pp
mnode.visitLabel(pp)
pp
}
}
def markProgramPoint(lbl: asm.Label): Unit = {
val skip = (lbl == null) || isAtProgramPoint(lbl)
if (!skip) { mnode visitLabel lbl }
if (!skip) { mnode.visitLabel(lbl) }
}
def isAtProgramPoint(lbl: asm.Label): Boolean = {
def getNonLineNumberNode(a: asm.tree.AbstractInsnNode): asm.tree.AbstractInsnNode = a match {
Expand Down
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/backend/jvm/BCodeSyncAndTry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {

/* ------ (1) pushing and entering the monitor, also keeping a reference to it in a local var. ------ */
genLoadQualifier(fun)
bc dup ObjectRef
bc.dup(ObjectRef)
locals.store(monitor)
emit(asm.Opcodes.MONITORENTER)

Expand Down Expand Up @@ -68,7 +68,7 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
emit(asm.Opcodes.MONITOREXIT)
if (hasResult) { locals.load(monitorResult) }
val postHandler = new asm.Label
bc goTo postHandler
bc.goTo(postHandler)

/* ------ (4) exception-handler version of monitor-exit code.
* Reached upon abrupt termination of (2).
Expand Down Expand Up @@ -99,7 +99,7 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
* Protected by whatever protects the whole synchronized expression.
* ------
*/
mnode visitLabel postHandler
mnode.visitLabel(postHandler)

lineNumber(tree)

Expand Down Expand Up @@ -258,7 +258,7 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
unregisterCleanup(finCleanup)
nopIfNeeded(startTryBody)
val endTryBody = currProgramPoint()
bc goTo postHandlers
bc.goTo(postHandlers)

/**
* A return within a `try` or `catch` block where a `finally` is present ("early return")
Expand Down Expand Up @@ -305,7 +305,7 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
registerCleanup(finCleanup)
ch match {
case NamelessEH(typeToDrop, caseBody) =>
bc drop typeToDrop
bc.drop(typeToDrop)
genLoad(caseBody, kind) // adapts caseBody to `kind`, thus it can be stored, if `guardResult`, in `tmp`.
nopIfNeeded(startHandler)
endHandler = currProgramPoint()
Expand All @@ -326,7 +326,7 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
// (2.b) mark the try-body as protected by this case clause.
protect(startTryBody, endTryBody, startHandler, excType)
// (2.c) emit jump to the program point where the finally-clause-for-normal-exit starts, or in effect `after` if no finally-clause was given.
bc goTo postHandlers
bc.goTo(postHandlers)

}

Expand Down Expand Up @@ -434,12 +434,12 @@ trait BCodeSyncAndTry extends BCodeBodyBuilder {
locals.load(earlyReturnVar)
bc.emitRETURN(locals(earlyReturnVar).tk)
} else {
bc emitRETURN UNIT
bc.emitRETURN(UNIT)
}
shouldEmitCleanup = false

case nextCleanup :: _ =>
bc goTo nextCleanup
bc.goTo(nextCleanup)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BackendUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class BackendUtils(val postProcessor: PostProcessor) {
*/
final def addInnerClasses(jclass: asm.ClassVisitor, declaredInnerClasses: List[ClassBType], refedInnerClasses: List[ClassBType]): Unit = {
// sorting ensures nested classes are listed after their enclosing class thus satisfying the Eclipse Java compiler
val allNestedClasses = new mutable.TreeSet[ClassBType]()(Ordering.by(_.internalName))
val allNestedClasses = new mutable.TreeSet[ClassBType]()(using Ordering.by(_.internalName))
allNestedClasses ++= declaredInnerClasses
refedInnerClasses.foreach(allNestedClasses ++= _.enclosingNestedClassesChain)
for nestedClass <- allNestedClasses
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,9 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
else throw new FileConflictException(s"${base.path}/${path}: ${dir.path} is not a directory")
val components = path.split('/')
var dir = base
for (i <- 0 until components.length - 1) dir = ensureDirectory(dir) subdirectoryNamed components(i).toString
ensureDirectory(dir) fileNamed components.last.toString
for i <- 0 until components.length - 1 do
dir = ensureDirectory(dir).subdirectoryNamed(components(i).toString)
ensureDirectory(dir).fileNamed(components.last.toString)
}

private def writeBytes(outFile: AbstractFile, bytes: Array[Byte]): Unit = {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/scalaPrimitives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class DottyPrimitives(ictx: Context) {

/** Add a primitive operation to the map */
def addPrimitive(s: Symbol, code: Int): Unit = {
assert(!(primitives contains s), "Duplicate primitive " + s)
assert(!primitives.contains(s), "Duplicate primitive " + s)
primitives(s) = code
}

Expand Down
Loading
Loading