scalus.compiler
Members list
Packages
Type members
Classlikes
Attributes
- Supertypes
-
class Annotationclass Objecttrait Matchableclass Any
Attributes
- Supertypes
-
class Annotationclass Objecttrait Matchableclass Any
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-costtypeProxycast from the trait type toselfAs. Defaults toNothing(no cast,selfkeeps 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 objectproviding on-chain implementations for each trait method.
Attributes
- Supertypes
-
trait StaticAnnotationclass Annotationclass Objecttrait Matchableclass Any
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
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 StaticAnnotationclass Annotationclass Objecttrait Matchableclass Any
Value members
Concrete methods
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
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.
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.
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
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]
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.
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
@Compileobjects.
Attributes
- Returns
-
A map from module name (with
$suffix) to scalus.compiler.sir.Module.
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