From 623fbb916ee2c915bc4f6d5861b20fb38135a2bb Mon Sep 17 00:00:00 2001 From: Graham Nelson Date: Mon, 22 Apr 2024 09:37:42 +0100 Subject: [PATCH] Added one kind-value pair function --- docs/BasicInformKit/S-knd.html | 20 +++++++++++--- inform7/Figures/memory-diagnostics.txt | 26 +++++++++---------- inform7/Figures/timings-diagnostics.txt | 18 ++++++------- .../Inter/BasicInformKit/Sections/Kinds.i6t | 11 ++++++++ 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/docs/BasicInformKit/S-knd.html b/docs/BasicInformKit/S-knd.html index 478522b18..0c88ced57 100644 --- a/docs/BasicInformKit/S-knd.html +++ b/docs/BasicInformKit/S-knd.html @@ -64,7 +64,7 @@ MathJax = {

An API for handling values within the Inform 7 system of kinds.

-
+

§1. Strong and weak IDs. Every kind has both a weak ID, like LIST_OF_TY, and a strong ID, which is a pointer to a small data structure: for instance, a pointer to the three @@ -253,7 +253,19 @@ it belongs to the kind K if (say_fn) say_fn(value); else print value; ]; -

§11. Given a value of any kind, assign it a hash code which fits in a single +

§11. And here is a general comparison. +

+ +
+[ CompareKindValuePairs k1 v1 k2 v2
+    cmp_fn;
+    if (k1 ~= k2) return k1-k2;
+    cmp_fn = ReadKindMetadata(k1, COMPARE_FN_KMF);
+    if (cmp_fn) return cmp_fn(v1, v2);
+    return v1-v2;
+];
+
+

§12. Given a value of any kind, assign it a hash code which fits in a single virtual machine word, maximizing the chances that two different values will have different hash codes.

@@ -284,7 +296,7 @@ different hash codes despite being equal. return value; ]; -

§12. Some values can be written to external files and shared with other projects: +

§13. Some values can be written to external files and shared with other projects: others cannot. The following routines abstract that.

@@ -325,7 +337,7 @@ whether it was able to write the data. rfalse; ]; -

§13. The Pointer Value API. This sits on top of the BlkValue API, but whereas the latter can be used for +

§14. The Pointer Value API. This sits on top of the BlkValue API, but whereas the latter can be used for many potential purposes, the PV functions are strictly for dealing with values of kinds conforming to POINTER_VALUE_TY.

