Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite dotty to indent after #17522 #17618

Closed
wants to merge 5 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 2 additions & 4 deletions compiler/src/dotty/tools/MainGenericCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ case class CompileSettings(
compiler: Boolean = false,
quiet: Boolean = false,
colors: Boolean = false,
) {
):
def withCompileMode(em: CompileMode): CompileSettings = this.compileMode match
case CompileMode.Guess =>
this.copy(compileMode = em)
Expand Down Expand Up @@ -83,9 +83,8 @@ case class CompileSettings(

def withNoColors: CompileSettings =
this.copy(colors = false)
}

object MainGenericCompiler {
object MainGenericCompiler:

val classpathSeparator = File.pathSeparator

Expand Down Expand Up @@ -185,4 +184,3 @@ object MainGenericCompiler {

run(settings)
end main
}
12 changes: 4 additions & 8 deletions compiler/src/dotty/tools/MainGenericRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ case class Settings(
modeShouldBePossibleRun: Boolean = false,
modeShouldBeRun: Boolean = false,
compiler: Boolean = false,
) {
):
def withExecuteMode(em: ExecuteMode): Settings = this.executeMode match
case ExecuteMode.Guess | ExecuteMode.PossibleRun =>
this.copy(executeMode = em)
Expand Down Expand Up @@ -94,9 +94,8 @@ case class Settings(

def withCompiler: Settings =
this.copy(compiler = true)
}

object MainGenericRunner {
object MainGenericRunner:

val classpathSeparator = File.pathSeparator

Expand Down Expand Up @@ -212,7 +211,7 @@ object MainGenericRunner {
case ExecuteMode.Run =>
val scalaClasspath = ClasspathFromClassloader(Thread.currentThread().getContextClassLoader).split(classpathSeparator)
val newClasspath = (settings.classPath.flatMap(_.split(classpathSeparator).filter(_.nonEmpty)) ++ removeCompiler(scalaClasspath) :+ ".").map(File(_).toURI.toURL)
ObjectRunner.runAndCatch(newClasspath, settings.targetToRun, settings.residualArgs).flatMap {
ObjectRunner.runAndCatch(newClasspath, settings.targetToRun, settings.residualArgs).flatMap:
case ex: ClassNotFoundException if ex.getMessage == settings.targetToRun =>
val file = settings.targetToRun
Jar(file).mainClass match
Expand All @@ -221,7 +220,6 @@ object MainGenericRunner {
case None =>
Some(IllegalArgumentException(s"No main class defined in manifest in jar: $file"))
case ex => Some(ex)
}

case ExecuteMode.Script =>
val targetScript = Paths.get(settings.targetScript).toFile
Expand Down Expand Up @@ -250,10 +248,9 @@ object MainGenericRunner {
scripting.Main.process(properArgs.toArray)

case ExecuteMode.Expression =>
val cp = settings.classPath match {
val cp = settings.classPath match
case Nil => ""
case list => list.mkString(classpathSeparator)
}
val cpArgs = if cp.isEmpty then Nil else List("-classpath", cp)
val properArgs = cpArgs ++ settings.residualArgs ++ settings.scalaArgs
val driver = StringDriver(properArgs.toArray, settings.targetExpression)
Expand All @@ -280,4 +277,3 @@ object MainGenericRunner {
def main(args: Array[String]): Unit =
if (!process(args)) System.exit(1)

}
30 changes: 10 additions & 20 deletions compiler/src/dotty/tools/backend/ScalaPrimitivesOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package backend

object ScalaPrimitivesOps extends ScalaPrimitivesOps

class ScalaPrimitivesOps {
class ScalaPrimitivesOps:
// Arithmetic unary operations
inline val POS = 1 // +x
inline val NEG = 2 // -x
Expand Down Expand Up @@ -165,68 +165,58 @@ class ScalaPrimitivesOps {
def isArrayOp(code: Int): Boolean =
isArrayNew(code) | isArrayLength(code) | isArrayGet(code) | isArraySet(code)

def isArrayNew(code: Int): Boolean = code match {
def isArrayNew(code: Int): Boolean = code match
case NEW_ZARRAY | NEW_BARRAY | NEW_SARRAY | NEW_CARRAY |
NEW_IARRAY | NEW_LARRAY | NEW_FARRAY | NEW_DARRAY |
NEW_OARRAY => true
case _ => false
}

def isArrayLength(code: Int): Boolean = code match {
def isArrayLength(code: Int): Boolean = code match
case ZARRAY_LENGTH | BARRAY_LENGTH | SARRAY_LENGTH | CARRAY_LENGTH |
IARRAY_LENGTH | LARRAY_LENGTH | FARRAY_LENGTH | DARRAY_LENGTH |
OARRAY_LENGTH | LENGTH => true
case _ => false
}

def isArrayGet(code: Int): Boolean = code match {
def isArrayGet(code: Int): Boolean = code match
case ZARRAY_GET | BARRAY_GET | SARRAY_GET | CARRAY_GET |
IARRAY_GET | LARRAY_GET | FARRAY_GET | DARRAY_GET |
OARRAY_GET | APPLY => true
case _ => false
}

def isArraySet(code: Int): Boolean = code match {
def isArraySet(code: Int): Boolean = code match
case ZARRAY_SET | BARRAY_SET | SARRAY_SET | CARRAY_SET |
IARRAY_SET | LARRAY_SET | FARRAY_SET | DARRAY_SET |
OARRAY_SET | UPDATE => true
case _ => false
}

/** Check whether the given code is a comparison operator */
def isComparisonOp(code: Int): Boolean = code match {
def isComparisonOp(code: Int): Boolean = code match
case ID | NI | EQ | NE |
LT | LE | GT | GE => true

case _ => false
}
def isUniversalEqualityOp(code: Int): Boolean = (code == EQ) || (code == NE)
def isReferenceEqualityOp(code: Int): Boolean = (code == ID) || (code == NI)

def isArithmeticOp(code: Int): Boolean = code match {
def isArithmeticOp(code: Int): Boolean = code match
case POS | NEG | NOT => true; // unary
case ADD | SUB | MUL |
DIV | MOD => true; // binary
case OR | XOR | AND |
LSL | LSR | ASR => true; // bitwise
case _ => false
}

def isLogicalOp(code: Int): Boolean = code match {
def isLogicalOp(code: Int): Boolean = code match
case ZNOT | ZAND | ZOR => true
case _ => false
}

def isShiftOp(code: Int): Boolean = code match {
def isShiftOp(code: Int): Boolean = code match
case LSL | LSR | ASR => true
case _ => false
}

def isBitwiseOp(code: Int): Boolean = code match {
def isBitwiseOp(code: Int): Boolean = code match
case OR | XOR | AND => true
case _ => false
}

def isCoercion(code: Int): Boolean = (code >= B2B) && (code <= D2D)

}
12 changes: 4 additions & 8 deletions compiler/src/dotty/tools/backend/WorklistAlgorithm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,20 @@ package backend
* @version 1.0
* @see [[scala.tools.nsc.backend.icode.Linearizers]]
*/
trait WorklistAlgorithm {
trait WorklistAlgorithm:
type Elem
class WList {
class WList:
private var list: List[Elem] = Nil
def isEmpty = list.isEmpty
def nonEmpty = !isEmpty
def push(e: Elem): Unit = { list = e :: list }
def pop(): Elem = {
def pop(): Elem =
val head = list.head
list = list.tail
head
}
def pushAll(xs: Iterable[Elem]): Unit = xs.foreach(push)
def clear(): Unit = list = Nil

}

val worklist: WList

Expand All @@ -38,12 +36,11 @@ trait WorklistAlgorithm {
* The initializer is run once before the loop starts and should
* initialize the worklist.
*/
def run(initWorklist: => Unit) = {
def run(initWorklist: => Unit) =
initWorklist

while (worklist.nonEmpty)
processElement(dequeue)
}

/**
* Process the current element from the worklist.
Expand All @@ -54,4 +51,3 @@ trait WorklistAlgorithm {
* Remove and return the first element to be processed from the worklist.
*/
def dequeue: Elem
}
15 changes: 5 additions & 10 deletions compiler/src/dotty/tools/backend/jvm/AsmUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.io.PrintWriter
import scala.tools.asm.util.{TraceClassVisitor, TraceMethodVisitor, Textifier}
import scala.tools.asm.ClassReader

object AsmUtils {
object AsmUtils:

/**
* Print the bytecode of methods generated by GenBCode to the standard output. Only methods
Expand All @@ -33,33 +33,28 @@ object AsmUtils {
inline val traceSerializedClassEnabled = false
inline val traceSerializedClassPattern = ""

def traceMethod(mnode: MethodNode1): Unit = {
def traceMethod(mnode: MethodNode1): Unit =
println(s"Bytecode for method ${mnode.name}")
val p = new Textifier
val tracer = new TraceMethodVisitor(p)
mnode.accept(tracer)
val w = new PrintWriter(System.out)
p.print(w)
w.flush()
}

def traceClass(cnode: ClassNode1): Unit = {
def traceClass(cnode: ClassNode1): Unit =
println(s"Bytecode for class ${cnode.name}")
val w = new PrintWriter(System.out)
cnode.accept(new TraceClassVisitor(w))
w.flush()
}

def traceClass(bytes: Array[Byte]): Unit = traceClass(readClass(bytes))

def readClass(bytes: Array[Byte]): ClassNode1 = {
def readClass(bytes: Array[Byte]): ClassNode1 =
val node = new ClassNode1()
new ClassReader(bytes).accept(node, 0)
node
}

def instructionString(instruction: AbstractInsnNode): String = instruction.getOpcode match {
def instructionString(instruction: AbstractInsnNode): String = instruction.getOpcode match
case -1 => instruction.toString
case op => scala.tools.asm.util.Printer.OPCODES(op)
}
}
Loading