From 877ed789ead40ae29811969e3b0f25feb0a68209 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Fri, 30 Aug 2024 19:30:44 +0300 Subject: [PATCH] adding new methods to GraphIRReflection --- .../src/main/scala/sigma/ast/methods.scala | 38 ++++++------------- .../sigma/compiler/ir/GraphIRReflection.scala | 16 ++++++++ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/data/shared/src/main/scala/sigma/ast/methods.scala b/data/shared/src/main/scala/sigma/ast/methods.scala index 84fc4955a5..0b69b4a2c0 100644 --- a/data/shared/src/main/scala/sigma/ast/methods.scala +++ b/data/shared/src/main/scala/sigma/ast/methods.scala @@ -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, "") @@ -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, "") @@ -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, "") @@ -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, "") @@ -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, "") @@ -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, @@ -1049,7 +1033,7 @@ object SCollectionMethods extends MethodsContainer with MethodByNameUnapply { ZipMethod ) - private val v6Methods = Seq( + private val v6Methods = v5Methods ++ Seq( ReverseMethod, DistinctMethod, StartsWithMethod, @@ -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 } } diff --git a/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala b/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala index 69736a0224..829a37f871 100644 --- a/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala +++ b/sc/shared/src/main/scala/sigma/compiler/ir/GraphIRReflection.scala @@ -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]]) } ) )