DO
AddEdge:
PROC [sep: StatEdgeSpec] ~ {
[] ← EnsureStatEdge[d, a.statrep, sep, FALSE, TRUE, FALSE];
RETURN};
anDw: DumbWire ~ NARROW[wires.AnElt.MA];
dumby: DumbWire ~ CreateBareDumbWire[act];
losers: Set ~ wires.Difference[Sets.CreateSingleA[anDw, a.dumrep.dwSpace]];
StartDumb:
PROC [dwv: Sets.Value]
RETURNS [
BOOL] ~ {
dw: DumbWire ~ NARROW[dwv.VA];
[] ← dumby.eps.AddSet[dw.eps];
IF dw.children#nilBiRel THEN ERROR;
IF dw.parent#NIL THEN ERROR;
RETURN [FALSE]};
FixExport:
PROC [dwv: Sets.Value]
RETURNS [
BOOL] ~ {
dw: DumbWire ~ NARROW[dwv.VA];
IF dw#anDw THEN a.dumrep.apToWire.SubstituteA[dw, anDw, right];
RETURN [FALSE]};
IF wires.Scan[StartDumb].found THEN ERROR;
{givenCai: Set ~ dumby.eps.SetOn[right];
splort: BOOL ~ givenCai.NonTrivial;
allCai: Set ~ IF splort THEN Sets.IIAsSet[[0, a.size-1]] ELSE Sets.CreateSingleton[givenCai.TheElt, SetBasics.ints];
allEp: Set ~ a.dumrep.epw.Image[wires, rightToLeft].CreateHashCopy[];
allEps: BiRel ~ BiRels.CreateProduct[[allEp, allCai]];
missedEps: BiRel ~ allEps.Difference[dumby.eps];
IF missedEps.NonEmpty
THEN {
missedEp: Set ~ missedEps.SetOn[left].CreateHashCopy[];
theirWires: Set ~ a.dumrep.epw.Image[missedEp];
ourLosses: Set ~ wires.Intersection[theirWires].CreateHashCopy[];
[] ← balks.AddSet[ourLosses];
[] ← wires.RemSet[ourLosses];
IF wires.Trivial THEN RETURN ELSE LOOP};
IF wires.Scan[FixExport].found THEN ERROR;
{edges: Set ~ a.statrep.portEdge[FALSE].Image[allEp] .Union[a.statrep.portEdge[TRUE].Image[allEp]] .CreateHashCopy[];
theCai: CompositeArrayIndex ~ givenCai.AnElt.MI;
theAi: Int2 ~ DecomposeAI[a, theCai];
thePhase: Int2 ~ Mod[theAi, a.basePeriod];
anEp: Port ~ NARROW[anDw.eps.SetOn[left].AnElt.MA];
epSofar: Set ~ Sets.CreateHashSet[d.eSpace];
caiSofar: Set ← Sets.CreateSingleI[theCai, SetBasics.ints];
epsSofar: BiRel ← BiRels.CreateProduct[[epSofar, caiSofar]];
splable: BOOL ← splort;
FinishDumb:
PROC [dwv: Sets.Value]
RETURNS [
BOOL] ~ {
dw: DumbWire ~ NARROW[dwv.VA];
missedEps: Set ~ dw.eps.SetOn[left].Difference[epSofar];
DO
missedEp: Port ~ NARROW[missedEps.AnElt.MDA];
IF missedEp#
NIL
THEN {
IF splort
THEN
FOR
f
x:
NAT
IN [0 .. a.basePeriod[X])
DO
FOR
f
y:
NAT
IN [0 .. a.basePeriod[X])
DO
AddEdge[[vs: [[anEp, [fx, fy]], [missedEp, [fx, fy]]], d: ALL[0]]];
ENDLOOP ENDLOOP
ELSE AddEdge[[vs: [[anEp, thePhase], [missedEp, thePhase]], d: ALL[0]]];
IF NOT epSofar.AddA[missedEp] THEN ERROR;
LOOP};
IF NOT splable THEN EXIT;
{missedCaiMv: Sets.MaybeValue ~ dw.eps.SetOn[right].Difference[caiSofar].AnElt;
IF NOT missedCaiMv.found THEN EXIT;
{missedAi: Int2 ~ DecomposeAI[a, missedCaiMv.it.VI];
mep: Port ~ NARROW[dw.eps.Mapping[missedCaiMv.it, rightToLeft].AnElt.MA];
doDim: ARRAY Dim2 OF BOOL ~ [a.size2[X]>1, a.size2[Y]>1];
FOR dim: Dim2
IN Dim2
DO
IF doDim[dim]
THEN
FOR
f
x:
NAT
IN [0 .. a.basePeriod[X])
DO
FOR
f
y:
NAT
IN [0 .. a.basePeriod[X])
DO
delta: Int2 ~ ConsInt2[dim, 1, 0];
f: Int2 ~ [fx, fy];
IF a.size2[dim]>f[dim]+1 THEN AddEdge[[vs: [[mep, f], [mep, AddMod[f, delta, a.basePeriod]]], d: delta]];
ENDLOOP ENDLOOP;
ENDLOOP;
splable ← FALSE;
caiSofar ← allCai;
}}ENDLOOP;
RETURN [FALSE]};
FinishEP:
PROC [epv: Sets.Value]
RETURNS [
BOOL] ~ {
ep: Port ~ NARROW[epv.VA];
dws: Fn--composite array index b DumbWire-- ~ LichenArrayPrivate.GetDumbWires[a, ep, FALSE]^;
[] ← dws.AddSet[BiRels.CreateProduct[[allCai, Sets.CreateSingleA[anDw, a.dumrep.dwSpace]]]];
RETURN [FALSE]};
IF NOT epSofar.AddA[anEp] THEN ERROR;
IF wires.Scan[FinishDumb].found THEN ERROR;
IF allEp.Scan[FinishEP].found THEN ERROR;
[] ← anDw.eps.AddSet[allEps];
IF NOT a.dumrep.wires.RemSet[losers].had.all THEN ERROR;
TrimStatrep[act, a, edges];
RETURN}};
ENDLOOP;