To compile the main/synoptic/kinds submodule.
§1. Our inventory inv already contains a list inv->kind_nodes of all packages in the tree with type _kind; here is one for each base kind. Similarly for the list inv->derived_kind_nodes.
void SynopticKinds::compile(inter_tree *I, pipeline_step *step, tree_inventory *inv) { if (InterNodeList::array_len(inv->kind_nodes) > 0) Assign unique strong ID numbers1.1; if (InterNodeList::array_len(inv->derived_kind_nodes) > 0) InterNodeList::array_sort(inv->derived_kind_nodes, MakeSynopticModuleStage::module_order); Define BASE_KIND_HWM1.2; Define KINDMETADATA array1.3; Define DEFAULTVALUEFINDER function1.4; Define I7_KIND_NAME function1.5; Define SHOWMEKINDDETAILS function1.6; Define RUCKSACK_CLASS constant1.7; Define KINDHIERARCHY array1.8; }
§1.1. Each base kind package contains a numeric constant with the symbol name strong_id. We want to ensure that these ID numbers are contiguous from 2 and never duplicated, so we change the values of these constants accordingly. (From 2 because we want to avoid 0, and we want 1 always to mean "kind unknown".)
Note that derived kinds are not enumerated in this way; their strong ID constants are addresses of small arrays.
Assign unique strong ID numbers1.1 =
InterNodeList::array_sort(inv->kind_nodes, MakeSynopticModuleStage::module_order); for (int i=0; i<InterNodeList::array_len(inv->kind_nodes); i++) { inter_package *pack = PackageInstruction::at_this_head(inv->kind_nodes->list[i].node); inter_symbol *id_s = Metadata::optional_symbol(pack, I"^strong_id"); if (id_s) InterSymbol::set_int(id_s, i+2); }
- This code is used in §1.
§1.2. The "high water mark" of strong IDs for base kinds. Any strong ID this high or higher is therefore that of a derived kind.
Define BASE_KIND_HWM1.2 =
int hwm = InterNodeList::array_len(inv->kind_nodes) + 2; inter_name *iname = HierarchyLocations::iname(I, BASE_KIND_HWM_HL); Produce::numeric_constant(I, iname, K_value, (inter_ti) hwm);
- This code is used in §1.
§1.3. Define KINDMETADATA array1.3 =
inter_name *iname = HierarchyLocations::iname(I, KINDMETADATA_HL); Synoptic::begin_array(I, step, iname); inter_ti pos = (inter_ti) InterNodeList::array_len(inv->kind_nodes) + 2; for (int dummy_entries = 1; dummy_entries <= 2; dummy_entries++) { Synoptic::numeric_entry(0); } for (int i=0; i<InterNodeList::array_len(inv->kind_nodes); i++) { inter_package *pack = PackageInstruction::at_this_head(inv->kind_nodes->list[i].node); Synoptic::numeric_entry(pos); pos += 7; if (Metadata::read_optional_numeric(pack, I"^has_block_values")) pos += 12; } for (int i=0; i<InterNodeList::array_len(inv->kind_nodes); i++) { inter_package *pack = PackageInstruction::at_this_head(inv->kind_nodes->list[i].node); ID field1.3.1; Say function field1.3.2; Compare function field1.3.3; Make default function field1.3.4; Enumeration array field1.3.5; Domain size field1.3.6; Conformance field1.3.7; if (Metadata::read_optional_numeric(pack, I"^has_block_values")) { Create function field1.3.8; Cast function field1.3.9; Copy function field1.3.10; Copy short block function field1.3.11; Quick-copy function field1.3.12; Destroy function field1.3.13; Make-mutable function field1.3.14; Hash function field1.3.15; Short block size field1.3.16; Long block size function field1.3.17; Serialise function field1.3.18; Unserialise function field1.3.19; } } Synoptic::end_array(I);
- This code is used in §1.
inter_symbol *id_s = Metadata::required_symbol(pack, I"^strong_id"); Synoptic::symbol_entry(id_s);
- This code is used in §1.3.
§1.3.2. Say function field1.3.2 =
if ((Metadata::optional_symbol(pack, I"^print_fn")) && (Metadata::read_optional_numeric(pack, I"^is_subkind_of_object") == FALSE)) { inter_symbol *print_fn_s = Metadata::required_symbol(pack, I"^print_fn"); Synoptic::symbol_entry(print_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.3. Compare function field1.3.3 =
if (Metadata::optional_symbol(pack, I"^cmp_fn")) { inter_symbol *cmp_fn_s = Metadata::required_symbol(pack, I"^cmp_fn"); Synoptic::symbol_entry(cmp_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.4. Make default function field1.3.4 =
if (Metadata::optional_symbol(pack, I"^mkdef_fn")) { inter_symbol *mkdef_fn_s = Metadata::required_symbol(pack, I"^mkdef_fn"); Synoptic::symbol_entry(mkdef_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.5. Enumeration array field1.3.5 =
inter_symbol *ea_s = Metadata::optional_symbol(pack, I"^enumeration_array"); if (ea_s) { Synoptic::symbol_entry(ea_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.6. Domain size field1.3.6 =
if (Metadata::read_optional_numeric(pack, I"^domain_size")) { inter_ti domain_size = Metadata::read_numeric(pack, I"^domain_size"); Synoptic::numeric_entry(domain_size); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.7. Conformance field1.3.7 =
if (Metadata::read_optional_numeric(pack, I"^has_block_values")) { Synoptic::numeric_entry(1); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.8. Create function field1.3.8 =
if (Metadata::optional_symbol(pack, I"^create_fn")) { inter_symbol *create_fn_s = Metadata::required_symbol(pack, I"^create_fn"); Synoptic::symbol_entry(create_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.9. Cast function field1.3.9 =
if (Metadata::optional_symbol(pack, I"^cast_fn")) { inter_symbol *cast_fn_s = Metadata::required_symbol(pack, I"^cast_fn"); Synoptic::symbol_entry(cast_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.10. Copy function field1.3.10 =
if (Metadata::optional_symbol(pack, I"^copy_fn")) { inter_symbol *copy_fn_s = Metadata::required_symbol(pack, I"^copy_fn"); Synoptic::symbol_entry(copy_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.11. Copy short block function field1.3.11 =
if (Metadata::optional_symbol(pack, I"^copy_short_block_fn")) { inter_symbol *copy_fn_s = Metadata::required_symbol(pack, I"^copy_short_block_fn"); Synoptic::symbol_entry(copy_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.12. Quick-copy function field1.3.12 =
if (Metadata::optional_symbol(pack, I"^quick_copy_fn")) { inter_symbol *quick_copy_fn_s = Metadata::required_symbol(pack, I"^quick_copy_fn"); Synoptic::symbol_entry(quick_copy_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.13. Destroy function field1.3.13 =
if (Metadata::optional_symbol(pack, I"^destroy_fn")) { inter_symbol *destroy_fn_s = Metadata::required_symbol(pack, I"^destroy_fn"); Synoptic::symbol_entry(destroy_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.14. Make-mutable function field1.3.14 =
if (Metadata::optional_symbol(pack, I"^make_mutable_fn")) { inter_symbol *make_mutable_fn_s = Metadata::required_symbol(pack, I"^make_mutable_fn"); Synoptic::symbol_entry(make_mutable_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.15. Hash function field1.3.15 =
if (Metadata::optional_symbol(pack, I"^hash_fn")) { inter_symbol *hash_fn_s = Metadata::required_symbol(pack, I"^hash_fn"); Synoptic::symbol_entry(hash_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.16. Short block size field1.3.16 =
inter_ti SB = 1; if (Metadata::read_optional_numeric(pack, I"^short_block_size") > 0) SB = Metadata::read_numeric(pack, I"^short_block_size"); Synoptic::numeric_entry(SB);
- This code is used in §1.3.
§1.3.17. Long block size function field1.3.17 =
if (Metadata::optional_symbol(pack, I"^long_block_size_fn")) { inter_symbol *long_block_size_fn_s = Metadata::required_symbol(pack, I"^long_block_size_fn"); Synoptic::symbol_entry(long_block_size_fn_s); } else { if (Metadata::read_optional_numeric(pack, I"^long_block_size") > 0) { inter_ti LB = Metadata::read_numeric(pack, I"^long_block_size"); Synoptic::numeric_entry(LB); } else { Synoptic::numeric_entry(0); } }
- This code is used in §1.3.
§1.3.18. Serialise function field1.3.18 =
if (Metadata::optional_symbol(pack, I"^serialise_fn")) { inter_symbol *serialise_fn_s = Metadata::required_symbol(pack, I"^serialise_fn"); Synoptic::symbol_entry(serialise_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.3.19. Unserialise function field1.3.19 =
if (Metadata::optional_symbol(pack, I"^unserialise_fn")) { inter_symbol *unserialise_fn_s = Metadata::required_symbol(pack, I"^unserialise_fn"); Synoptic::symbol_entry(unserialise_fn_s); } else { Synoptic::numeric_entry(0); }
- This code is used in §1.3.
§1.4. Define DEFAULTVALUEFINDER function1.4 =
inter_name *iname = HierarchyLocations::iname(I, DEFAULTVALUEFINDER_HL); Synoptic::begin_function(I, iname); inter_symbol *k_s = Synoptic::local(I, I"k", NULL); for (int i=0; i<InterNodeList::array_len(inv->derived_kind_nodes); i++) { inter_package *pack = PackageInstruction::at_this_head(inv->derived_kind_nodes->list[i].node); if (Metadata::read_numeric(pack, I"^default_value_needed")) { inter_symbol *rks_s = Synoptic::get_symbol(pack, I"strong_id"); inter_symbol *dv_s = Synoptic::get_symbol(pack, I"default_value"); Produce::inv_primitive(I, IF_BIP); Produce::down(I); Produce::inv_primitive(I, EQ_BIP); Produce::down(I); Produce::val_symbol(I, K_value, k_s); Produce::val_symbol(I, K_value, rks_s); Produce::up(I); Produce::code(I); Produce::down(I); Produce::inv_primitive(I, RETURN_BIP); Produce::down(I); Produce::val_symbol(I, K_value, dv_s); Produce::up(I); Produce::up(I); Produce::up(I); } } Produce::rfalse(I); Synoptic::end_function(I, step, iname);
- This code is used in §1.
§1.5. Define I7_KIND_NAME function1.5 =
inter_name *iname = HierarchyLocations::iname(I, I7_KIND_NAME_HL); Synoptic::begin_function(I, iname); inter_symbol *k_s = Synoptic::local(I, I"k", NULL); for (int i=0; i<InterNodeList::array_len(inv->kind_nodes); i++) { inter_package *pack = PackageInstruction::at_this_head(inv->kind_nodes->list[i].node); inter_symbol *class_s = Metadata::optional_symbol(pack, I"^object_class"); if (class_s) { text_stream *pn = Metadata::required_textual(pack, I"^printed_name"); Produce::inv_primitive(I, IF_BIP); Produce::down(I); Produce::inv_primitive(I, EQ_BIP); Produce::down(I); Produce::val_symbol(I, K_value, k_s); Produce::val_symbol(I, K_value, class_s); Produce::up(I); Produce::code(I); Produce::down(I); Produce::inv_primitive(I, PRINT_BIP); Produce::down(I); Produce::val_text(I, pn); Produce::up(I); Produce::up(I); Produce::up(I); } } Synoptic::end_function(I, step, iname);
- This code is used in §1.
§1.6. Define SHOWMEKINDDETAILS function1.6 =
inter_name *iname = HierarchyLocations::iname(I, SHOWMEKINDDETAILS_HL); Synoptic::begin_function(I, iname); inter_symbol *which_s = Synoptic::local(I, I"which", NULL); inter_symbol *na_s = Synoptic::local(I, I"na", NULL); inter_symbol *t_0_s = Synoptic::local(I, I"t_0", NULL); for (int i=0; i<InterNodeList::array_len(inv->kind_nodes); i++) { inter_package *pack = PackageInstruction::at_this_head(inv->kind_nodes->list[i].node); if (Metadata::read_optional_numeric(pack, I"^is_object")) { inter_symbol *showme_s = Metadata::optional_symbol(pack, I"^showme_fn"); if (showme_s) { Produce::inv_primitive(I, STORE_BIP); Produce::down(I); Produce::ref_symbol(I, K_value, na_s); Produce::inv_call_symbol(I, showme_s); Produce::down(I); Produce::val_symbol(I, K_value, which_s); Produce::val_symbol(I, K_value, na_s); Produce::val_symbol(I, K_value, t_0_s); Produce::up(I); Produce::up(I); } } } Produce::inv_primitive(I, RETURN_BIP); Produce::down(I); Produce::val_symbol(I, K_value, na_s); Produce::up(I); Synoptic::end_function(I, step, iname);
- This code is used in §1.
§1.7. This goes right back to a curious feature of Inform 1, in 1993. To enable the use of player's holdalls, we must declare a constant RUCKSACK_CLASS to tell some code in WorldModelKit to use possessions with this Inter class as the rucksack pro tem. This is all a bit of a hack, and isn't really fully general: only the player has the benefit of a "player's holdall" (hence the name), with other actors oblivious.
Define RUCKSACK_CLASS constant1.7 =
inter_name *iname = HierarchyLocations::iname(I, RUCKSACK_CLASS_HL); int found = FALSE; for (int i=0; i<InterNodeList::array_len(inv->kind_nodes); i++) { inter_package *pack = PackageInstruction::at_this_head(inv->kind_nodes->list[i].node); if (Metadata::read_optional_numeric(pack, I"^rucksack_class")) { inter_symbol *value_s = Metadata::required_symbol(pack, I"^object_class"); Produce::symbol_constant(I, iname, K_value, value_s); found = TRUE; break; } } if (found == FALSE) Produce::numeric_constant(I, iname, K_value, 0);
- This code is used in §1.
§1.8. The kind inheritance tree is represented by an array providing metadata on the kinds of object: there are just two words per kind — the class, then the instance count for its own kind. For instance, "door" is usually kind number 4, so it occupies record 4 in this array — words 8 and 9. Word 8 will be K4_door, and word 9 will be the number 2, meaning kind number 2, "thing". This tells us that a door is a kind of thing.
Define KINDHIERARCHY array1.8 =
linked_list *L = NEW_LINKED_LIST(inter_symbol); for (int i=0; i<InterNodeList::array_len(inv->kind_nodes); i++) { inter_package *pack = PackageInstruction::at_this_head(inv->kind_nodes->list[i].node); if (Metadata::read_optional_numeric(pack, I"^is_subkind_of_object")) { inter_symbol *kind_name = Metadata::required_symbol(pack, I"^object_class"); ADD_TO_LINKED_LIST(kind_name, inter_symbol, L); } } linked_list *ordered_L = NEW_LINKED_LIST(inter_symbol); CodeGen::sort_symbol_list(ordered_L, L, CodeGen::in_source_md_order); int i = 1; inter_symbol *kind_name; LOOP_OVER_LINKED_LIST(kind_name, inter_symbol, ordered_L) SymbolAnnotation::set_i(kind_name, OBJECT_KIND_COUNTER_IANN, (inter_ti) i++); inter_name *iname = HierarchyLocations::iname(I, KINDHIERARCHY_HL); Synoptic::begin_array(I, step, iname); if (LinkedLists::len(L) > 0) { Synoptic::symbol_entry(RunningPipelines::get_symbol(step, object_kind_RPSYM)); Synoptic::numeric_entry(0); inter_symbol *kind_name; LOOP_OVER_LINKED_LIST(kind_name, inter_symbol, ordered_L) { Synoptic::symbol_entry(kind_name); inter_symbol *super_name = TypenameInstruction::super(kind_name); if ((super_name) && (super_name != RunningPipelines::get_symbol(step, object_kind_RPSYM))) { Synoptic::numeric_entry(SynopticKinds::kind_of_object_count(step, super_name)); } else { Synoptic::numeric_entry(0); } } } else { Synoptic::numeric_entry(0); Synoptic::numeric_entry(0); } Synoptic::end_array(I);
- This code is used in §1.
inter_ti SynopticKinds::kind_of_object_count(pipeline_step *step, inter_symbol *kind_name) { if ((kind_name == NULL) || (kind_name == RunningPipelines::get_symbol(step, object_kind_RPSYM))) return 0; int N = SymbolAnnotation::get_i(kind_name, OBJECT_KIND_COUNTER_IANN); if (N >= 0) return (inter_ti) N; return 0; }