Class ConstraintLowering

java.lang.Object
org.ek9lang.compiler.phase7.ConstraintLowering

final class ConstraintLowering extends Object
THE lowering of a constrained type's constrain as expression (DFN-3): the Panicking check a value handed in must pass (emitConstraintCheck(List, String, String, DebugInfo)), its non-throwing twin that records viability (emitViabilityCheck(List, String, String, DebugInfo)), and the walk of the constraint's parse tree to a Boolean (walkConstraint(EK9Parser.ConstrainTypeContext, String, List, String, DebugInfo)).
  • Constructor Details

  • Method Details

    • emitViabilityCheck

      void emitViabilityCheck(List<IRInstr> instructions, String subjectVar, String scopeId, DebugInfo debugInfo)
      Evaluate whether subjectVar is a USABLE value for this constrained type - it is set AND satisfies the constraint - and store that Boolean as the first _viable. Never Panics.

      This is the non-throwing twin of emitConstraintCheck(List, String, String, DebugInfo). Both ask the same question; they differ only in what they do with the answer. A Panic is right when the CALLER handed us a value (the bare constructor). It is wrong everywhere the compiler synthesised the value itself, or where the contract is to report a rejection rather than abort - _i_init and the fallible factory.

    • emitConstraintCheck

      void emitConstraintCheck(List<IRInstr> instructions, String subjectVar, String scopeId, DebugInfo debugInfo)
      Emit the constraint check on subjectVar (a base-type value). Evaluates the declared constraint expression to a Boolean; if it does not hold (false or unset), constructs and throws an org.ek9.lang::Panic — uncatchable, so it propagates to the program _main.
    • walkConstraint

      String walkConstraint(EK9Parser.ConstrainTypeContext ctx, String subjectVar, List<IRInstr> instructions, String scopeId, DebugInfo debugInfo)
      Lower the constrainType parse tree to IR over subjectVar, returning the temp holding the resulting Boolean. Mirrors the grammar:
        constrainType
          : op=(GT|GE|LT|LE|EQUAL|NOTEQUAL|NOTEQUAL2|MATCHES|CONTAINS)? literal   // subject._op(literal)
          | constrainType op=(AND|OR) constrainType                               // left._and/_or(right)
          | LPAREN constrainType RPAREN