@@ -8,15 +8,18 @@ import scala.lms.internal.GenericNestedCodegen
8
8
import collection .mutable .ArrayBuffer
9
9
import scala .reflect .SourceContext
10
10
11
- trait ArrayBufferOps extends Base {
11
+ trait ArrayBufferOps extends Base with StringOps with ArrayOps {
12
12
13
13
object ArrayBuffer {
14
- def apply [A : Manifest ](xs : Rep [A ]* ) = arraybuffer_new(xs)
14
+ def apply [A : Typ ](xs : Rep [A ]* ) = arraybuffer_new(xs)
15
15
}
16
16
17
- implicit def repToArrayBufferOps [A : Manifest ](l : Rep [ArrayBuffer [A ]]) = new ArrayBufferOpsCls (l)
17
+ implicit def arrayBufferTyp [T : Typ ]: Typ [ArrayBuffer [T ]]
18
+ implicit def seqTyp [T : Typ ]: Typ [Seq [T ]] // TODO: remove?
19
+
20
+ implicit def repToArrayBufferOps [A : Typ ](l : Rep [ArrayBuffer [A ]]) = new ArrayBufferOpsCls (l)
18
21
19
- class ArrayBufferOpsCls [A : Manifest ](l : Rep [ArrayBuffer [A ]]) {
22
+ class ArrayBufferOpsCls [A : Typ ](l : Rep [ArrayBuffer [A ]]) {
20
23
def += (e : Rep [A ])(implicit pos : SourceContext ) = arraybuffer_append(l,e)
21
24
def mkString (sep : Rep [String ] = unit(" " ))(implicit pos : SourceContext ) = arraybuffer_mkstring(l,sep)
22
25
def append (l : Rep [ArrayBuffer [A ]], e : Rep [A ])(implicit pos : SourceContext ) = arraybuffer_append(l,e)
@@ -25,53 +28,58 @@ trait ArrayBufferOps extends Base {
25
28
def toSeq (implicit pos : SourceContext ) = arraybuffer_toseq(l)
26
29
}
27
30
28
- def infix_+= [A : Manifest ](l : Rep [ArrayBuffer [A ]], e : Rep [A ])(implicit pos : SourceContext ) = arraybuffer_append(l, e)
31
+ def infix_+= [A : Typ ](l : Rep [ArrayBuffer [A ]], e : Rep [A ])(implicit pos : SourceContext ) = arraybuffer_append(l, e)
29
32
30
33
/* when mixed in with OptiML, one of these infix operations causes an NPE in the scala-virtualized compiler */ // TR: still the case?
31
34
/*
32
- def infix_mkString[A:Manifest ](l: Rep[ArrayBuffer[A]], sep: Rep[String] = unit(""))(implicit pos: SourceContext) = arraybuffer_mkstring(l, sep)
33
- def infix_+=[A:Manifest ](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l, e)
34
- def infix_append[A:Manifest ](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l, e)
35
- def infix_toArray[A:Manifest ](l: Rep[ArrayBuffer[A]])(implicit pos: SourceContext) = arraybuffer_toarray(l)
36
- def infix_toSeq[A:Manifest ](l: Rep[ArrayBuffer[A]])(implicit pos: SourceContext) = arraybuffer_toseq(l)
35
+ def infix_mkString[A:Typ ](l: Rep[ArrayBuffer[A]], sep: Rep[String] = unit(""))(implicit pos: SourceContext) = arraybuffer_mkstring(l, sep)
36
+ def infix_+=[A:Typ ](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l, e)
37
+ def infix_append[A:Typ ](l: Rep[ArrayBuffer[A]], e: Rep[A])(implicit pos: SourceContext) = arraybuffer_append(l, e)
38
+ def infix_toArray[A:Typ ](l: Rep[ArrayBuffer[A]])(implicit pos: SourceContext) = arraybuffer_toarray(l)
39
+ def infix_toSeq[A:Typ ](l: Rep[ArrayBuffer[A]])(implicit pos: SourceContext) = arraybuffer_toseq(l)
37
40
*/
38
41
39
- def arraybuffer_mkstring [A : Manifest ](l : Rep [ArrayBuffer [A ]], sep : Rep [String ])(implicit pos : SourceContext ): Rep [String ]
40
- def arraybuffer_append [A : Manifest ](l : Rep [ArrayBuffer [A ]], e : Rep [A ])(implicit pos : SourceContext ): Rep [Unit ]
41
- def arraybuffer_new [A : Manifest ](xs : Seq [Rep [A ]])(implicit pos : SourceContext ): Rep [ArrayBuffer [A ]]
42
- def arraybuffer_clear [A : Manifest ](l : Rep [ArrayBuffer [A ]]): Rep [Unit ]
43
- def arraybuffer_toarray [A : Manifest ](x : Rep [ArrayBuffer [A ]])(implicit pos : SourceContext ): Rep [Array [A ]]
44
- def arraybuffer_toseq [A : Manifest ](x : Rep [ArrayBuffer [A ]])(implicit pos : SourceContext ): Rep [Seq [A ]]
42
+ def arraybuffer_mkstring [A : Typ ](l : Rep [ArrayBuffer [A ]], sep : Rep [String ])(implicit pos : SourceContext ): Rep [String ]
43
+ def arraybuffer_append [A : Typ ](l : Rep [ArrayBuffer [A ]], e : Rep [A ])(implicit pos : SourceContext ): Rep [Unit ]
44
+ def arraybuffer_new [A : Typ ](xs : Seq [Rep [A ]])(implicit pos : SourceContext ): Rep [ArrayBuffer [A ]]
45
+ def arraybuffer_clear [A : Typ ](l : Rep [ArrayBuffer [A ]]): Rep [Unit ]
46
+ def arraybuffer_toarray [A : Typ ](x : Rep [ArrayBuffer [A ]])(implicit pos : SourceContext ): Rep [Array [A ]]
47
+ def arraybuffer_toseq [A : Typ ](x : Rep [ArrayBuffer [A ]])(implicit pos : SourceContext ): Rep [Seq [A ]]
45
48
}
46
49
47
50
trait ArrayBufferOpsExp extends ArrayBufferOps with EffectExp {
48
- case class ArrayBufferNew [A : Manifest ](xs : Seq [Exp [A ]]) extends Def [ArrayBuffer [A ]] {
51
+ implicit def arrayBufferTyp [T : Typ ]: Typ [ArrayBuffer [T ]] = {
52
+ implicit val ManifestTyp (m) = typ[T ]
53
+ manifestTyp
54
+ }
55
+
56
+ case class ArrayBufferNew [A : Typ ](xs : Seq [Exp [A ]]) extends Def [ArrayBuffer [A ]] {
49
57
val mA = manifest[A ]
50
58
}
51
- case class ArrayBufferMkString [A : Manifest ](l : Exp [ArrayBuffer [A ]], sep : Exp [String ]) extends Def [String ]
52
- case class ArrayBufferAppend [A : Manifest ](l : Exp [ArrayBuffer [A ]], e : Exp [A ]) extends Def [Unit ]
53
- case class ArrayBufferClear [A : Manifest ](l : Exp [ArrayBuffer [A ]]) extends Def [Unit ]
54
- case class ArrayBufferToArray [A : Manifest ](x : Exp [ArrayBuffer [A ]]) extends Def [Array [A ]]
55
- case class ArrayBufferToSeq [A : Manifest ](x : Exp [ArrayBuffer [A ]]) extends Def [Seq [A ]]
56
-
57
- def arraybuffer_new [A : Manifest ](xs : Seq [Exp [A ]])(implicit pos : SourceContext ) = reflectMutable(ArrayBufferNew (xs))
58
- def arraybuffer_mkstring [A : Manifest ](l : Exp [ArrayBuffer [A ]], sep : Exp [String ])(implicit pos : SourceContext ) = ArrayBufferMkString (l, sep)
59
- def arraybuffer_append [A : Manifest ](l : Exp [ArrayBuffer [A ]], e : Exp [A ])(implicit pos : SourceContext ) = reflectWrite(l)(ArrayBufferAppend (l, e))
60
- def arraybuffer_clear [A : Manifest ](l : Exp [ArrayBuffer [A ]]) = reflectWrite(l)(ArrayBufferClear (l))
61
- def arraybuffer_toarray [A : Manifest ](x : Exp [ArrayBuffer [A ]])(implicit pos : SourceContext ) = ArrayBufferToArray (x)
62
- def arraybuffer_toseq [A : Manifest ](x : Exp [ArrayBuffer [A ]])(implicit pos : SourceContext ) = ArrayBufferToSeq (x)
59
+ case class ArrayBufferMkString [A : Typ ](l : Exp [ArrayBuffer [A ]], sep : Exp [String ]) extends Def [String ]
60
+ case class ArrayBufferAppend [A : Typ ](l : Exp [ArrayBuffer [A ]], e : Exp [A ]) extends Def [Unit ]
61
+ case class ArrayBufferClear [A : Typ ](l : Exp [ArrayBuffer [A ]]) extends Def [Unit ]
62
+ case class ArrayBufferToArray [A : Typ ](x : Exp [ArrayBuffer [A ]]) extends Def [Array [A ]]
63
+ case class ArrayBufferToSeq [A : Typ ](x : Exp [ArrayBuffer [A ]]) extends Def [Seq [A ]]
64
+
65
+ def arraybuffer_new [A : Typ ](xs : Seq [Exp [A ]])(implicit pos : SourceContext ) = reflectMutable(ArrayBufferNew (xs))
66
+ def arraybuffer_mkstring [A : Typ ](l : Exp [ArrayBuffer [A ]], sep : Exp [String ])(implicit pos : SourceContext ) = ArrayBufferMkString (l, sep)
67
+ def arraybuffer_append [A : Typ ](l : Exp [ArrayBuffer [A ]], e : Exp [A ])(implicit pos : SourceContext ) = reflectWrite(l)(ArrayBufferAppend (l, e))
68
+ def arraybuffer_clear [A : Typ ](l : Exp [ArrayBuffer [A ]]) = reflectWrite(l)(ArrayBufferClear (l))
69
+ def arraybuffer_toarray [A : Typ ](x : Exp [ArrayBuffer [A ]])(implicit pos : SourceContext ) = ArrayBufferToArray (x)
70
+ def arraybuffer_toseq [A : Typ ](x : Exp [ArrayBuffer [A ]])(implicit pos : SourceContext ) = ArrayBufferToSeq (x)
63
71
64
72
// ////////////
65
73
// mirroring
66
74
67
- override def mirrorDef [A : Manifest ](e : Def [A ], f : Transformer )(implicit pos : SourceContext ): Def [A ] = (e match {
68
- case ArrayBufferMkString (l,r) => ArrayBufferMkString (f(l),f(r))
69
- case ArrayBufferAppend (l,r) => ArrayBufferAppend (f(l),f(r))
75
+ override def mirrorDef [A : Typ ](e : Def [A ], f : Transformer )(implicit pos : SourceContext ): Def [A ] = (e match {
76
+ case ArrayBufferMkString (l,r) => ArrayBufferMkString (f(l),f(r))(mtype(manifest[ A ]))
77
+ case ArrayBufferAppend (l,r) => ArrayBufferAppend (f(l),f(r))(mtype(manifest[ A ]))
70
78
case _ => super .mirrorDef(e,f)
71
79
}).asInstanceOf [Def [A ]] // why??
72
80
73
81
/*
74
- override def mirror[A:Manifest ](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match {
82
+ override def mirror[A:Typ ](e: Def[A], f: Transformer)(implicit pos: SourceContext): Exp[A] = (e match {
75
83
case Reflect(ArrayBufferMkString(l,r), u, es) => reflectMirrored(Reflect(ArrayBufferMkString(f(l),f(r)), mapOver(f,u), f(es)))(mtype(manifest[A]))
76
84
case Reflect(ArrayBufferAppend(l,r), u, es) => reflectMirrored(Reflect(ArrayBufferAppend(f(l),f(r)), mapOver(f,u), f(es)))(mtype(manifest[A]))
77
85
case _ => super.mirror(e,f)
0 commit comments