alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (SelectiveCPSPlugin.scala)

This example Scala source code file (SelectiveCPSPlugin.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

boolean, cpsannotationchecker, enable, enable, global, list, list, option, option, p:continuations:enable, plugin, plugin, selectiveanftransform, string

The Scala SelectiveCPSPlugin.scala source code

// $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")
  }
  
  
  val components = List[PluginComponent](anfPhase, cpsPhase)

  val checker = new CPSAnnotationChecker {
    val global: SelectiveCPSPlugin.this.global.type = SelectiveCPSPlugin.this.global
  }
  global.addAnnotationChecker(checker.checker)

  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")
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala SelectiveCPSPlugin.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.