1
0
Fork 0
mirror of https://github.com/ganelson/inform.git synced 2024-06-28 21:14:57 +03:00

Added one kind-value pair function

This commit is contained in:
Graham Nelson 2024-04-22 09:37:42 +01:00
parent 61534b38cc
commit 623fbb916e
4 changed files with 49 additions and 26 deletions

View file

@ -64,7 +64,7 @@ MathJax = {
<ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../extensions.html">Kits</a></li><li><a href="index.html">BasicInformKit</a></li><li><b>Kinds Template</b></li></ul></div>
<p class="purpose">An API for handling values within the Inform 7 system of kinds.</p>
<ul class="toc"><li><a href="S-knd.html#SP1">&#167;1. Strong and weak IDs</a></li><li><a href="S-knd.html#SP3">&#167;3. The kind metadata array</a></li><li><a href="S-knd.html#SP9">&#167;9. Non-standard enumerations</a></li><li><a href="S-knd.html#SP10">&#167;10. Kind-value pairs</a></li><li><a href="S-knd.html#SP13">&#167;13. The Pointer Value API</a></li></ul><hr class="tocbar">
<ul class="toc"><li><a href="S-knd.html#SP1">&#167;1. Strong and weak IDs</a></li><li><a href="S-knd.html#SP3">&#167;3. The kind metadata array</a></li><li><a href="S-knd.html#SP9">&#167;9. Non-standard enumerations</a></li><li><a href="S-knd.html#SP10">&#167;10. Kind-value pairs</a></li><li><a href="S-knd.html#SP14">&#167;14. The Pointer Value API</a></li></ul><hr class="tocbar">
<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Strong and weak IDs. </b>Every kind has both a weak ID, like <span class="extract"><span class="extract-syntax">LIST_OF_TY</span></span>, 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 <span class="extract"><span class="extract-syntax">K</spa
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">say_fn</span><span class="plain-syntax">) </span><span class="identifier-syntax">say_fn</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">); </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="identifier-syntax">value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>Given a value of any kind, assign it a hash code which fits in a single
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b>And here is a general comparison.
</p>
<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">CompareKindValuePairs</span><span class="plain-syntax"> </span><span class="identifier-syntax">k1</span><span class="plain-syntax"> </span><span class="identifier-syntax">v1</span><span class="plain-syntax"> </span><span class="identifier-syntax">k2</span><span class="plain-syntax"> </span><span class="identifier-syntax">v2</span>
<span class="plain-syntax"> </span><span class="identifier-syntax">cmp_fn</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">k1</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">k2</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">k1</span><span class="plain-syntax">-</span><span class="identifier-syntax">k2</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="identifier-syntax">cmp_fn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ReadKindMetadata</span><span class="plain-syntax">(</span><span class="identifier-syntax">k1</span><span class="plain-syntax">, </span><span class="identifier-syntax">COMPARE_FN_KMF</span><span class="plain-syntax">);</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">cmp_fn</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">cmp_fn</span><span class="plain-syntax">(</span><span class="identifier-syntax">v1</span><span class="plain-syntax">, </span><span class="identifier-syntax">v2</span><span class="plain-syntax">);</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">v1</span><span class="plain-syntax">-</span><span class="identifier-syntax">v2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. </b>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.
</p>
@ -284,7 +296,7 @@ different hash codes despite being equal.
<span class="plain-syntax"> </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. </b>Some values can be written to external files and shared with other projects:
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. </b>Some values can be written to external files and shared with other projects:
others cannot. The following routines abstract that.
</p>
@ -325,7 +337,7 @@ whether it was able to write the data.
<span class="plain-syntax"> </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. The Pointer Value API. </b>This sits on top of the BlkValue API, but whereas the latter can be used for
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. The Pointer Value API. </b>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.
</p>

View file

@ -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

View file

@ -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

View file

@ -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.