blob: 4eecddd9bb65d235575dc8313d23c1648e81e770 (
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
|
package dotty.runtime.vc
import scala.reflect.ClassTag
import scala.runtime.Statics
abstract class VCLongPrototype(val underlying: Long) extends VCPrototype {}
abstract class VCLongCasePrototype(underlying: Long) extends VCLongPrototype(underlying) with Product1[Long] {
final def _1: Long = underlying
override final def hashCode(): Int = {
underlying.hashCode()
}
override final def toString: String = {
s"$productPrefix($underlying)"
}
// subclasses are expected to implement equals, productPrefix, and canEqual
}
abstract class VCLongCompanion[T <: VCLongPrototype] extends ClassTag[T] {
def box(underlying: Long): T
final def unbox(boxed: T) = boxed.underlying
override def newArray(len: Int): Array[T] =
new VCLongArray(this, len).asInstanceOf[Array[T]]
final def _1$extension(underlying: Long) = underlying
final def hashCode$extension(underlying: Long) = underlying.hashCode()
final def toString$extension(underlying: Long) = s"${productPrefix$extension(underlying)}($underlying)"
def productPrefix$extension(underlying: Long): String
}
final class VCLongArray[T <: VCLongPrototype](val ct: VCLongCompanion[T], sz: Int) extends VCArrayPrototype[T] {
var arr = new Array[Long](sz) // mutable for clone
def apply(idx: Int) =
ct.box(arr(idx))
def update(idx: Int, elem: T) =
arr(idx) = ct.unbox(elem)
def length: Int = arr.length
override def clone(): VCLongArray[T] = {
val t = super.clone().asInstanceOf[VCLongArray[T]]
t.arr = this.arr.clone()
t
}
override def toString: String = {
"[" + ct.runtimeClass
}
// Todo: what was the reason for 255 classes in my original proposal? arr.toString!
// todo: need to discuss do we want to be compatible with ugly format of jvm here?
}
|