diff --git a/inform7/Figures/memory-diagnostics.txt b/inform7/Figures/memory-diagnostics.txt index 67ba927de..e7e679ee4 100644 --- a/inform7/Figures/memory-diagnostics.txt +++ b/inform7/Figures/memory-diagnostics.txt @@ -1,10 +1,10 @@ -Total memory consumption was 140053K = 137 MB +Total memory consumption was 140059K = 137 MB - ---- was used for 2135436 objects, in 376005 frames in 0 x 800K = 0K = 0 MB: + ---- was used for 2135443 objects, in 376012 frames in 0 x 800K = 0K = 0 MB: 30.1% inter_tree_node_array 60 x 8192 = 491520 objects, 43255680 bytes 19.4% text_stream_array 4958 x 100 = 495800 objects, 27923456 bytes - 17.9% linked_list 45907 objects, 25707920 bytes + 17.9% linked_list 45908 objects, 25708480 bytes 10.0% inter_symbol_array 135 x 1024 = 138240 objects, 14381280 bytes 9.6% inter_error_stash_array 106 x 1024 = 108544 objects, 13897024 bytes 7.4% parse_node 133914 objects, 10713120 bytes @@ -19,10 +19,10 @@ Total memory consumption was 140053K = 137 MB 1.3% package_request 21375 objects, 1881000 bytes 1.2% vocabulary_entry_array 164 x 100 = 16400 objects, 1842048 bytes 1.1% dict_entry_array 503 x 100 = 50300 objects, 1625696 bytes - 1.0% inter_symbols_table 26964 objects, 1509984 bytes + 1.0% inter_symbols_table 26966 objects, 1510096 bytes 1.0% match_trie_array 11 x 1000 = 11000 objects, 1496352 bytes 1.0% i6_schema_array 24 x 100 = 2400 objects, 1440768 bytes - 0.9% inter_package 26964 objects, 1294272 bytes + 0.9% inter_package 26966 objects, 1294368 bytes 0.7% map_data 682 objects, 1145760 bytes 0.7% id_body 981 objects, 1122264 bytes 0.7% adjective_meaning 210 objects, 1039920 bytes @@ -36,13 +36,13 @@ Total memory consumption was 140053K = 137 MB 0.3% local_variable_array 49 x 100 = 4900 objects, 471968 bytes 0.2% verb_usage 1148 objects, 394912 bytes 0.2% rule 478 objects, 374752 bytes - 0.2% dictionary 7774 objects, 373152 bytes + 0.2% dictionary 7775 objects, 373200 bytes 0.2% verb_form 388 objects, 350752 bytes 0.2% noun 2396 objects, 287520 bytes 0.1% compilation_subtask 3392 objects, 271360 bytes 0.1% inference_subject 677 objects, 265384 bytes 0.1% inter_annotation_array 2 x 8192 = 16384 objects, 262208 bytes - 0.1% vanilla_function 3834 objects, 245376 bytes + 0.1% vanilla_function 3835 objects, 245440 bytes 0.1% binary_predicate 334 objects, 176352 bytes 0.1% hierarchy_location 1222 objects, 175968 bytes 0.1% linguistic_stock_item 3341 objects, 160368 bytes @@ -262,18 +262,18 @@ Total memory consumption was 140053K = 137 MB ---- loop_over_scope 1 object, 40 bytes ---- i6_memory_setting 1 object, 32 bytes -99.9% was used for memory not allocated for objects: +100.0% was used for memory not allocated for objects: - 62.4% text stream storage 89601664 bytes in 515979 claims - 3.8% dictionary storage 5512256 bytes in 7774 claims + 62.4% text stream storage 89606536 bytes in 516009 claims + 3.8% dictionary storage 5512768 bytes in 7775 claims ---- sorting 2624 bytes in 531 claims 5.0% source text 7200000 bytes in 3 claims 7.5% source text details 10800000 bytes in 2 claims 0.1% documentation fragments 262144 bytes in 1 claim ---- linguistic stock array 81920 bytes in 2 claims ---- small word set array 105600 bytes in 22 claims - 3.1% inter symbols storage 4585248 bytes in 28332 claims - 11.6% inter bytecode storage 16759596 bytes in 15 claims + 3.1% inter symbols storage 4585504 bytes in 28334 claims + 11.6% inter bytecode storage 16759620 bytes in 15 claims 4.3% inter links storage 6222976 bytes in 11 claims 0.1% inter tree location list storage 191232 bytes in 32 claims 1.2% instance-of-kind counting 1758276 bytes in 1 claim @@ -282,5 +282,5 @@ Total memory consumption was 140053K = 137 MB ---- code generation workspace for objects 3536 bytes in 19 claims 0.2% emitter array storage 290048 bytes in 2074 claims --136.-7% was overhead - -196069928 bytes = -191474K = -186 MB +-136.-7% was overhead - -196070808 bytes = -191475K = -186 MB diff --git a/inform7/Figures/timings-diagnostics.txt b/inform7/Figures/timings-diagnostics.txt index c53f9eee8..c033a3617 100644 --- a/inform7/Figures/timings-diagnostics.txt +++ b/inform7/Figures/timings-diagnostics.txt @@ -1,8 +1,8 @@ 100.0% in inform7 run - 67.7% in compilation to Inter - 46.3% in //Sequence::undertake_queued_tasks// + 67.5% in compilation to Inter + 45.9% in //Sequence::undertake_queued_tasks// 4.2% in //MajorNodes::pre_pass// - 3.5% in //MajorNodes::pass_1// + 3.4% in //MajorNodes::pass_1// 1.9% in //ImperativeDefinitions::assess_all// 1.5% in //RTKindConstructors::compile// 1.5% in //RTPhrasebook::compile_entries// @@ -13,11 +13,11 @@ 0.3% in //Sequence::undertake_queued_tasks// 0.3% in //Sequence::undertake_queued_tasks// 0.3% in //World::stage_V// - 5.1% not specifically accounted for - 27.6% in running Inter pipeline - 8.9% in step 14/15: generate inform6 -> auto.inf - 7.0% in step 5/15: load-binary-kits - 5.8% in step 6/15: make-synoptic-module + 5.4% not specifically accounted for + 27.4% in running Inter pipeline + 8.8% in step 14/15: generate inform6 -> auto.inf + 6.9% in step 5/15: load-binary-kits + 5.7% in step 6/15: make-synoptic-module 1.9% in step 9/15: make-identifiers-unique 0.3% in step 12/15: eliminate-redundant-operations 0.3% in step 4/15: compile-splats @@ -25,4 +25,4 @@ 0.3% in step 8/15: detect-indirect-calls 2.4% not specifically accounted for 3.8% in supervisor - 0.8% not specifically accounted for + 1.2% not specifically accounted for diff --git a/inform7/Internal/Inter/BasicInformKit/Sections/Kinds.i6t b/inform7/Internal/Inter/BasicInformKit/Sections/Kinds.i6t index d97672ec2..3cb0e84ab 100644 --- a/inform7/Internal/Inter/BasicInformKit/Sections/Kinds.i6t +++ b/inform7/Internal/Inter/BasicInformKit/Sections/Kinds.i6t @@ -179,6 +179,17 @@ it belongs to the kind |K|. if (say_fn) say_fn(value); else print value; ]; +@ And here is a general comparison. + += +[ CompareKindValuePairs k1 v1 k2 v2 + cmp_fn; + if (k1 ~= k2) return k1-k2; + cmp_fn = ReadKindMetadata(k1, COMPARE_FN_KMF); + if (cmp_fn) return cmp_fn(v1, v2); + return v1-v2; +]; + @ Given a value of any kind, assign it a hash code which fits in a single virtual machine word, maximizing the chances that two different values will have different hash codes.