blob: 237159795a534582d4a13fd6ab4e73f2c4c15cad (
plain) (
blame)
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
|
// $Id$
package scala.tools.selectivecps
import scala.tools.nsc
import scala.tools.nsc.typechecker._
import nsc.Global
import nsc.Phase
import nsc.plugins.Plugin
import nsc.plugins.PluginComponent
class SelectiveCPSPlugin(val global: Global) extends Plugin {
import global._
val name = "continuations"
val description = "applies selective cps conversion"
val anfPhase = new SelectiveANFTransform() {
val global = SelectiveCPSPlugin.this.global
val runsAfter = List("pickler")
}
val cpsPhase = new SelectiveCPSTransform() {
val global = SelectiveCPSPlugin.this.global
val runsAfter = List("selectiveanf")
override val runsBefore = List("uncurry")
}
val components = List[PluginComponent](anfPhase, cpsPhase)
val checker = new CPSAnnotationChecker {
val global: SelectiveCPSPlugin.this.global.type = SelectiveCPSPlugin.this.global
}
global.addAnnotationChecker(checker.checker)
global.analyzer.addAnalyzerPlugin(checker.plugin)
global.log("instantiated cps plugin: " + this)
def setEnabled(flag: Boolean) = {
checker.cpsEnabled = flag
anfPhase.cpsEnabled = flag
cpsPhase.cpsEnabled = flag
}
// TODO: require -enabled command-line flag
override def processOptions(options: List[String], error: String => Unit) = {
var enabled = false
for (option <- options) {
if (option == "enable") {
enabled = true
} else {
error("Option not understood: "+option)
}
}
setEnabled(enabled)
}
override val optionsHelp: Option[String] =
Some(" -P:continuations:enable Enable continuations")
}
|