-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvalStatefulConditional.ulam
58 lines (48 loc) · 1.54 KB
/
EvalStatefulConditional.ulam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local typedef EvalConditional EC;
local typedef PackageData PD;
/**
Helper for evaluating conditionals that may require multiple retries.
*/
transient EvalStatefulConditional : Eval {
typedef Exec.State State;
constant State cSTATE_IF_ATTACHED_NEXT_2 = 17;
constant State cSTATE_FIRST = cSTATE_IF_ATTACHED_NEXT_2;
constant State cSTATE_LAST = cSTATE_IF_ATTACHED_NEXT_2;
Arity eval(Exec& exec, Package& tree, Bool& done) {
Bool cond = false;
Symbol symbol = PD.cNIL;
if (exec.isState(cSTATE_IF_ATTACHED_NEXT_2)) {
cond = isAttachedNext2(exec, done);
symbol = EC.cIF_ATTACHED_NEXT_2;
}
EvalConditional ec;
if (ec.getArgNum(symbol) == 1)
return cond ? 1u : Arity.maxof;
return cond ? 0u : 1u;
}
Bool isAttachedNext2(Exec& exec, Bool& done) {
Index index = getBondIndex(exec, cSRC);
Index nextIndex = getBondIndex(exec, cDST);
Index nextIndex2 = getBondIndex(exec, cREG1);
done = false;
// Get attached atom (bondable)
QBond& bond = exec.getBond(index);
if (!bond.isAttached()) {
done = true;
return false;
}
SiteNum site = bond.getSiteNumber();
IBondable& bondable = (IBondable&) ew[site];
// Get next atom
QBond& nextBond = bondable.getBond(nextIndex);
if (!nextBond.isAttached()) {
done = true;
return false;
}
SiteNum nextSite = nextBond.getSiteNumber(site);
if (!ew.isAccessible(nextSite))
return false;
IBondable& next = (IBondable&) ew[nextSite];
return next.getBond(nextIndex2).isAttached();
}
}