Builder

scalus.compiler.sir.lowering.LoweredValue.Builder
object Builder

Builder for LoweredValue, to avoid boilerplate code. Import this object to make available

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Builder.type

Members list

Value members

Concrete methods

def lvApply(f: LoweredValue, arg: LoweredValue, inPos: SIRPosition, resTp: Option[SIRType] = ..., resRepr: Option[LoweredValueRepresentation] = ...)(using lctx: LoweringContext): LoweredValue

Low-level apply that skips automatic type/representation conversion.

Low-level apply that skips automatic type/representation conversion.

Use when the caller explicitly manages argument types and representations, e.g., in runtime conversion functions where arguments are intentionally in non-default representations.

Attributes

def lvAsIdentifiable(lv: LoweredValue, nameHint: String, tp: SIRType, repr: LoweredValueRepresentation, pos: SIRPosition)(using lctx: LoweringContext): (IdentifiableLoweredValue, Boolean)

If lv is already identifiable, return it unchanged with false. Otherwise wrap it in a fresh lazy let-binding (lvNewLazyIdVar) with nameHint (uniqued), tp, and repr, returning the new identifiable plus true to signal the caller that it must add the binding to scope (e.g., via ScopeBracketsLoweredValue).

If lv is already identifiable, return it unchanged with false. Otherwise wrap it in a fresh lazy let-binding (lvNewLazyIdVar) with nameHint (uniqued), tp, and repr, returning the new identifiable plus true to signal the caller that it must add the binding to scope (e.g., via ScopeBracketsLoweredValue).

tp / repr are passed explicitly because some callers wrap the result of a toRepresentation conversion whose runtime type/repr differs from the source value's stored ones.

Note: when lv is already identifiable, tp and repr are ignored — the existing binding's stored shape is returned as-is. Callers that pass values different from lv.sirType / lv.representation must already have ensured the existing binding's shape matches what they need; otherwise the identifiable branch would silently mask a mismatch.

Attributes

def lvBoolConstant(value: Boolean, pos: SIRPosition)(using lctx: LoweringContext): ConstantLoweredValue
def lvCaseBoolean(scrutinee: LoweredValue, falseBranch: LoweredValue, trueBranch: LoweredValue, inPos: SIRPosition, optTargetType: Option[SIRType] = ...)(using lctx: LoweringContext): LoweredValue

Generate a case expression on a boolean value (PlutusV4 feature).

Generate a case expression on a boolean value (PlutusV4 feature).

In PlutusV4, Case can be used directly on boolean constants: Case(bool, [falseBranch, trueBranch]) where False = index 0 and True = index 1.

Attributes

def lvCaseData(scrutinee: LoweredValue, constrTagVar: IdentifiableLoweredValue, constrArgsVar: IdentifiableLoweredValue, constrBranch: LoweredValue, mapEntriesVar: IdentifiableLoweredValue, mapBranch: LoweredValue, listElementsVar: IdentifiableLoweredValue, listBranch: LoweredValue, iValueVar: IdentifiableLoweredValue, iBranch: LoweredValue, bValueVar: IdentifiableLoweredValue, bBranch: LoweredValue, inPos: SIRPosition, optTargetType: Option[SIRType] = ...)(using lctx: LoweringContext): LoweredValue

Create a Case on Data for PlutusV4+.

Create a Case on Data for PlutusV4+.

Value parameters

bBranch

the branch to execute for B case

bValueVar

variable to bind to the bytestring value (ByteString)

constrArgsVar

variable to bind to the constructor args (List[Data])

constrBranch

the branch to execute for Constr case

constrTagVar

variable to bind to the constructor tag (Integer)

iBranch

the branch to execute for I case

iValueVar

variable to bind to the integer value (Integer)

inPos

source position

listBranch

the branch to execute for List case

listElementsVar

variable to bind to the list elements (List[Data])

mapBranch

the branch to execute for Map case

mapEntriesVar

variable to bind to the map entries (List[(Data, Data)])

optTargetType

optional target type for the result

scrutinee

the Data value to match on

Attributes

