While looking into a recent question I noticed that the I7 compiler seems to be at least a little bit smart regarding its awareness of the code chunks associated with executing various tasks for a relation.
The example in question involves the condition test for player is within nothing
, which produces code like:
! True or false?
! [ DoesNotExist x IN[ IN] : is(x, ContainerOf('player')) ]
[ Prop_3
...
objectloop (x ofclass Object){
qcn_0++;
if ((x == ContainerOf(player))){ ! <-- key line
qcy_0++;
}
}
if (qcy_0 == 0){
rtrue;
}
rfalse;
];
The key line makes use of a routine ContainerOf()
, which also appears in the relation handler for the containment relation
:
[ Rel_Handler_15
...
switch (task) {
RELS_TEST: if (X == ContainerOf(Y)) rtrue; rfalse; ! <-- task for testing whether a relation holds
...
}
rfalse;
];
For the same condition test using an author-written relation, the role of ContainerOf()
is displaced by a different generated routine:
for (x=IK2_First: x: x=x.IK2_Link){
qcn_0++;
if (((RGuard_f1_7(x)) == player)){ ! <-- replaced logic
qcy_0++;
}
}
which is also used in the handler for that relation:
[ Rel_Handler_81
...
switch (task) {
RELS_TEST: if (Y == (RGuard_f1_7(X))) rtrue; rfalse; ! <-- task for testing whether a relation holds
}
rfalse;
];
It seems as though the code generation is modular here, and that some special case code forces use of ContainerOf()
as the the “truth-tester” routine instead of a generated one.
It occurs to me that if such special case code exists, then exposing hooks for it could be very useful. It would allow authors to make use of some of the same tricks as core relations, such as ensuring mutual exclusivity between sets of two or more relations (a la spatial relations) or enforcing simultaneous applicability of another relation (e.g. the wearing relation
forcing spatial movement when asserted true).
I know Inform doesn’t allow that now, but I’m wondering just how feasible this might be to implement. Depending on the underlying structure, it could be low-effort. Does anyone happen to know where to find the part of the I7 source documentation that covers generation of code chunks for relation tasks?