Skip to content

Commit a68980c

Browse files
committed
Merge pull request #251 from dotty-staging/shared-backend
Shared backend
2 parents 7f6d234 + 4c11203 commit a68980c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3900
-76
lines changed

bin/dotc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55

66
# Configuration
7-
SCALA_VERSION=2.11.1
7+
SCALA_VERSION=2.11.4
88
SCALA_BINARY_VERSION=2.11
9+
SCALA_COMPILER_VERSION=2.11.5-20141212-151631-beaa78b033
910
DOTTY_VERSION=0.1
1011
bootcp=true
1112
default_java_opts="-Xmx768m -Xms768m"
@@ -62,12 +63,18 @@ if [ "$SCALA_REFLECT_JAR" == "" ]
6263
then
6364
SCALA_REFLECT_JAR=$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-$SCALA_VERSION.jar
6465
fi
66+
if [ "$SCALA_COMPILER_JAR" == "" ]
67+
then
68+
SCALA_COMPILER_JAR=$HOME/.ivy2/cache/me.d-d/scala-compiler/jars/scala-compiler-$SCALA_COMPILER_VERSION.jar
69+
fi
6570

66-
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" ]
71+
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_COMPILER_JAR" ]
6772
then
6873
echo To use this script please set
6974
echo SCALA_LIBRARY_JAR to point to scala-library-$SCALA_VERSION.jar "(currently $SCALA_LIBRARY_JAR)"
7075
echo SCALA_REFLECT_JAR to point to scala-reflect-$SCALA_VERSION.jar "(currently $SCALA_REFLECT_JAR)"
76+
echo SCALA_COMPILER_JAR to point to scala-compiler-$SCALA_VERSION.jar with bcode patches "(currently $SCALA_COMPILER_JAR)"
77+
7178
fi
7279

