summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-01-28 16:24:29 +0000
committerPaul Phillips <paulp@improving.org>2011-01-28 16:24:29 +0000
commitad3910e7fe0aedbab09ba6a85614f41b45e8b107 (patch)
tree5b3d8c4da7bf647ef7011c0758771f5a77d4e578 /src/compiler/scala/tools/nsc/interpreter/NamedParam.scala
parent834c065736573b11a1b51111edb032b2d3ca9b14 (diff)
downloadscala-ad3910e7fe0aedbab09ba6a85614f41b45e8b107.tar.gz
scala-ad3910e7fe0aedbab09ba6a85614f41b45e8b107.tar.bz2
scala-ad3910e7fe0aedbab09ba6a85614f41b45e8b107.zip
More repl housecleaning.
interpreter and the interpreter loop has become so fuzzy it can hardly be said to exist. In this commit I take a step or two toward clearer boundaries, and also fix some gratuitous name inconsistencies with the rest of trunk. A Global should be called "global" in the absence of a compelling reason otherwise. Also, now having had a couple years to explore every inch of the design space, I can announce that where possible to use them, distinguished objects like NoType and NoSymbol are far superior to swaddling things in Option. Applied this piece of canon to Completion and History. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/interpreter/NamedParam.scala')
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/NamedParam.scala31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala b/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala
new file mode 100644
index 0000000000..62255b2aaf
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/interpreter/NamedParam.scala
@@ -0,0 +1,31 @@
+/* NSC -- new Scala compiler
+ * Copyright 2005-2011 LAMP/EPFL
+ * @author Paul Phillips
+ */
+
+package scala.tools.nsc
+package interpreter
+
+object NamedParam {
+ def apply[T: Manifest](name: String, x: T): NamedParam[T] = new NamedParam[T](name, x)
+ def apply[T: Manifest](x: T): NamedParam[T] = apply(getParamName(), x)
+
+ implicit def fromValue[T: Manifest](x: T) = apply(x)
+ implicit def fromNameAndValue[T: Manifest](name: String, x: T) = apply(name, x)
+ implicit def fromTuple[T: Manifest](pair: (String, T)) = apply(pair._1, pair._2)
+
+ private val getParamName = {
+ var counter = 0
+ () => { counter += 1; "p" + counter }
+ }
+}
+
+class NamedParam[T: Manifest](val name: String, val value: T) {
+ val clazz = manifest[T].erasure.getName
+ val tparams = manifest[T].typeArguments match {
+ case Nil => ""
+ case xs => xs.mkString("[", ", ", "]")
+ }
+ val tpe = clazz + tparams
+ override def toString = name + ": " + tpe
+}