Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.0] Merge with refactored SigmaCompiler #987

Merged
merged 29 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2ad11df
i966-template-compiler: use default values of parameters in compiler env
aslesarenko May 9, 2024
98fd5b7
i966-template-compiler: fix type of ContractParam field
aslesarenko May 9, 2024
232c25d
i966-template-compiler: fix for Scala 2.11
aslesarenko May 9, 2024
eb6270c
i966-template-compiler: create ConstantPlaceholder for each parameter…
aslesarenko May 12, 2024
6abf292
i966-template-compiler: added ErgoTreeUtils.explainTreeHeader
aslesarenko May 12, 2024
efabf24
i966-template-compiler: test ContractTemplate.applyTemplate method
aslesarenko May 12, 2024
dcee258
i966-template-compiler: more tests for CompilerTemplate.applyTemplate
aslesarenko May 12, 2024
ba6abad
i966-template-compiler: fix ErgoTreeUtilsSpec
aslesarenko May 12, 2024
28f7e15
i966-template-compiler: addressed review comments
aslesarenko May 12, 2024
8af5260
Merge pull request #977 from ScorexFoundation/i966-template-compiler
aslesarenko May 12, 2024
302b09d
refactor-ir-cake: removed Library trait (merged with Scalan)
aslesarenko May 14, 2024
3ffafe7
refactor-ir-cake: removed SigmaLibrary.scala
aslesarenko May 15, 2024
30d3bd9
refactor-ir-cake: Scalan moved to sigma.compiler package
aslesarenko May 15, 2024
bd0feb0
refactor-ir-cake: IRContext moved to sigma.compiler
aslesarenko May 15, 2024
f4bd542
refactor-ir-cake: everything is assembled in Scalan cake
aslesarenko May 15, 2024
26da1fa
refactor-ir-cake: Scalan renamed to IRContext
aslesarenko May 15, 2024
9c9ddc5
refactor-ir-cake: `staged` package removed
aslesarenko May 16, 2024
291f255
refactor-ir-cake: IR classes moved to sigma.compiler.ir package
aslesarenko May 16, 2024
7247cf8
refactor-ir-cake: move classes around in sigma.compiler.ir
aslesarenko May 16, 2024
80114f1
refactor-ir-cake: SigmaCompiler moved to sigma.compiler package
aslesarenko May 16, 2024
66daf52
refactor-ir-cake: wrappers moved to sigma.compiler.ir.wrappers package
aslesarenko May 16, 2024
baab0a8
refactor-ir-cake: wrappers moved to sigma.compiler.ir.wrappers packag…
aslesarenko May 16, 2024
7c18eef
refactor-ir-cake: wrappers moved to sigma.compiler.ir.wrappers packag…
aslesarenko May 16, 2024
3dd55aa
refactor-ir-cake: SizeOf, CostOf removed from IR + more ScalaDocs
aslesarenko May 16, 2024
f56df6a
refactor-ir-cake: removed WSpecialPredefs.scala
aslesarenko May 16, 2024
318c05b
Merge branch 'refs/heads/refactor-ir-cake' into v6.0.0-refactor-ir-cake
aslesarenko May 16, 2024
553bee8
refactor-ir-cake: add ScalaDoc
aslesarenko May 21, 2024
2b72e1a
Merge pull request #986 from ScorexFoundation/refactor-ir-cake
aslesarenko May 21, 2024
a63631f
Merge remote-tracking branch 'refs/remotes/origin/develop' into v6.0.…
aslesarenko May 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data/shared/src/main/scala/sigma/ast/ErgoTree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ case class UnparsedErgoTree(bytes: mutable.WrappedArray[Byte], error: Validation
* ErgoTreeSerializer defines top-level serialization format of the scripts.
* The interpretation of the byte array depend on the first `header` byte, which uses VLQ encoding up to 30 bits.
* Currently we define meaning for only first byte, which may be extended in future versions.
* 7 6 5 4 3 2 1 0
* 7 6 5 4 3 2 1 0
* -------------------------
* | | | | | | | | |
* -------------------------
* Bit 7 == 1 if the header contains more than 1 byte (default == 0)
* Bit 6 - reserved for GZIP compression (should be 0)
* Bit 5 == 1 - reserved for context dependent costing (should be = 0)
* Bit 5 == 1 - reserved (should be = 0)
* Bit 4 == 1 if constant segregation is used for this ErgoTree (default = 0)
* (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/264)
* Bit 3 == 1 if size of the whole tree is serialized after the header byte (default = 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sigmastate.lang
import fastparse._
import fastparse.NoWhitespace._
import SigmaParser._
import sigma.ast.SType
import sigma.ast.{Constant, SType}
import sigma.ast.syntax.SValue
import sigmastate.lang.parsers.Basic

Expand Down Expand Up @@ -187,9 +187,9 @@ object ContractParser {

def annotation[_: P] = P("@contract")

def paramDefault[_: P] = P(WL.? ~ `=` ~ WL.? ~ ExprLiteral).map(s => s.asWrappedType)
def paramDefault[_: P] = P(WL.? ~ `=` ~ WL.? ~ ExprLiteral)

def param[_: P] = P(WL.? ~ Id.! ~ ":" ~ Type ~ paramDefault.?).map(s => ContractParam(s._1, s._2, s._3))
def param[_: P] = P(WL.? ~ Id.! ~ ":" ~ Type ~ paramDefault.?).map(s => ContractParam(s._1, s._2, s._3.map(_.value)))

def params[_: P] = P("(" ~ param.rep(1, ",").? ~ ")")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sigmastate.lang
import org.scalatest.matchers.should.Matchers
import org.scalatest.propspec.AnyPropSpec
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
import sigma.ast.SType.AnyOps
import sigma.ast._

class ContractParserSpec extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers {
Expand Down Expand Up @@ -34,8 +35,8 @@ class ContractParserSpec extends AnyPropSpec with ScalaCheckPropertyChecks with

parsed.name shouldBe "contractName"
parsed.params should contain theSameElementsInOrderAs Seq(
ContractParam("p1", SInt, Some(IntConstant(5).asWrappedType)),
ContractParam("p2", SString, Some(StringConstant("default string").asWrappedType)),
ContractParam("p1", SInt, Some(5.asWrappedType)),
ContractParam("p2", SString, Some("default string".asWrappedType)),
ContractParam("param3", SLong, None)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package sigmastate.lang

import org.scalatest.matchers.should.Matchers
import sigma.{Coll, _}
import sigma.ast.SCollection.SByteArray
import sigma.ast.syntax.{SValue, ValueOps}
import sigma.ast._
import sigma.crypto.CryptoConstants
import sigma.data.{CAnyValue, CSigmaDslBuilder, ProveDHTuple, ProveDlog, SigmaBoolean}
import sigma.util.Extensions.BigIntegerOps
import sigma._
import sigmastate.helpers.NegativeTesting
import sigmastate.interpreter.Interpreter.ScriptEnv
import sigma.ast.{Ident, MethodCallLike}

import java.math.BigInteger

Expand Down
6 changes: 3 additions & 3 deletions sc/js/src/main/scala/sigmastate/lang/js/SigmaCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import scala.scalajs.js
import scala.scalajs.js.annotation.JSExportTopLevel
import sigma.js.Value
import sigma.ast.ErgoTree.HeaderType
import sigmastate.eval.CompiletimeIRContext
import sigma.compiler.ir.CompiletimeIRContext
import sigma.ast.syntax.ValueOps


/** Wrapper exported to JS. */
@JSExportTopLevel("SigmaCompiler")
class SigmaCompiler(_compiler: sigmastate.lang.SigmaCompiler) extends js.Object {
class SigmaCompiler(_compiler: sigma.compiler.SigmaCompiler) extends js.Object {

/** Compiles ErgoScript code to ErgoTree.
*
Expand Down Expand Up @@ -59,7 +59,7 @@ object SigmaCompiler extends js.Object {
* @return SigmaCompiler instance
*/
private def create(networkPrefix: Byte): SigmaCompiler = {
val compiler = sigmastate.lang.SigmaCompiler(networkPrefix)
val compiler = sigma.compiler.SigmaCompiler(networkPrefix)
new SigmaCompiler(compiler)
}
}
6 changes: 4 additions & 2 deletions sc/js/src/test/scala/scalan/Platform.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package scalan

import sigma.compiler.ir.IRContext

import scala.annotation.unused

object Platform {
/** In JS tests do nothing. The corresponding JVM method outputs graphs into files. */
def stage[Ctx <: Scalan](scalan: Ctx)(
def stage[Ctx <: IRContext](ctx: Ctx)(
@unused prefix: String,
@unused testName: String,
@unused name: String,
@unused sfs: Seq[() => scalan.Sym]): Unit = {
@unused sfs: Seq[() => ctx.Sym]): Unit = {
}

/** On JS it is no-operation. */
Expand Down
11 changes: 6 additions & 5 deletions sc/jvm/src/test/scala/scalan/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ package scalan
import scalan.compilation.GraphVizExport
import sigma.util.FileUtil
import org.scalatest.Assertions
import sigma.compiler.ir.IRContext

object Platform {
/** Output graph given by symbols in `sfs` to files.
* @param scalan The Scalan context
* @param ctx The Scalan context
* @param prefix The prefix of the directory where the graphs will be stored.
* @param testName The name of the test.
* @param name The name of the graph.
* @param sfs A sequence of functions that return symbols of the graph roots.
*/
def stage[Ctx <: Scalan](scalan: Ctx)
(prefix: String, testName: String, name: String, sfs: Seq[() => scalan.Sym]): Unit = {
def stage[Ctx <: IRContext](ctx: Ctx)
(prefix: String, testName: String, name: String, sfs: Seq[() => ctx.Sym]): Unit = {
val directory = FileUtil.file(prefix, testName)
val gv = new GraphVizExport(scalan)
val gv = new GraphVizExport(ctx)
implicit val graphVizConfig = gv.defaultGraphVizConfig
try {
val ss = sfs.map(_.apply()).asInstanceOf[Seq[gv.scalan.Sym]]
val ss = sfs.map(_.apply()).asInstanceOf[Seq[gv.ctx.Sym]]
gv.emitDepGraph(ss, directory, name)(graphVizConfig)
} catch {
case e: Exception =>
Expand Down
6 changes: 3 additions & 3 deletions sc/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package scalan.compilation

import java.awt.Desktop
import java.io.{File, PrintWriter}
import scalan.Scalan
import scalan.core.ScalaNameUtil
import sigma.compiler.ir.IRContext
import sigma.util.{FileUtil, ProcessUtil, StringUtil}

import scala.annotation.unused
Expand All @@ -12,8 +12,8 @@ import scala.collection.immutable.StringOps
// TODO implement this outside of the cake

/** Implementation of Graphviz's dot file generator. */
class GraphVizExport[Ctx <: Scalan](val scalan: Ctx) {
import scalan._
class GraphVizExport[Ctx <: IRContext](val ctx: Ctx) {
import ctx._
case class GraphFile(file: File, fileType: String) {
def open() = {
Desktop.getDesktop.open(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sigmastate

import org.scalatest.matchers.should.Matchers
import org.scalatest.propspec.AnyPropSpec
import scalan.TypeDescs
import sigma.compiler.ir.{IRContext, TypeDescs}
import sigma.reflection.ReflectionData.registerClassEntry
import sigma.reflection.SRConstructor

Expand Down Expand Up @@ -37,7 +37,7 @@ class InterpreterReflectionGeneratorTests extends AnyPropSpec with Matchers {
}

property("inner class") {
val ctx = null.asInstanceOf[scalan.Library] // ok! type level only
val ctx = null.asInstanceOf[IRContext] // ok! type level only
val clazz = classOf[ctx.Coll.CollElem[_, _]]
registerClassEntry(clazz,
constructors = Array(
Expand Down
21 changes: 16 additions & 5 deletions sc/jvm/src/test/scala/sigmastate/ReflectionGenerator.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
package sigmastate

import scalan.{Base, TypeDescs}
import sigma.compiler.ir.{Base, TypeDescs}
import sigma.reflection._
import scala.annotation.unused
import scala.collection.mutable

/** Generates code for registering classes in the ReflectionData.
* It is not used in the runtime.
*
* The generated invocations of `registerClassEntry`, `mkMethod`, `mkConstructor` may
* require manual adjustments.
*
* It uses [[sigma.reflection.Platform.unknownClasses]] to collect classes which were
* accessed during runtime
*
* @see [[ReflectionData]]
*/
object ReflectionGenerator {

def normalizeName(name: String): String = {
Expand All @@ -30,17 +41,17 @@ object ReflectionGenerator {
}

val knownPackages = Array(
"scalan.primitives.",
"sigma.compiler.ir.primitives.",
"sigma.",
"sigma.",
"special.wrappers.",
"sigma.compiler.ir.wrappers.",
"sigma.ast.",
"sigmastate.lang.Terms.",
"sigmastate.interpreter.",
"sigmastate.utxo.",
"sigmastate.",
"wrappers.scala.",
"scalan.",
"sigma.compiler.ir.wrappers.scala.",
"sigma.compiler.ir.",
"scala.collection.",
"scala."
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.ergoplatform

import sigmastate.lang.SigmaCompiler
import sigmastate.eval.IRContext
import org.ergoplatform.ErgoAddressEncoder.NetworkPrefix
import sigma.ast.SType
import sigma.ast.syntax.SigmaPropValue
import sigma.ast.Value
import sigma.ast.syntax.ValueOps
import sigma.compiler.SigmaCompiler
import sigma.compiler.ir.IRContext

object ErgoScriptPredef {
import sigmastate.interpreter.Interpreter._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import sigma.interpreter.{CostedProverResult, ProverResult}
import sigma.data.{CSigmaDslBuilder, RType}
import org.ergoplatform.{ErgoBox, ErgoLikeContext}
import sigma.{Coll, SigmaDslBuilder, SigmaProp}
import sigmastate.eval.IRContext

import scala.util.Try
import org.ergoplatform.dsl.ContractSyntax.{ErgoScript, Proposition, Token}
import sigma.ast.{ErgoTree, EvaluatedValue, SType}
import sigma.compiler.ir.IRContext

import scala.language.implicitConversions

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.ergoplatform.dsl

import sigma.Coll
import sigmastate.eval.IRContext
import org.ergoplatform.dsl.ContractSyntax.{ErgoScript, Proposition, Token}
import org.ergoplatform.ErgoBox.{BoxId, NonMandatoryRegisterId, TokenId}
import sigma.compiler.ir.IRContext
import sigma.interpreter.CostedProverResult

class ErgoContractSpec(implicit val IR: IRContext) extends ContractSpec {
Expand Down
36 changes: 0 additions & 36 deletions sc/shared/src/main/scala/scalan/Scalan.scala

This file was deleted.

92 changes: 0 additions & 92 deletions sc/shared/src/main/scala/scalan/primitives/UniversalOps.scala

This file was deleted.

Loading
Loading