7380
ifdebug () {
@@ -156,7 +163,7 @@ trap onExit INT
156163
# to java to suppress "." from materializing.
157164
classpathArgs () {
158165
if [[ -n $bootcp ]]; then
159-
echo "-Xbootclasspath/a:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$MAIN_JAR -classpath $MAIN_JAR"
166+
echo "-Xbootclasspath/a:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_COMPILER_JAR:$MAIN_JAR -classpath $MAIN_JAR"
160167
else
161168
echo "-classpath $SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$MAIN_JAR"
162169
fi

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
name := "dotty"
33

4-
scalaVersion in Global := "2.11.1"
4+
scalaVersion in Global := "2.11.4"
55

66
version in Global := "0.1-SNAPSHOT"
77

out/.keep

Whitespace-only changes.

project/Build.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ object DottyBuild extends Build {
3030

3131
// get reflect and xml onboard
3232
libraryDependencies ++= Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value,
33-
"org.scala-lang.modules" %% "scala-xml" % "1.0.1"),
33+
"org.scala-lang.modules" %% "scala-xml" % "1.0.1",
34+
"me.d-d" % "scala-compiler" % "2.11.5-20141212-151631-beaa78b033"),
3435

3536
// get junit onboard
3637
libraryDependencies += "com.novocode" % "junit-interface" % "0.11-RC1" % "test",
@@ -53,7 +54,7 @@ object DottyBuild extends Build {
5354

5455
// http://grokbase.com/t/gg/simple-build-tool/135ke5y90p/sbt-setting-jvm-boot-paramaters-for-scala
5556
javaOptions <++= (managedClasspath in Runtime, packageBin in Compile) map { (attList, bin) =>
56-
// put the Scala {library, reflect, compiler} in the classpath
57+
// put the Scala {library, reflect} in the classpath
5758
val path = for {
5859
file <- attList.map(_.data)
5960
path = file.getAbsolutePath
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package dotty.tools.backend.jvm
2+
3+
import dotty.tools.dotc.ast.tpd
4+
import dotty.tools.dotc.core.Contexts.Context
5+
import dotty.tools.dotc.core.Types
6+
import dotty.tools.dotc.transform.TreeTransforms.{TransformerInfo, TreeTransform, MiniPhase, MiniPhaseTransform}
7+
import dotty.tools.dotc.ast.tpd
8+
import dotty.tools.dotc
9+
import dotty.tools.dotc.backend.jvm.DottyPrimitives
10+
import dotty.tools.dotc.core.Flags.FlagSet
11+
import dotty.tools.dotc.transform.Erasure
12+
import dotty.tools.dotc.transform.SymUtils._
13+
import java.io.{File => JFile}
14+
15+
import scala.collection.generic.Clearable
16+
import scala.collection.mutable
17+
import scala.reflect.ClassTag
18+
import scala.reflect.internal.util.WeakHashSet
19+
import scala.reflect.io.{Directory, PlainDirectory, AbstractFile}
20+
import scala.tools.asm.{ClassVisitor, FieldVisitor, MethodVisitor}
21+
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}
22+
import dotty.tools.dotc.core._
23+
import Periods._
24+
import SymDenotations._
25+
import Contexts._
26+
import Types._
27+
import Symbols._
28+
import Denotations._
29+
import Phases._
30+
import java.lang.AssertionError
31+
import dotty.tools.dotc.util.Positions.Position
32+
import Decorators._
33+
import tpd._
34+
import StdNames.nme
35+
36+
/**
37+
* Created by dark on 26/11/14.
38+
*/
39+
class CollectEntryPoints extends MiniPhaseTransform {
40+
def phaseName: String = "Collect entry points"
41+
42+
override def transformDefDef(tree: tpd.DefDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = {
43+
if((tree.symbol ne NoSymbol) && CollectEntryPoints.isJavaEntyPoint(tree.symbol)) {
44+
ctx.genBCodePhase.asInstanceOf[GenBCode].registerEntryPoint(tree.symbol)
45+
}
46+
tree
47+
}
48+
}
49+
50+
object CollectEntryPoints{
51+
def isJavaEntyPoint(sym: Symbol)(implicit ctx: Context): Boolean = {
52+
import Types.MethodType
53+
val d = ctx.definitions
54+
val StringType = d.StringType
55+
def isJavaMainMethod(sym: Symbol) = (sym.name == nme.main) && (toDenot(sym).info match {
56+
case r@ MethodType(_, List(d.ArrayType(StringType))) => r.resultType eq d.UnitType
57+
case _ => false
58+
})
59+
// The given class has a main method.
60+
def hasJavaMainMethod(sym: Symbol): Boolean =
61+
(toDenot(sym).info member nme.main).alternatives exists(x => isJavaMainMethod(x.symbol))
62+
63+
def fail(msg: String, pos: Position = sym.pos) = {
64+
ctx.warning( sym.name +
65+
s" has a main method with parameter type Array[String], but ${toDenot(sym).fullName} will not be a runnable program.\n Reason: $msg",
66+
sourcePos(sym.pos)
67+
// TODO: make this next claim true, if possible
68+
// by generating valid main methods as static in module classes
69+
// not sure what the jvm allows here
70+
// + " You can still run the program by calling it as " + javaName(sym) + " instead."
71+
)
72+
false
73+
}
74+
def failNoForwarder(msg: String) = {
75+
fail(s"$msg, which means no static forwarder can be generated.\n")
76+
}
77+
val possibles = if (sym.flags is Flags.Module) (toDenot(sym).info nonPrivateMember nme.main).alternatives else Nil
78+
val hasApproximate = possibles exists { m =>
79+
m.info match {
80+
case MethodType(_, p :: Nil) =>
81+
p.typeSymbol == defn.ArrayClass
82+
case _ => false
83+
}
84+
}
85+
// At this point it's a module with a main-looking method, so either succeed or warn that it isn't.
86+
hasApproximate && {
87+
// Before erasure so we can identify generic mains.
88+
{
89+
// implicit val c = ctx.withPhase(ctx.erasurePhase)
90+
91+
val companion = sym.asClass.moduleClass
92+
93+
if (hasJavaMainMethod(companion))
94+
failNoForwarder("companion contains its own main method")
95+
else if (toDenot(companion).info.member(nme.main) != NoDenotation)
96+
// this is only because forwarders aren't smart enough yet
97+
failNoForwarder("companion contains its own main method (implementation restriction: no main is allowed, regardless of signature)")
98+
else if (companion.flags is Flags.Trait)
99+
failNoForwarder("companion is a trait")
100+
// Now either succeeed, or issue some additional warnings for things which look like
101+
// attempts to be java main methods.
102+
else (possibles exists(x=> isJavaMainMethod(x.symbol))) || {
103+
possibles exists { m =>
104+
toDenot(m.symbol).info match {
105+
case t:PolyType =>
106+
fail("main methods cannot be generic.")
107+
case t@MethodType(paramNames, paramTypes) =>
108+
if (t.resultType :: paramTypes exists (_.typeSymbol.isAbstractType))
109+
fail("main methods cannot refer to type parameters or abstract types.", m.symbol.pos)
110+
else
111+
isJavaMainMethod(m.symbol) || fail("main method must have exact signature (Array[String])Unit", m.symbol.pos)
112+
case tp =>
113+
fail(s"don't know what this is: $tp", m.symbol.pos)
114+
}
115+
}
116+
}
117+
}
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)