BaseSimpleLowering

scalus.compiler.sir.lowering.simple.BaseSimpleLowering
abstract class BaseSimpleLowering(sir: SIR, generateErrorTraces: Boolean = ..., val targetLanguage: Language = ...) extends DataLowering

Base class for simple lowering from Scalus Intermediate Representation SIR to UPLC scalus.uplc.Term.

This class contains common functionality shared between different lowering strategies. Subclasses must implement the encoding-specific methods for constructors, pattern matching, and field selection.

Value parameters

generateErrorTraces

whether to generate error traces

sir

the Scalus Intermediate Representation to lower

targetLanguage

the target Plutus language version

Attributes

Graph
Supertypes
trait DataLowering
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Concrete methods

def lower(): Term

Lower the SIR to UPLC Term

Lower the SIR to UPLC Term

Attributes

Inherited methods

protected def isDataConstructor(name: String): Boolean

Check if a constructor name is a Data type constructor.

Check if a constructor name is a Data type constructor.

Attributes

Inherited from:
DataLowering
protected def isDataType(sirType: SIRType): Boolean

Check if a SIR type is the builtin Data type.

Check if a SIR type is the builtin Data type.

Attributes

Inherited from:
DataLowering
protected def isDataVariantType(sirType: SIRType): Boolean

Check if a scrutinee type is a known Data variant (I, B, List, Map, Constr).

Check if a scrutinee type is a known Data variant (I, B, List, Map, Constr).

Attributes

Inherited from:
DataLowering
protected def lowerDataCaseBranchV3(sirCase: Case, variantName: String, scrutineeRef: Term): Term

Lower a single case branch for Data pattern matching (PlutusV3).

Lower a single case branch for Data pattern matching (PlutusV3).

For V3 chooseData, branches are thunks that reference a pre-bound scrutinee. We extract values from the scrutinee within each branch.

Attributes

Inherited from:
DataLowering
protected def lowerDataCaseBranchV4(sirCase: Case, variantName: String): Term

Lower a single case branch for Data pattern matching (PlutusV4).

Lower a single case branch for Data pattern matching (PlutusV4).

For V4 Case on Data, branches are lambdas that receive the inner values directly:

  • Constr: \tag args -> body
  • Map: \entries -> body
  • List: \elements -> body
  • I: \value -> body
  • B: \value -> body

Even for wildcards/no-bindings, we need lambdas that ignore the inner values.

Attributes

Inherited from:
DataLowering
protected def lowerDataConstr(name: String, args: List[SIR], anns: AnnotationsDecl): Term

Lower a Data constructor expression to UPLC.

Lower a Data constructor expression to UPLC.

Data constructors are lowered to their corresponding builtin functions:

  • Data.I(value) → iData(value)
  • Data.B(value) → bData(value)
  • Data.List(values) → listData(values)
  • Data.Map(values) → mapData(values)
  • Data.Constr(tag, args) → constrData(tag, args)

Attributes

Inherited from:
DataLowering
protected def lowerDataMatch(matchExpr: Match): Term

Lower a match expression on Data type.

Lower a match expression on Data type.

Data has 5 constructors in a fixed order:

  • 0: Constr (tag: Integer, args: List[Data])
  • 1: Map (entries: List[(Data, Data)])
  • 2: List (elements: List[Data])
  • 3: I (value: Integer)
  • 4: B (value: ByteString)

For PlutusV4, use Case on Data instruction. For PlutusV3 and earlier, use chooseData builtin.

For V4 Case on Data:

  • Branches are lambdas that receive the inner values
  • Constr branch: \tag args -> body
  • Other branches: \value -> body

For V3 chooseData:

  • chooseData just selects a delayed branch, it doesn't pass arguments
  • We bind the scrutinee first, then extract values within each branch

Attributes

Inherited from:
DataLowering
protected def lowerDataSelect(scrutinee: SIR, field: String, tp: SIRType, anns: AnnotationsDecl): Term

Lower a field selection on Data type.

Lower a field selection on Data type.

Data field selections are lowered to their corresponding builtin unpack functions:

  • Data.I.value → unIData(scrutinee)
  • Data.B.value → unBData(scrutinee)
  • Data.List.values → unListData(scrutinee)
  • Data.Map.values → unMapData(scrutinee)
  • Data.Constr.constr → fstPair(unConstrData(scrutinee))
  • Data.Constr.args → sndPair(unConstrData(scrutinee))

Attributes

Inherited from:
DataLowering