Skip to content

Commit

Permalink
Merge pull request #679 from ScorexFoundation/develop
Browse files Browse the repository at this point in the history
Release v3.3.0
  • Loading branch information
aslesarenko authored Aug 11, 2020
2 parents b54a173 + 6fc2491 commit f5420ca
Show file tree
Hide file tree
Showing 70 changed files with 12,338 additions and 1,581 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ version in ThisBuild := {
git.gitUncommittedChanges in ThisBuild := true

val bouncycastleBcprov = "org.bouncycastle" % "bcprov-jdk15on" % "1.64"
val scrypto = "org.scorexfoundation" %% "scrypto" % "2.1.7"
val scrypto = "org.scorexfoundation" %% "scrypto" % "2.1.9"
val scorexUtil = "org.scorexfoundation" %% "scorex-util" % "0.1.6"
val macroCompat = "org.typelevel" %% "macro-compat" % "1.1.1"
val paradise = "org.scalamacros" %% "paradise" % "2.1.0" cross CrossVersion.full
Expand All @@ -96,6 +96,7 @@ val testingDependencies = Seq(
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"org.scalactic" %% "scalactic" % "3.0.+" % "test",
"org.scalacheck" %% "scalacheck" % "1.14.+" % "test",
"com.lihaoyi" %% "pprint" % "0.5.4" % "test", // the last version with Scala 2.11 support
"com.storm-enroute" %% "scalameter" % "0.8.2" % Test,
"junit" % "junit" % "4.12" % "test",
"com.novocode" % "junit-interface" % "0.11" % "test"
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/scala/scalan/TypeDesc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import scala.reflect.ClassTag
import scala.annotation.implicitNotFound

/** Base type for all runtime type descriptors. */
@implicitNotFound(msg = "No Elem available for ${A}.")
@implicitNotFound(msg = "No RType available for ${A}.")
abstract class RType[A] {
/** Class tag suitable for construct instances of Array[A]. */
def classTag: ClassTag[A]
Expand Down
20 changes: 10 additions & 10 deletions common/src/main/scala/scalan/util/Extensions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ object Extensions {
* @since 2.0
*/
def toAbs: Byte = if (b < 0) (-b).toByte else b

/** Compares this numeric with that numeric for order. Returns a negative integer, zero, or a positive integer as the
* `this` is less than, equal to, or greater than `that`.
*/
def compare(that: Byte): Byte = if (b < that) -1.toByte else if (b == that) 0.toByte else 1.toByte
}

implicit class ShortOps(val x: Short) extends AnyVal {
Expand Down Expand Up @@ -82,6 +77,11 @@ object Extensions {
throw new ArithmeticException("Short overflow")
r.toShort
}

/** Absolute value of this numeric value.
* @since 2.0
*/
def toAbs: Short = if (x < 0) (-x).toShort else x
}

implicit class IntOps(val x: Int) extends AnyVal {
Expand All @@ -101,11 +101,6 @@ object Extensions {
* @since 2.0
*/
def toAbs: Int = if (x < 0) -x else x

/** Compares this numeric with that numeric for order. Returns a negative integer, zero, or a positive integer as the
* `this` is less than, equal to, or greater than `that`.
*/
def compare(that: Int): Int = if (x < that) -1 else if (x == that) 0 else 1
}

implicit class LongOps(val x: Long) extends AnyVal {
Expand All @@ -126,6 +121,11 @@ object Extensions {
throw new ArithmeticException("Int overflow")
x.toInt
}

/** Absolute value of this numeric value.
* @since 2.0
*/
def toAbs: Long = if (x < 0) -x else x
}

implicit class BigIntegerOps(val x: BigInteger) extends AnyVal {
Expand Down
67 changes: 59 additions & 8 deletions docs/LangSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,65 @@ class Box {
*/
def tokens: Coll[(Coll[Byte], Long)]

/** Extracts register by id and type.
* @param regId zero-based identifier of the register.
* @tparam T expected type of the register.
* @return Some(value) if the register is defined and has given type.
* None otherwise
* @since 2.0
*/
def getReg[T](regId: Int): Option[T]
/** Extracts register by id and type.
* ErgoScript is typed, so accessing a register is an operation which involves some
* expected type given in brackets. Thus `SELF.R4[Int]` expression should evaluate to a
* valid value of the `Option[Int]` type.
*
* For example `val x = SELF.R4[Int]` expects the
* register, if it is present, to have type `Int`. At runtime the corresponding type
* descriptor is passed as `implicit t: RType[T]` parameter of `getReg` method and
* checked against the actual value of the register.
*
* There are three cases:
* 1) If the register doesn't exist.
* Then `val x = SELF.R4[Int]` succeeds and returns the None value, which conforms to
* any value of type `Option[T]` for any T. (In the example above T is equal to
* `Int`). Calling `x.get` fails when x is equal to None, but `x.isDefined`
* succeeds and returns `false`.
* 2) If the register contains a value `v` of type `Int`.
* Then `val x = SELF.R4[Int]` succeeds and returns `Some(v)`, which is a valid value
* of type `Option[Int]`. In this case, calling `x.get` succeeds and returns the
* value `v` of type `Int`. Calling `x.isDefined` returns `true`.
* 3) If the register contains a value `v` of type T other then `Int`.
* Then `val x = SELF.R4[Int]` fails, because there is no way to return a valid value
* of type `Option[Int]`. The value of register is present, so returning it as None
* would break the typed semantics of registers collection.
*
* In some use cases one register may have values of different types. To access such
* register an additional register can be used as a tag.
*
* <pre class="stHighlight">
* val tagOpt = SELF.R5[Int]
* val res = if (tagOpt.isDefined) {
* val tag = tagOpt.get
* if (tag == 1) {
* val x = SELF.R4[Int].get
* // compute res using value x is of type Int
* } else if (tag == 2) {
* val x = SELF.R4[GroupElement].get
* // compute res using value x is of type GroupElement
* } else if (tag == 3) {
* val x = SELF.R4[ Array[Byte] ].get
* // compute res using value x of type Array[Byte]
* } else {
* // compute `res` when `tag` is not 1, 2 or 3
* }
* }
* else {
* // compute value of res when register is not present
* }
* </pre>
*
* @param i zero-based identifier of the register.
* @tparam T expected type of the register.
* @return Some(value) if the register is defined AND has the given type.
* None otherwise
* @throws special.sigma.InvalidType exception when the type of the register value is
* different from T.
* @since 2.0
*/
def getReg[T](i: Int): Option[T]

/** Extracts register as Coll[Byte], deserializes it to script and then executes this script in the current context.
* The original Coll[Byte] of the script is available as getReg[Coll[Byte]](id)
Expand Down
Binary file added docs/posters/fc-poster-2.pdf
Binary file not shown.
Loading

0 comments on commit f5420ca

Please sign in to comment.