aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r--src/dotty/tools/dotc/Compiler.scala17
-rw-r--r--src/dotty/tools/dotc/config/SJSPlatform.scala13
-rw-r--r--src/dotty/tools/dotc/config/ScalaSettings.scala1
-rw-r--r--src/dotty/tools/dotc/core/Contexts.scala25
-rw-r--r--src/dotty/tools/dotc/transform/LinkScala2ImplClasses.scala12
-rw-r--r--src/dotty/tools/dotc/transform/Memoize.scala1
-rw-r--r--src/dotty/tools/dotc/transform/Pickler.scala2
7 files changed, 61 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala
index f12ab66c5..be4477ee2 100644
--- a/src/dotty/tools/dotc/Compiler.scala
+++ b/src/dotty/tools/dotc/Compiler.scala
@@ -16,6 +16,7 @@ import core.DenotTransformers.DenotTransformer
import core.Denotations.SingleDenotation
import dotty.tools.backend.jvm.{LabelDefs, GenBCode}
+import dotty.tools.backend.sjs.GenSJSIR
class Compiler {
@@ -82,6 +83,7 @@ class Compiler {
List(new ExpandPrivate,
new CollectEntryPoints,
new LabelDefs),
+ List(new GenSJSIR),
List(new GenBCode)
)
@@ -99,8 +101,17 @@ class Compiler {
* imports For each element of RootImports, an import context
*/
def rootContext(implicit ctx: Context): Context = {
- ctx.definitions.init(ctx)
- ctx.setPhasePlan(phases)
+ ctx.initialize()(ctx)
+ val actualPhases = if (ctx.settings.scalajs.value) {
+ phases
+ } else {
+ // Remove Scala.js-related phases
+ phases.mapConserve(_.filter {
+ case _: GenSJSIR => false
+ case _ => true
+ }).filter(_.nonEmpty)
+ }
+ ctx.setPhasePlan(actualPhases)
val rootScope = new MutableScope
val bootstrap = ctx.fresh
.setPeriod(Period(nextRunId, FirstPhaseId))
@@ -111,7 +122,7 @@ class Compiler {
.setTyper(new Typer)
.setMode(Mode.ImplicitsEnabled)
.setTyperState(new MutableTyperState(ctx.typerState, ctx.typerState.reporter, isCommittable = true))
- ctx.definitions.init(start) // set context of definitions to start
+ ctx.initialize()(start) // re-initialize the base context with start
def addImport(ctx: Context, refFn: () => TermRef) =
ctx.fresh.setImportInfo(ImportInfo.rootImport(refFn)(ctx))
(start.setRunInfo(new RunInfo(start)) /: defn.RootImportFns)(addImport)
diff --git a/src/dotty/tools/dotc/config/SJSPlatform.scala b/src/dotty/tools/dotc/config/SJSPlatform.scala
new file mode 100644
index 000000000..fec9c25a1
--- /dev/null
+++ b/src/dotty/tools/dotc/config/SJSPlatform.scala
@@ -0,0 +1,13 @@
+package dotty.tools.dotc.config
+
+import dotty.tools.dotc.core._
+import Contexts._
+
+import dotty.tools.backend.sjs.JSDefinitions
+
+class SJSPlatform()(implicit ctx: Context) extends JavaPlatform {
+
+ /** Scala.js-specific definitions. */
+ val jsDefinitions: JSDefinitions = new JSDefinitions()
+
+}
diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala
index 65bc9ba23..aa264329c 100644
--- a/src/dotty/tools/dotc/config/ScalaSettings.scala
+++ b/src/dotty/tools/dotc/config/ScalaSettings.scala
@@ -29,6 +29,7 @@ class ScalaSettings extends Settings.SettingGroup {
val target = ChoiceSetting("-target", "target", "Target platform for object files. All JVM 1.5 targets are deprecated.",
List("jvm-1.5", "jvm-1.5-fjbg", "jvm-1.5-asm", "jvm-1.6", "jvm-1.7", "jvm-1.8", "msil"),
"jvm-1.8")
+ val scalajs = BooleanSetting("-scalajs", "Compile in Scala.js mode (requires scalajs-library.jar on the classpath).")
val unchecked = BooleanSetting("-unchecked", "Enable additional warnings where generated code depends on assumptions.")
val uniqid = BooleanSetting("-uniqid", "Uniquely tag all identifiers in debugging output.")
val usejavacp = BooleanSetting("-usejavacp", "Utilize the java.class.path in classpath resolution.")
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala
index f0537dffa..2fc958a49 100644
--- a/src/dotty/tools/dotc/core/Contexts.scala
+++ b/src/dotty/tools/dotc/core/Contexts.scala
@@ -26,7 +26,7 @@ import reporting._
import collection.mutable
import collection.immutable.BitSet
import printing._
-import config.{Settings, ScalaSettings, Platform, JavaPlatform}
+import config.{Settings, ScalaSettings, Platform, JavaPlatform, SJSPlatform}
import language.implicitConversions
import DenotTransformers.DenotTransformer
@@ -514,8 +514,21 @@ object Contexts {
/** The symbol loaders */
val loaders = new SymbolLoaders
+ /** The platform, initialized by `initPlatform()`. */
+ private var _platform: Platform = _
+
/** The platform */
- val platform: Platform = new JavaPlatform
+ def platform: Platform = {
+ if (_platform == null) {
+ throw new IllegalStateException(
+ "initialize() must be called before accessing platform")
+ }
+ _platform
+ }
+
+ protected def newPlatform(implicit ctx: Context): Platform =
+ if (settings.scalajs.value) new SJSPlatform
+ else new JavaPlatform
/** The loader that loads the members of _root_ */
def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = platform.rootLoader(root)
@@ -526,6 +539,14 @@ object Contexts {
/** The standard definitions */
val definitions = new Definitions
+ /** Initializes the `ContextBase` with a starting context.
+ * This initializes the `platform` and the `definitions`.
+ */
+ def initialize()(implicit ctx: Context): Unit = {
+ _platform = newPlatform
+ definitions.init
+ }
+
def squashed(p: Phase): Phase = {
allPhases.find(_.period.containsPhaseId(p.id)).getOrElse(NoPhase)
}
diff --git a/src/dotty/tools/dotc/transform/LinkScala2ImplClasses.scala b/src/dotty/tools/dotc/transform/LinkScala2ImplClasses.scala
index 60e8edc26..ca06938dc 100644
--- a/src/dotty/tools/dotc/transform/LinkScala2ImplClasses.scala
+++ b/src/dotty/tools/dotc/transform/LinkScala2ImplClasses.scala
@@ -48,11 +48,15 @@ class LinkScala2ImplClasses extends MiniPhaseTransform with IdentityDenotTransfo
}
}
- private def implMethod(meth: Symbol)(implicit ctx: Context): Symbol =
- meth.owner.implClass.info
- .decl(if (meth.isConstructor) nme.TRAIT_CONSTRUCTOR else meth.name)
+ private def implMethod(meth: Symbol)(implicit ctx: Context): Symbol = {
+ val implInfo = meth.owner.implClass.info
+ if (meth.isConstructor)
+ implInfo.decl(nme.TRAIT_CONSTRUCTOR).symbol
+ else
+ implInfo.decl(meth.name)
.suchThat(c => FullParameterization.memberSignature(c.info) == meth.signature)
.symbol
+ }
private val Scala2xTrait = allOf(Scala2x, Trait)
-} \ No newline at end of file
+}
diff --git a/src/dotty/tools/dotc/transform/Memoize.scala b/src/dotty/tools/dotc/transform/Memoize.scala
index fbf8ed763..b775496ae 100644
--- a/src/dotty/tools/dotc/transform/Memoize.scala
+++ b/src/dotty/tools/dotc/transform/Memoize.scala
@@ -91,6 +91,7 @@ import Decorators._
}
} else if (sym.isSetter) {
if (!sym.is(ParamAccessor)) { val Literal(Constant(())) = tree.rhs } // this is intended as an assertion
+ field.setFlag(Mutable) // necessary for vals mixed in from Scala2 traits
val initializer = Assign(ref(field), ref(tree.vparamss.head.head.symbol))
cpy.DefDef(tree)(rhs = transformFollowingDeep(initializer)(ctx.withOwner(sym), info))
}
diff --git a/src/dotty/tools/dotc/transform/Pickler.scala b/src/dotty/tools/dotc/transform/Pickler.scala
index 8040c86d4..c5b223d53 100644
--- a/src/dotty/tools/dotc/transform/Pickler.scala
+++ b/src/dotty/tools/dotc/transform/Pickler.scala
@@ -80,7 +80,7 @@ class Pickler extends Phase {
private def testUnpickler(units: List[CompilationUnit])(implicit ctx: Context): Unit = {
pickling.println(i"testing unpickler at run ${ctx.runId}")
- ctx.definitions.init
+ ctx.initialize()
val unpicklers =
for (unit <- units; (cls, pickler) <- unit.picklers) yield {
val unpickler = new DottyUnpickler(pickler.assembleParts())