Skip to content

Commit

Permalink
adding new methods to GraphIRReflection
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Aug 30, 2024
1 parent acb76c9 commit 877ed78
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
38 changes: 11 additions & 27 deletions data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,7 @@ object SCollectionMethods extends MethodsContainer with MethodByNameUnapply {
baseCost = JitCost(10), perChunkCost = JitCost(1), chunkSize = 10)

val ZipMethod = SMethod(this, "zip",
SFunc(Array(ThisType, tOVColl), SCollection(STuple(tIV, tOV)), Array[STypeParam](tIV, tOV)),
29, Zip_CostKind)
SFunc(Array(ThisType, tOVColl), SCollection(STuple(tIV, tOV)), Array[STypeParam](tIV, tOV)), 29, Zip_CostKind)
.withIRInfo(MethodCallIrBuilder)
.withInfo(MethodCall, "")

Expand All @@ -939,11 +938,10 @@ object SCollectionMethods extends MethodsContainer with MethodByNameUnapply {
}
}

// ======== 6.0 methods below ===========

// 6.0 methods below
val ReverseMethod = SMethod(this, "reverse",
SFunc(Array(ThisType), ThisType, paramIVSeq),
30, Zip_CostKind) // todo: costing
SFunc(Array(ThisType), ThisType, paramIVSeq), 30, Zip_CostKind) // todo: costing
.withIRInfo(MethodCallIrBuilder)
.withInfo(MethodCall, "")

Expand All @@ -960,8 +958,7 @@ object SCollectionMethods extends MethodsContainer with MethodByNameUnapply {
}

val DistinctMethod = SMethod(this, "distinct",
SFunc(Array(ThisType), ThisType, paramIVSeq),
31, Zip_CostKind) // todo: costing
SFunc(Array(ThisType), ThisType, paramIVSeq), 31, Zip_CostKind) // todo: costing
.withIRInfo(MethodCallIrBuilder)
.withInfo(MethodCall, "")

Expand All @@ -978,8 +975,7 @@ object SCollectionMethods extends MethodsContainer with MethodByNameUnapply {
}

val StartsWithMethod = SMethod(this, "startsWith",
SFunc(Array(ThisType, ThisType), SBoolean, paramIVSeq),
32, Zip_CostKind) // todo: costing
SFunc(Array(ThisType, ThisType), SBoolean, paramIVSeq), 32, Zip_CostKind) // todo: costing
.withIRInfo(MethodCallIrBuilder)
.withInfo(MethodCall, "")

Expand All @@ -996,8 +992,7 @@ object SCollectionMethods extends MethodsContainer with MethodByNameUnapply {
}

val EndsWithMethod = SMethod(this, "endsWith",
SFunc(Array(ThisType, ThisType), SBoolean, paramIVSeq),
33, Zip_CostKind) // todo: costing
SFunc(Array(ThisType, ThisType), SBoolean, paramIVSeq), 33, Zip_CostKind) // todo: costing
.withIRInfo(MethodCallIrBuilder)
.withInfo(MethodCall, "")

Expand All @@ -1018,18 +1013,7 @@ object SCollectionMethods extends MethodsContainer with MethodByNameUnapply {
.withIRInfo(MethodCallIrBuilder)
.withInfo(MethodCall, "")

/** Implements evaluation of Coll.zip method call ErgoTree node.
* Called via reflection based on naming convention.
* @see SMethod.evalMethod
*/
def get_eval[A](mc: MethodCall, xs: Coll[A], index: Int)
(implicit E: ErgoTreeEvaluator): Option[A] = {
E.addCost(ByIndex.costKind, mc.method.opDesc) //todo: costing
??? // todo: this get is not actually executed, why?
xs.get(index)
}

private val v5Methods = Seq(
private val v5Methods = super.getMethods() ++ Seq(
SizeMethod,
GetOrElseMethod,
MapMethod,
Expand All @@ -1049,7 +1033,7 @@ object SCollectionMethods extends MethodsContainer with MethodByNameUnapply {
ZipMethod
)

private val v6Methods = Seq(
private val v6Methods = v5Methods ++ Seq(
ReverseMethod,
DistinctMethod,
StartsWithMethod,
Expand All @@ -1061,10 +1045,10 @@ object SCollectionMethods extends MethodsContainer with MethodByNameUnapply {
* Typical override: `super.getMethods() ++ Seq(m1, m2, m3)`
*/
override protected def getMethods(): Seq[SMethod] = {
if(VersionContext.current.isV6SoftForkActivated) {
super.getMethods() ++ v5Methods ++ v6Methods
if (VersionContext.current.isV6SoftForkActivated) {
v6Methods
} else {
super.getMethods() ++ v5Methods
v5Methods
}
}

Expand Down
16 changes: 16 additions & 0 deletions sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ object GraphIRReflection {
},
mkMethod(clazz, "exists", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.Coll[Any]].exists(args(0).asInstanceOf[ctx.Ref[Any => Boolean]])
},
// V6 methods
mkMethod(clazz, "reverse", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Coll[Any]].reverse
},
mkMethod(clazz, "distinct", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Coll[Any]].distinct
},
mkMethod(clazz, "startsWith", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.Coll[Any]].startsWith(args(0).asInstanceOf[ctx.Ref[ctx.Coll[Any]]])
},
mkMethod(clazz, "endsWith", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.Coll[Any]].endsWith(args(0).asInstanceOf[ctx.Ref[ctx.Coll[Any]]])
},
mkMethod(clazz, "get", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.Coll[_]].apply(args(0).asInstanceOf[ctx.Ref[Int]])
}
)
)
Expand Down

0 comments on commit 877ed78

Please sign in to comment.