Class ConstraintLowering
java.lang.Object
org.ek9lang.compiler.phase7.ConstraintLowering
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 Summary
ConstructorsConstructorDescriptionConstraintLowering(IRGenerationContext stackContext, ConstrainedTypeInstrs instrs, BooleanCondition booleanCondition) -
Method Summary
Modifier and TypeMethodDescription(package private) voidemitConstraintCheck(List<IRInstr> instructions, String subjectVar, String scopeId, DebugInfo debugInfo) Emit the constraint check onsubjectVar(a base-type value).(package private) voidemitViabilityCheck(List<IRInstr> instructions, String subjectVar, String scopeId, DebugInfo debugInfo) Evaluate whethersubjectVaris a USABLE value for this constrained type - it is set AND satisfies the constraint - and store that Boolean as the first_viable.(package private) StringwalkConstraint(EK9Parser.ConstrainTypeContext ctx, String subjectVar, List<IRInstr> instructions, String scopeId, DebugInfo debugInfo) Lower theconstrainTypeparse tree to IR oversubjectVar, returning the temp holding the resulting Boolean.
-
Constructor Details
-
ConstraintLowering
ConstraintLowering(IRGenerationContext stackContext, ConstrainedTypeInstrs instrs, BooleanCondition booleanCondition)
-
-
Method Details
-
emitViabilityCheck
void emitViabilityCheck(List<IRInstr> instructions, String subjectVar, String scopeId, DebugInfo debugInfo) Evaluate whethersubjectVaris 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_initand the fallible factory. -
emitConstraintCheck
void emitConstraintCheck(List<IRInstr> instructions, String subjectVar, String scopeId, DebugInfo debugInfo) Emit the constraint check onsubjectVar(a base-type value). Evaluates the declared constraint expression to a Boolean; if it does not hold (false or unset), constructs and throws anorg.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 theconstrainTypeparse tree to IR oversubjectVar, 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
-