2021-05-01 13:56:10 +03:00
|
|
|
[SynopticRelations::] Relations.
|
|
|
|
|
2021-05-05 14:24:08 +03:00
|
|
|
To compile the main/synoptic/relations submodule.
|
2021-05-01 13:56:10 +03:00
|
|
|
|
2022-01-07 01:10:15 +02:00
|
|
|
@ Our inventory |inv| already contains a list |inv->relation_nodes| of all packages
|
|
|
|
in the tree with type |_relation|.
|
2021-05-01 13:56:10 +03:00
|
|
|
|
|
|
|
=
|
2021-11-15 01:40:33 +02:00
|
|
|
void SynopticRelations::compile(inter_tree *I, pipeline_step *step, tree_inventory *inv) {
|
2022-02-03 01:35:38 +02:00
|
|
|
if (InterNodeList::array_len(inv->relation_nodes) > 0) @<Assign unique relation ID numbers@>;
|
2021-05-05 14:24:08 +03:00
|
|
|
@<Define CCOUNT_BINARY_PREDICATE@>;
|
|
|
|
@<Define CREATEDYNAMICRELATIONS function@>;
|
|
|
|
@<Define ITERATERELATIONS function@>;
|
|
|
|
@<Define RPROPERTY function@>;
|
2021-05-01 13:56:10 +03:00
|
|
|
}
|
|
|
|
|
2022-01-07 01:10:15 +02:00
|
|
|
@ Each relation package contains a numeric constant with the symbol name |relation_id|.
|
|
|
|
We want to ensure that these ID numbers are contiguous from 0 and never duplicated,
|
|
|
|
so we change the values of these constants accordingly.
|
|
|
|
|
|
|
|
@<Assign unique relation ID numbers@> =
|
2022-02-03 01:35:38 +02:00
|
|
|
InterNodeList::array_sort(inv->relation_nodes, MakeSynopticModuleStage::module_order);
|
|
|
|
for (int i=0; i<InterNodeList::array_len(inv->relation_nodes); i++) {
|
2022-03-01 02:41:22 +02:00
|
|
|
inter_package *pack = PackageInstruction::at_this_head(inv->relation_nodes->list[i].node);
|
2022-01-07 01:10:15 +02:00
|
|
|
inter_tree_node *D = Synoptic::get_definition(pack, I"relation_id");
|
2022-03-13 23:18:06 +02:00
|
|
|
ConstantInstruction::set_constant(D, InterValuePairs::number((inter_ti) i));
|
2022-01-07 01:10:15 +02:00
|
|
|
}
|
|
|
|
|
2021-05-01 13:56:10 +03:00
|
|
|
@<Define CCOUNT_BINARY_PREDICATE@> =
|
2022-01-16 01:49:25 +02:00
|
|
|
inter_name *iname = HierarchyLocations::iname(I, CCOUNT_BINARY_PREDICATE_HL);
|
2022-02-03 01:35:38 +02:00
|
|
|
Produce::numeric_constant(I, iname, K_value, (inter_ti) (InterNodeList::array_len(inv->relation_nodes)));
|
2021-05-01 13:56:10 +03:00
|
|
|
|
2021-05-05 14:24:08 +03:00
|
|
|
@<Define CREATEDYNAMICRELATIONS function@> =
|
2022-01-16 01:49:25 +02:00
|
|
|
inter_name *iname = HierarchyLocations::iname(I, CREATEDYNAMICRELATIONS_HL);
|
2021-05-05 14:24:08 +03:00
|
|
|
Synoptic::begin_function(I, iname);
|
2022-02-03 01:35:38 +02:00
|
|
|
for (int i=0; i<InterNodeList::array_len(inv->relation_nodes); i++) {
|
2022-03-01 02:41:22 +02:00
|
|
|
inter_package *pack = PackageInstruction::at_this_head(inv->relation_nodes->list[i].node);
|
2022-03-01 00:24:58 +02:00
|
|
|
inter_symbol *creator_s = Metadata::optional_symbol(pack, I"^creator");
|
2022-01-22 18:44:52 +02:00
|
|
|
if (creator_s) Produce::inv_call_symbol(I, creator_s);
|
2021-05-01 13:56:10 +03:00
|
|
|
}
|
2021-11-15 01:40:33 +02:00
|
|
|
Synoptic::end_function(I, step, iname);
|
2021-05-01 13:56:10 +03:00
|
|
|
|
2021-05-05 14:24:08 +03:00
|
|
|
@<Define ITERATERELATIONS function@> =
|
2022-01-16 01:49:25 +02:00
|
|
|
inter_name *iname = HierarchyLocations::iname(I, ITERATERELATIONS_HL);
|
2021-05-05 14:24:08 +03:00
|
|
|
Synoptic::begin_function(I, iname);
|
|
|
|
inter_symbol *callback_s = Synoptic::local(I, I"callback", NULL);
|
2022-02-03 01:35:38 +02:00
|
|
|
for (int i=0; i<InterNodeList::array_len(inv->relation_nodes); i++) {
|
2022-03-01 02:41:22 +02:00
|
|
|
inter_package *pack = PackageInstruction::at_this_head(inv->relation_nodes->list[i].node);
|
2022-03-01 00:24:58 +02:00
|
|
|
inter_symbol *rel_s = Metadata::optional_symbol(pack, I"^value");
|
2021-06-04 01:03:51 +03:00
|
|
|
if (rel_s) {
|
|
|
|
Produce::inv_primitive(I, INDIRECT1V_BIP);
|
|
|
|
Produce::down(I);
|
|
|
|
Produce::val_symbol(I, K_value, callback_s);
|
|
|
|
Produce::val_symbol(I, K_value, rel_s);
|
|
|
|
Produce::up(I);
|
|
|
|
}
|
2021-05-01 13:56:10 +03:00
|
|
|
}
|
2021-11-15 01:40:33 +02:00
|
|
|
Synoptic::end_function(I, step, iname);
|
2021-05-01 13:56:10 +03:00
|
|
|
|
2021-05-05 14:24:08 +03:00
|
|
|
@<Define RPROPERTY function@> =
|
2022-01-16 01:49:25 +02:00
|
|
|
inter_name *iname = HierarchyLocations::iname(I, RPROPERTY_HL);
|
2021-05-05 14:24:08 +03:00
|
|
|
Synoptic::begin_function(I, iname);
|
|
|
|
inter_symbol *obj_s = Synoptic::local(I, I"obj", NULL);
|
|
|
|
inter_symbol *cl_s = Synoptic::local(I, I"cl", NULL);
|
|
|
|
inter_symbol *pr_s = Synoptic::local(I, I"pr", NULL);
|
2021-05-01 13:56:10 +03:00
|
|
|
Produce::inv_primitive(I, IF_BIP);
|
|
|
|
Produce::down(I);
|
|
|
|
Produce::inv_primitive(I, OFCLASS_BIP);
|
|
|
|
Produce::down(I);
|
|
|
|
Produce::val_symbol(I, K_value, obj_s);
|
|
|
|
Produce::val_symbol(I, K_value, cl_s);
|
|
|
|
Produce::up(I);
|
|
|
|
Produce::code(I);
|
|
|
|
Produce::down(I);
|
|
|
|
Produce::inv_primitive(I, RETURN_BIP);
|
|
|
|
Produce::down(I);
|
|
|
|
Produce::inv_primitive(I, PROPERTYVALUE_BIP);
|
|
|
|
Produce::down(I);
|
2022-01-07 01:10:15 +02:00
|
|
|
inter_symbol *OBJECT_TY_s =
|
2022-01-21 23:46:41 +02:00
|
|
|
IdentifierFinders::find(I, I"OBJECT_TY",
|
|
|
|
IdentifierFinders::common_names_only());
|
2021-10-18 00:55:41 +03:00
|
|
|
Produce::val_symbol(I, K_value, OBJECT_TY_s);
|
2021-05-01 13:56:10 +03:00
|
|
|
Produce::val_symbol(I, K_value, obj_s);
|
|
|
|
Produce::val_symbol(I, K_value, pr_s);
|
|
|
|
Produce::up(I);
|
|
|
|
Produce::up(I);
|
|
|
|
Produce::up(I);
|
|
|
|
Produce::up(I);
|
|
|
|
Produce::inv_primitive(I, RETURN_BIP);
|
|
|
|
Produce::down(I);
|
2022-02-25 01:53:40 +02:00
|
|
|
Produce::val(I, K_value, InterValuePairs::number(0));
|
2021-05-01 13:56:10 +03:00
|
|
|
Produce::up(I);
|
2021-11-15 01:40:33 +02:00
|
|
|
Synoptic::end_function(I, step, iname);
|