594 def update[A](r: Ref[A], x: A): Unit = |
594 def update[A](r: Ref[A], x: A): Unit = |
595 { r.value = x } |
595 { r.value = x } |
596 } |
596 } |
597 |
597 |
598 object Array { |
598 object Array { |
599 import collection.mutable.ArraySeq |
599 class T[A](n: Int) |
600 def alloc[A](n: BigInt)(x: A): ArraySeq[A] = |
600 { |
601 ArraySeq.fill(n.toInt)(x) |
601 val array: Array[AnyRef] = new Array[AnyRef](n) |
602 def make[A](n: BigInt)(f: BigInt => A): ArraySeq[A] = |
602 def apply(i: Int): A = array(i).asInstanceOf[A] |
603 ArraySeq.tabulate(n.toInt)((k: Int) => f(BigInt(k))) |
603 def update(i: Int, x: A): Unit = array(i) = x.asInstanceOf[AnyRef] |
604 def len[A](a: ArraySeq[A]): BigInt = |
604 def length: Int = array.length |
605 BigInt(a.length) |
605 def toList: List[A] = array.toList.asInstanceOf[List[A]] |
606 def nth[A](a: ArraySeq[A], n: BigInt): A = |
606 override def toString: String = array.mkString("Array.T(", ",", ")") |
607 a(n.toInt) |
607 } |
608 def upd[A](a: ArraySeq[A], n: BigInt, x: A): Unit = |
608 def make[A](n: BigInt)(f: BigInt => A): T[A] = |
609 a.update(n.toInt, x) |
609 { |
610 def freeze[A](a: ArraySeq[A]): List[A] = |
610 val m = n.toInt |
611 a.toList |
611 val a = new T[A](m) |
|
612 for (i <- 0 until m) a(i) = f(i) |
|
613 a |
|
614 } |
|
615 def alloc[A](n: BigInt)(x: A): T[A] = make(n)(_ => x) |
|
616 def len[A](a: T[A]): BigInt = BigInt(a.length) |
|
617 def nth[A](a: T[A], n: BigInt): A = a(n.toInt) |
|
618 def upd[A](a: T[A], n: BigInt, x: A): Unit = a.update(n.toInt, x) |
|
619 def freeze[A](a: T[A]): List[A] = a.toList |
612 } |
620 } |
|
621 |
613 \<close> |
622 \<close> |
614 |
623 |
615 code_reserved Scala Heap Ref Array |
624 code_reserved Scala Heap Ref Array |
616 |
625 |
617 code_printing type_constructor Heap \<rightharpoonup> (Scala) "(Unit/ =>/ _)" |
626 code_printing type_constructor Heap \<rightharpoonup> (Scala) "(Unit/ =>/ _)" |