-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
towards-data-module: some Extensions moved to sigma.eval
- Loading branch information
1 parent
2a77625
commit cd088ca
Showing
28 changed files
with
110 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
interpreter/shared/src/main/scala/sigma/data/BigIntegerOps.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
interpreter/shared/src/main/scala/sigma/eval/Extensions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package sigma.eval | ||
|
||
import sigma.ast.defs.SigmaPropValue | ||
import sigma.data.{CAnyValue, CSigmaDslBuilder, Nullable, RType, SigmaBoolean} | ||
import sigma.{BigInt, Coll, Evaluation} | ||
import sigma.ast.{Constant, ConstantNode, SBoolean, SCollection, SCollectionType, SType, SigmaPropConstant, SigmaPropIsProven, TransformingSigmaBuilder, Value} | ||
import sigmastate.Platform | ||
import sigmastate.utils.Helpers | ||
|
||
import java.math.BigInteger | ||
|
||
object Extensions { | ||
implicit class ByteExt(val b: Byte) extends AnyVal { | ||
@inline def toBigInt: BigInt = CSigmaDslBuilder.BigInt(BigInteger.valueOf(b.toLong)) | ||
} | ||
|
||
implicit class ShortExt(val b: Short) extends AnyVal { | ||
@inline def toBigInt: BigInt = CSigmaDslBuilder.BigInt(BigInteger.valueOf(b.toLong)) | ||
} | ||
|
||
implicit class IntExt(val x: Int) extends AnyVal { | ||
/** Convert this value to BigInt. */ | ||
@inline def toBigInt: BigInt = CSigmaDslBuilder.BigInt(BigInteger.valueOf(x.toLong)) | ||
} | ||
|
||
implicit class LongExt(val x: Long) extends AnyVal { | ||
/** Convert this value to BigInt. */ | ||
@inline def toBigInt: BigInt = CSigmaDslBuilder.BigInt(BigInteger.valueOf(x)) | ||
} | ||
|
||
def toAnyValue[A: RType](x: A) = new CAnyValue(x, RType[A].asInstanceOf[RType[Any]]) | ||
|
||
implicit class EvalCollOps[T](val coll: Coll[T]) extends AnyVal { | ||
/** Helper type synonym. */ | ||
type ElemTpe = SType {type WrappedType = T} | ||
|
||
/** Wraps the collection into ConstantNode using collection's element type. */ | ||
def toConstant: Constant[SCollection[ElemTpe]] = { | ||
val elemTpe = Evaluation.rtypeToSType(coll.tItem).asInstanceOf[ElemTpe] | ||
ConstantNode[SCollection[ElemTpe]](coll, SCollectionType(elemTpe)) | ||
} | ||
|
||
/** Transforms this collection into array of constants. | ||
* | ||
* This method have exactly the same semantics on JS and JVM IF `coll.tItem` | ||
* precisely describes the type of elements in `call`. (Which is the case for all | ||
* collections created by ErgoTree interpreter). | ||
* | ||
* However, if it is not the case, then JVM and JS will have different semantics for Byte and Short. | ||
* | ||
* The JVM version preserves v5.0 consensus protocol semantics. | ||
* The JS version is a reasonable approximation of the JVM version. | ||
*/ | ||
def toArrayOfConstants: Array[Constant[SType]] = { | ||
val constants = coll.toArray.map { v => | ||
// see ScalaDoc for ensureTypeCarringValue | ||
val valToLift = Helpers.ensureTypeCarringValue(v, coll.tItem.asInstanceOf[RType[Any]]) | ||
// call platform-specific method to transform the value to a Constant | ||
Platform.liftToConstant(valToLift, TransformingSigmaBuilder) match { | ||
case Nullable(c) => c | ||
case _ => sys.error(s"Cannot liftToConstant($valToLift)") | ||
} | ||
} | ||
constants | ||
} | ||
} | ||
|
||
implicit class SigmaBooleanOps(val sb: SigmaBoolean) extends AnyVal { | ||
def toSigmaPropValue: SigmaPropValue = SigmaPropConstant(sb) | ||
|
||
def isProven: Value[SBoolean.type] = SigmaPropIsProven(SigmaPropConstant(sb)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
interpreter/shared/src/test/scala/sigma/serialization/PDHTSerializerSpecification.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
interpreter/shared/src/test/scala/sigma/serialization/ProveDlogSerializerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.