def lvCaseInteger(scrutinee: LoweredValue, branches: List[LoweredValue], inPos: SIRPosition, optTargetType: Option[SIRType] = ...)(using lctx: LoweringContext): LoweredValue

Generate a case expression on an integer value (PlutusV4 feature).

Generate a case expression on an integer value (PlutusV4 feature).

In PlutusV4, Case can be used directly on integer constants when cases form a contiguous sequence starting from 0: Case(int, [branch0, branch1, ..., branchN]).

Value parameters

branches

list of branches indexed by integer value (0 -> branches(0), 1 -> branches(1), etc.)

inPos

source position

optTargetType

optional target type for the result

scrutinee

the integer value to match on

Attributes

def lvCaseList(scrutinee: LoweredValue, consHead: IdentifiableLoweredValue, consTail: IdentifiableLoweredValue, consBranch: LoweredValue, optNilBranch: Option[LoweredValue], inPos: SIRPosition, optTargetType: Option[SIRType] = ...)(using lctx: LoweringContext): LoweredValue

Generate a case expression on a list value (PlutusV4 feature).

Generate a case expression on a list value (PlutusV4 feature).

In PlutusV4, Case can be used directly on list constants: Case(list, [consBranch, nilBranch]) where Cons = index 0 (receives head and tail as arguments) and Nil = index 1 (no arguments).

Value parameters

consBranch

the branch to execute for non-empty list (Cons)

consHead

variable for the head element in cons branch

consTail

variable for the tail list in cons branch

inPos

source position

nilBranch

the branch to execute for empty list (Nil)

optTargetType

optional target type for the result

scrutinee

the list value to match on

Attributes

Create a Case on Pair for PlutusV4+.

Create a Case on Pair for PlutusV4+.

Value parameters

body

the body expression using fstVar and sndVar

fstVar

variable to bind to the first element

inPos

source position

scrutinee

the pair to match on

sndVar

variable to bind to the second element

Attributes

def lvCast(expr: LoweredValue, targetType: SIRType, inPos: SIRPosition, isTypeProxy: Boolean = ...)(using lctx: LoweringContext): LoweredValue

Nil for a BuiltinList[Data] with DataData element repr.

Nil for a BuiltinList[Data] with DataData element repr.

Attributes

def lvDelay(value: LoweredValue, inPos: SIRPosition)(using lctx: LoweringContext): LoweredValue
def lvForce(value: LoweredValue, inPos: SIRPosition)(using lctx: LoweringContext): LoweredValue
def lvIfThenElse(cond: LoweredValue, thenBranch: LoweredValue, elseBranch: LoweredValue, inPos: SIRPosition, optTargetType: Option[SIRType] = ...)(using lctx: LoweringContext): LoweredValue
def lvIntConstant(value: Int, pos: SIRPosition)(using lctx: LoweringContext): ConstantLoweredValue
def lvLamAbs(name: String, tp: SIRType, inputRepresentation: LoweredValueRepresentation, f: IdentifiableLoweredValue => LoweringContext ?=> LoweredValue, inPos: SIRPosition)(using lctx: LoweringContext): LoweredValue

create let and add it to the current scope.

create let and add it to the current scope.

Attributes

Nil for a BuiltinList[Data] used as product case constructor fields.

Nil for a BuiltinList[Data] used as product case constructor fields.

Attributes

def lvStringConstant(value: String, pos: SIRPosition)(using lctx: LoweringContext): ConstantLoweredValue
def lvTrace(message: String, value: LoweredValue)(using LoweringContext): LoweredValue

Convert input to target via a static intermediate repr — i.e., input.toRepresentation(intermediate, pos).toRepresentation(target, pos). Replaces per-emitter viaXxx helpers (Phase 5).

Convert input to target via a static intermediate repr — i.e., input.toRepresentation(intermediate, pos).toRepresentation(target, pos). Replaces per-emitter viaXxx helpers (Phase 5).

For intermediates that depend on input.sirType (e.g. SumBuiltinList(defaultDataRep(elemType))), keep the per-emitter helper since the intermediate computation needs sirType context — this via only wraps the static case.

Attributes