|
| 1 | +package scala.quoted |
| 2 | + |
| 3 | +import scala.quoted.Types.TaggedType |
| 4 | +import scala.reflect.ClassTag |
| 5 | +import scala.runtime.quoted.Unpickler.Pickled |
| 6 | + |
| 7 | +sealed abstract class Type[T] { |
| 8 | + type `$splice` = T |
| 9 | +} |
| 10 | + |
| 11 | +/** Some basic type tags, currently incomplete */ |
| 12 | +object Type { |
| 13 | + /** A term quote is desugared by the compiler into a call to this method */ |
| 14 | + def apply[T]: Type[T] = |
| 15 | + throw new Error("Internal error: this method call should have been replaced by the compiler") |
| 16 | + |
| 17 | + implicit def UnitTag: Type[Unit] = new TaggedType[Unit] |
| 18 | + implicit def BooleanTag: Type[Boolean] = new TaggedType[Boolean] |
| 19 | + implicit def ByteTag: Type[Byte] = new TaggedType[Byte] |
| 20 | + implicit def CharTag: Type[Char] = new TaggedType[Char] |
| 21 | + implicit def ShortTag: Type[Short] = new TaggedType[Short] |
| 22 | + implicit def IntTag: Type[Int] = new TaggedType[Int] |
| 23 | + implicit def LongTag: Type[Long] = new TaggedType[Long] |
| 24 | + implicit def FloatTag: Type[Float] = new TaggedType[Float] |
| 25 | + implicit def DoubleTag: Type[Double] = new TaggedType[Double] |
| 26 | +} |
| 27 | + |
| 28 | +/** All implementations of Type[T]. |
| 29 | + * These should never be used directly. |
| 30 | + */ |
| 31 | +object Types { |
| 32 | + /** A Type backed by a pickled TASTY tree */ |
| 33 | + final class TastyType[T](val tasty: Pickled, val args: Seq[Any]) extends Type[T] { |
| 34 | + override def toString(): String = s"Type(<pickled tasty>)" |
| 35 | + } |
| 36 | + |
| 37 | + /** An Type backed by a value */ |
| 38 | + final class TaggedType[T](implicit val ct: ClassTag[T]) extends Type[T] { |
| 39 | + override def toString: String = s"Type($ct)" |
| 40 | + } |
| 41 | + |
| 42 | + /** An Type backed by a tree */ |
| 43 | + final class TreeType[Tree](val typeTree: Tree) extends quoted.Type[Any] { |
| 44 | + override def toString: String = s"Type(<tasty tree>)" |
| 45 | + } |
| 46 | +} |
0 commit comments