/
OzmaGlobal.scala
135 lines (116 loc) · 5 KB
/
OzmaGlobal.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package scala.tools.nsc
package ozma
import util.returning
import transform.{ ExplicitOuter, SpecializeTypes }
import backend.MozartPlatform
import backend.mozart._
import backend.ozcode._
import backend.ozcode.opt._
trait OzmaGlobal extends Global with OzmaTrees {
/** Platform */
override lazy val platform: ThisPlatform =
new { val global: OzmaGlobal.this.type = OzmaGlobal.this } with MozartPlatform
/** OzCode generator */
object ozcodes extends {
val global: OzmaGlobal.this.type = OzmaGlobal.this
} with OzCodes
// OZMA Compiler phases ------------------------------------------------------
// phaseName = "singleass"
object singleAssignVals extends {
val global: OzmaGlobal.this.type = OzmaGlobal.this
val runsAfter = List[String]("parser")
val runsRightAfter = None
override val runsBefore = List[String]("namer")
} with SingleAssignVals
// phaseName = "looprecover"
object whileLoopRecovering extends {
val global: OzmaGlobal.this.type = OzmaGlobal.this
val runsAfter = List[String]("parser")
val runsRightAfter = None
override val runsBefore = List[String]("namer")
} with WhileLoopRecovering
// phaseName = "casetailcalls"
object caseClassTailCalls extends {
val global: OzmaGlobal.this.type = OzmaGlobal.this
val runsAfter = List[String]("parser")
val runsRightAfter = None
override val runsBefore = List[String]("namer")
} with CaseClassTailCalls
// phaseName = "explicitouter"
object ozmaExplicitOuter extends {
val global: OzmaGlobal.this.type = OzmaGlobal.this
val runsAfter = List[String]("uncurry") // "tailcalls" in Global
val runsRightAfter = None
} with ExplicitOuter
// phaseName = "specialize"
object ozmaSpecializeTypes extends {
val global: OzmaGlobal.this.type = OzmaGlobal.this
val runsAfter = List[String]("")
val runsRightAfter = Some("uncurry") // "tailcalls" in Global
} with SpecializeTypes
// phaseName = "lambdalift"
object ozmaLambdaLift extends {
val global: OzmaGlobal.this.type = OzmaGlobal.this
val runsAfter = List[String]("lazyvals")
val runsRightAfter = None
} with OzmaLambdaLift
// phaseName = "ozcode"
object ozcode extends {
val global: OzmaGlobal.this.type = OzmaGlobal.this
val runsAfter = List[String]("mixin")
val runsRightAfter = None
} with GenOzCode
// phaseName = "tailcalls"
object tailcalls extends {
val global: OzmaGlobal.this.type = OzmaGlobal.this
val runsAfter = List[String]("ozcode")
val runsRightAfter = None
} with TailCalls
// phaseName = "terminal"
object ozmaTerminal extends {
val global: OzmaGlobal.this.type = OzmaGlobal.this
val phaseName = "terminal"
val runsAfter = List[String]("mozart")
val runsRightAfter = None
} with SubComponent {
private var cache: Option[GlobalPhase] = None
def reset(): Unit = cache = None
def newPhase(prev: Phase): GlobalPhase =
cache getOrElse returning(new TerminalPhase(prev))(x => cache = Some(x))
class TerminalPhase(prev: Phase) extends GlobalPhase(prev) {
def name = "terminal"
def apply(unit: CompilationUnit) {}
}
}
/** Add the internal compiler phases to the phases set.
* This implementation creates a description map at the same time.
*/
override protected def computeInternalPhases() {
// Note: this fits -Xshow-phases into 80 column width, which it is
// desirable to preserve.
val phs = List(
syntaxAnalyzer -> "parse source into ASTs, perform simple desugaring",
singleAssignVals -> "take care of single assignment values",
whileLoopRecovering -> "recover while loops",
caseClassTailCalls -> "annotate case class constructors with @tailcall",
analyzer.namerFactory -> "resolve names, attach symbols to named trees",
analyzer.packageObjects -> "load package objects",
analyzer.typerFactory -> "the meat and potatoes: type the trees",
superAccessors -> "add super accessors in traits and nested classes",
pickler -> "serialize symbol tables",
refchecks -> "reference/override checking, translate nested objects",
uncurry -> "uncurry, translate function values to anonymous classes",
ozmaSpecializeTypes -> "@specialized-driven class and method specialization",
ozmaExplicitOuter -> "this refs to outer pointers, translate patterns",
erasure -> "erase types, add interfaces for traits",
lazyVals -> "allocate bitmaps, translate lazy vals into lazified defs",
ozmaLambdaLift -> "move nested functions to top level",
constructors -> "move field definitions into constructors",
mixer -> "mixin composition",
ozcode -> "generate Oz code from AST",
tailcalls -> "rewrite tail calls",
ozmaTerminal -> "The last phase in the compiler chain"
)
phs foreach (addToPhasesSet _).tupled
}
}