Skip to content

Commit

Permalink
Merge pull request #857 from darkdrag00nv2/eip5_template_ds_poc
Browse files Browse the repository at this point in the history
Implement ContractTemplate data structures according to EIP5
  • Loading branch information
aslesarenko authored Apr 11, 2023
2 parents 78dd1e7 + 7450df6 commit 18d9e4c
Show file tree
Hide file tree
Showing 11 changed files with 907 additions and 21 deletions.
24 changes: 9 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,15 @@ dynverSeparator in ThisBuild := "-"

val bouncycastleBcprov = "org.bouncycastle" % "bcprov-jdk15on" % "1.66"

val scrypto = "org.scorexfoundation" %% "scrypto" % "2.2.1-37-59c4fbd9-SNAPSHOT"
def scryptoDependency(platform: String) = {
val scrypto = "org.scorexfoundation" %% "scrypto" % "2.3.0"
def scryptoDependency = {
libraryDependencies +=
"org.scorexfoundation" %%% "scrypto" % (
if (platform == "js") "0.0.0-1-59c4fbd9-SNAPSHOT"
else "2.2.1-37-59c4fbd9-SNAPSHOT" // for JVM
)
"org.scorexfoundation" %%% "scrypto" % "2.3.0"
}
//val scorexUtil = "org.scorexfoundation" %% "scorex-util" % "0.1.8"
//val debox = "org.scorexfoundation" %% "debox" % "0.9.0"
val scorexUtil = "org.scorexfoundation" %% "scorex-util" % "0.1.8-20-565873cd-SNAPSHOT"
val scorexUtil = "org.scorexfoundation" %% "scorex-util" % "0.2.0"
val scorexUtilDependency =
libraryDependencies += "org.scorexfoundation" %%% "scorex-util" % "0.1.8-20-565873cd-SNAPSHOT"

val debox = "org.scorexfoundation" %% "debox" % "0.9.0-9-f853cdce-SNAPSHOT"
libraryDependencies += "org.scorexfoundation" %%% "scorex-util" % "0.2.0"
val debox = "org.scorexfoundation" %% "debox" % "0.10.0"
val spireMacros = "org.typelevel" %% "spire-macros" % "0.17.0-M1"

val fastparse = "com.lihaoyi" %% "fastparse" % "2.3.3"
Expand Down Expand Up @@ -160,7 +154,7 @@ def libraryDefSettings = commonSettings ++ crossScalaSettings ++ testSettings

lazy val commonDependenies2 = libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scorexfoundation" %%% "debox" % "0.9.0-9-f853cdce-SNAPSHOT",
"org.scorexfoundation" %%% "debox" % "0.10.0",
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.7.0"
)

Expand Down Expand Up @@ -195,11 +189,11 @@ lazy val corelib = crossProject(JVMPlatform, JSPlatform)
)
.jvmSettings(
crossScalaSettings,
scryptoDependency("jvm")
scryptoDependency
)
.jsSettings(
crossScalaSettingsJS,
scryptoDependency("js"),
scryptoDependency,
libraryDependencies ++= Seq(
"org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0"
),
Expand Down
21 changes: 21 additions & 0 deletions common/shared/src/main/scala/scalan/util/ReflectionUtil.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package scalan.util

import scala.language.existentials

object ReflectionUtil {

implicit class ClassOps(val cl: Class[_]) extends AnyVal {
private def isSpecialChar(c: Char): Boolean = {
('0' <= c && c <= '9') || c == '$'
}
def safeSimpleName: String = {
if (cl.getEnclosingClass == null) return cl.getSimpleName
val simpleName = cl.getName.substring(cl.getEnclosingClass.getName.length)
val length = simpleName.length
var index = 0
while (index < length && isSpecialChar(simpleName.charAt(index))) { index += 1 }
// Eventually, this is the empty string iff this is an anonymous class
simpleName.substring(index)
}
}
}
3 changes: 2 additions & 1 deletion graph-ir/src/main/scala/scalan/Entities.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scalan

import scala.language.higherKinds
import scalan.util.ReflectionUtil.ClassOps

/** A slice in the Scalan cake with base classes for various descriptors. */
trait Entities extends TypeDescs { self: Scalan =>
Expand All @@ -13,7 +14,7 @@ trait Entities extends TypeDescs { self: Scalan =>
def parent: Option[Elem[_]] = None
/** Name of the entity type without `Elem` suffix. */
def entityName: String = {
val n = this.getClass.getSimpleName.stripSuffix("Elem")
val n = this.getClass.safeSimpleName.stripSuffix("Elem")
n
}
def convert(x: Ref[Def[_]]): Ref[A] = !!!("should not be called")
Expand Down
6 changes: 3 additions & 3 deletions graph-ir/src/main/scala/scalan/TypeDescs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.annotation.implicitNotFound
import scala.collection.immutable.ListMap
import scalan.util._
import scalan.RType._

import scalan.util.ReflectionUtil.ClassOps
import scala.collection.mutable
import debox.cfor
import scalan.reflection.{RClass, RConstructor, RMethod}
Expand Down Expand Up @@ -108,7 +108,7 @@ abstract class TypeDescs extends Base { self: Scalan =>
lazy val name: String = getName(_.name)

// <> to delimit because: [] is used inside name; {} looks bad with structs.
override def toString = s"${getClass.getSimpleName}<$name>"
override def toString = s"${getClass.safeSimpleName}<$name>"
}

/** Type descriptor of staged types, which correspond to source (unstaged) RTypes
Expand All @@ -134,7 +134,7 @@ abstract class TypeDescs extends Base { self: Scalan =>
be.sourceType.name
case e =>
val cl = e.getClass
val name = cl.getSimpleName.stripSuffix("Elem")
val name = cl.safeSimpleName.stripSuffix("Elem")
name
}
if (typeArgs.isEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,12 @@ trait ObjectGenerators extends TypeGenerators
ErgoTree.withoutSegregation))
} yield treeBuilder(prop)

lazy val ergoTreeWithSegregationGen: Gen[ErgoTree] = for {
sigmaBoolean <- Gen.delay(sigmaBooleanGen)
propWithConstants <- Gen.delay(logicalExprTreeNodeGen(Seq(AND.apply, OR.apply, XorOf.apply)).map(_.toSigmaProp))
prop <- Gen.oneOf(propWithConstants, sigmaBoolean.toSigmaProp)
} yield ErgoTree.withSegregation(prop)

def headerGen(stateRoot: AvlTree, parentId: Coll[Byte]): Gen[Header] = for {
id <- modifierIdBytesGen
version <- arbByte.arbitrary
Expand Down
Loading

0 comments on commit 18d9e4c

Please sign in to comment.