scalus.compiler

package scalus.compiler

Members list

Type members

Classlikes

final class Compile extends Annotation

Attributes

Supertypes
class Annotation
class Object
trait Matchable
class Any
final class Ignore extends Annotation

Attributes

Supertypes
class Annotation
class Object
trait Matchable
class Any
final class OnChainSubstitute(substitute: AnyRef, selfAs: Class[_] = ...) extends StaticAnnotation

Marks a trait/class as having an on-chain substitute object.

Marks a trait/class as having an on-chain substitute object.

When the Scalus plugin compiles a method call on a type annotated with @OnChainSubstitute, it redirects the call to the substitute @Compile object. The substitute object must define methods matching the original trait's methods, with an additional self first parameter.

On-chain, self receives the actual qualifier value (cast via typeProxy if selfAs is specified). Off-chain, the trait works as normal OOP — the annotation is ignored.

Value parameters

selfAs

The on-chain type for self. The plugin inserts a zero-cost typeProxy cast from the trait type to selfAs. Defaults to Nothing (no cast, self keeps the original type). Example:

@OnChainSubstitute(OnChainCellOps, classOf[ScriptContext])
trait CellContext {
 def requireSignedBy(pkh: PubKeyHash): Unit
}
@Compile
object OnChainCellOps {
 def requireSignedBy(self: ScriptContext, pkh: PubKeyHash): Unit =
     require(self.txInfo.isSignedBy(pkh), "missing signature")
}
substitute

A @Compile object providing on-chain implementations for each trait method.

Attributes

Supertypes
trait StaticAnnotation
class Annotation
class Object
trait Matchable
class Any
case class Options(targetLoweringBackend: TargetLoweringBackend = ..., targetLanguage: Language = ..., targetProtocolVersion: MajorProtocolVersion = ..., generateErrorTraces: Boolean = ..., removeTraces: Boolean = ..., optimizeUplc: Boolean = ..., debugLevel: Int = ..., debug: Boolean = ...)

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Options

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Options.type
trait SIRModuleAnnotation extends StaticAnnotation

Marker trait for annotations that should be propagated to SIR Module metadata.

Marker trait for annotations that should be propagated to SIR Module metadata.

The compiler plugin finds all annotations on @Compile objects whose class extends this trait and serializes their arguments generically into Module.anns.data. Adding a new annotation subclass requires zero plugin changes.

Keys in anns.data are "annotationClassName" for simple args or "annotationClassName:key" for Map entries.

Attributes

Supertypes
trait StaticAnnotation
class Annotation
class Object
trait Matchable
class Any

Value members

Concrete methods

def compile(e: Any): SIR

Compiles the given expression to a scalus.compiler.sir.SIR at compile time using the Scalus compiler plugin.

Compiles the given expression to a scalus.compiler.sir.SIR at compile time using the Scalus compiler plugin.

Value parameters

e

The expression to compile.

Attributes

Returns

The compiled scalus.compiler.sir.SIR.

Example
 val sir = scalus.compiler.compile(true) // Compiles the expression `true` to a SIR
 val uplc = sir.toUplc() // Converts the SIR to UPLC
def compileDebug(e: Any): SIR

Compiles the given expression to a scalus.compiler.sir.SIR at compile time using the Scalus compiler plugin, producing debug output during the compilation.

Compiles the given expression to a scalus.compiler.sir.SIR at compile time using the Scalus compiler plugin, producing debug output during the compilation.

Value parameters

e

The expression to compile.

Attributes

Returns

The compiled scalus.compiler.sir.SIR.

def compileDebugWithOptions(options: Options, e: Any): SIR

Compiles the given expression to a scalus.compiler.sir.SIR at compile time using the Scalus compiler plugin, with explicit compiler options and debug output.

Compiles the given expression to a scalus.compiler.sir.SIR at compile time using the Scalus compiler plugin, with explicit compiler options and debug output.

Value parameters

e

The expression to compile.

options

The compiler options to use.

Attributes

Returns

The compiled scalus.compiler.sir.SIR.

inline def compileInline(inline code: Any): SIR

Generates a scalus.compiler.compile(code) call at compile time.

Generates a scalus.compiler.compile(code) call at compile time.

When you want to use compile in an inline method you can't do it directly, because the Scalus compiler plugin finds the call to compile and replaces it with the compiled code. Which is not what you want in this case!

For example this will not work:

 inline def myTest(inline code: Any): SIR = {
     scalus.compiler.compile(code).toUplc().evaluate
 }

Instead, you should use this method:

inline def myTest(inline code: Any): SIR = {
   scalus.compiler.compileInline(code).toUplc().evaluate
}

Attributes

inline def compileInlineWithOptions(inline options: Options, inline code: Any): SIR

Compiles the given expression to a scalus.compiler.sir.SIRType at compile time using the Scalus compiler plugin.

Compiles the given expression to a scalus.compiler.sir.SIRType at compile time using the Scalus compiler plugin.

Type parameters

T

The type to compile.

Attributes

Returns

The compiled scalus.compiler.sir.SIRType.

Example
 // Compiles the type `BigInt` to a SIRType.Integer
 val sirType = scalus.compiler.compileType[BigInt]
def compileWithOptions(options: Options, e: Any): SIR

Compiles the given expression to a scalus.compiler.sir.SIR at compile time using the Scalus compiler plugin, with explicit compiler options.

Compiles the given expression to a scalus.compiler.sir.SIR at compile time using the Scalus compiler plugin, with explicit compiler options.

Value parameters

e

The expression to compile.

options

The compiler options to use.

Attributes

Returns

The compiled scalus.compiler.sir.SIR.

def compiledModules(moduleNames: String*): Map[String, Module]

Collects SIR modules from the given @Compile objects at compile time.

Collects SIR modules from the given @Compile objects at compile time.

The Scalus compiler plugin intercepts this call and replaces it with a Map[String, Module] containing the SIR modules of the referenced objects. Each argument must be a fully qualified name of a @Compile object (e.g., "scalus.compiler.intrinsics.BuiltinListOperations").

Value parameters

moduleNames

Fully qualified names of @Compile objects.

Attributes

Returns

A map from module name (with $ suffix) to scalus.compiler.sir.Module.

inline def fieldAsData[A](inline expr: A => Any): Data => Data
inline def offsetOf[A](inline expr: A => Any): BigInt

Returns the 0-based field index of a case-class field at compile time.

Returns the 0-based field index of a case-class field at compile time.

Useful in assembler mode with dropList to avoid hardcoding field offsets:

dropList(offsetOf[TxInfo](_.signatories), txInfoFields)
// expands to: dropList(BigInt(8), txInfoFields)

Type parameters

A

the case class type

Value parameters

expr

a single-level field selector, e.g. _.signatories

Attributes

Returns

the field index as BigInt