Skip to content

Commit

Permalink
Fix for Jira bug I7-2304
Browse files Browse the repository at this point in the history
  • Loading branch information
ganelson committed Apr 22, 2023
1 parent e4eaf4a commit 1c18007
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Inform 7

[Version](notes/versioning.md): 10.2.0-beta+6W34 'Krypton' (21 April 2023)
[Version](notes/versioning.md): 10.2.0-beta+6W35 'Krypton' (22 April 2023)

## About Inform

Expand Down
4 changes: 2 additions & 2 deletions build.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Prerelease: beta
Build Date: 21 April 2023
Build Number: 6W34
Build Date: 22 April 2023
Build Number: 6W35
28 changes: 24 additions & 4 deletions docs/final-module/4-i6c2.html
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ <h1><a href="../index.html">
<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">PLUS_BIP:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" + "</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_2C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">MINUS_BIP:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" - "</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_2C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">UNARYMINUS_BIP:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"(-("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"))"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">UNARYMINUS_BIP:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="4-i6c2.html#SP6_1_1" class="named-paragraph-link"><span class="named-paragraph">Handle unary minus</span><span class="named-paragraph-number">6.1.1</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TIMES_BIP:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"*"</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_2C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">DIVIDE_BIP:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"/"</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_2C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">MODULO_BIP:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"%%"</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_2C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
Expand All @@ -396,11 +396,31 @@ <h1><a href="../index.html">
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOOKUPBYTE_BIP:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"-&gt;("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_2C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"))"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">ALTERNATIVE_BIP:</span><span class="plain-syntax"> </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" or "</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_2C</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">SEQUENTIAL_BIP:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">","</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_2C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TERNARYSEQUENTIAL_BIP:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="4-i6c2.html#SP6_1_1" class="named-paragraph-link"><span class="named-paragraph">Generate primitive for ternarysequential</span><span class="named-paragraph-number">6.1.1</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TERNARYSEQUENTIAL_BIP:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="4-i6c2.html#SP6_1_2" class="named-paragraph-link"><span class="named-paragraph">Generate primitive for ternarysequential</span><span class="named-paragraph-number">6.1.2</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">RANDOM_BIP:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"random("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-i6c2.html#SP6">&#167;6</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP6_1_1" class="paragraph-anchor"></a><b>&#167;6.1.1. </b>But the unfortunate <span class="extract"><span class="extract-syntax">!ternarysequential a b c</span></span> needs some gymnastics. It
<p class="commentary firstcommentary"><a id="SP6_1_1" class="paragraph-anchor"></a><b>&#167;6.1.1. </b>In general, Inform 6 is able to constant-fold, that is, to evaluate expressions
between constants at compile time: for example, <span class="extract"><span class="extract-syntax">5+6</span></span> will be compiled as <span class="extract"><span class="extract-syntax">11</span></span>,
not as code to add <span class="extract"><span class="extract-syntax">5</span></span> to <span class="extract"><span class="extract-syntax">6</span></span>. But in just a few contexts, notably as case values
in <span class="extract"><span class="extract-syntax">switch</span></span> statements, constants won't fold. This in particular affects unary
minus, so that <span class="extract"><span class="extract-syntax">(-(23))</span></span> is not syntactically valid as a switch case. So we
omit the brackets for applications of unary minus which are simple enough to
do so. (See Jira bug I7-2304.)
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Handle unary minus</span><span class="named-paragraph-number">6.1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Inode::get_construct_ID</span><span class="plain-syntax">(</span><span class="identifier-syntax">InterTree::first_child</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">)) == </span><span class="identifier-syntax">VAL_IST</span><span class="plain-syntax">) {</span>
<span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"-"</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">;</span>
<span class="plain-syntax"> } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"(-("</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"))"</span><span class="plain-syntax">);</span>
<span class="plain-syntax"> }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-i6c2.html#SP6_1">&#167;6.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP6_1_2" class="paragraph-anchor"></a><b>&#167;6.1.2. </b>But the unfortunate <span class="extract"><span class="extract-syntax">!ternarysequential a b c</span></span> needs some gymnastics. It
would be trivial to generate to C with the serial comma operator: <span class="extract"><span class="extract-syntax">(a, b, c)</span></span>
evaluates <span class="extract"><span class="extract-syntax">a</span></span>, then throws that away and evaluates <span class="extract"><span class="extract-syntax">b</span></span>, then throws that away
too and returns the value of <span class="extract"><span class="extract-syntax">c</span></span>.
Expand Down Expand Up @@ -428,7 +448,7 @@ <h1><a href="../index.html">
then the result.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Generate primitive for ternarysequential</span><span class="named-paragraph-number">6.1.1</span></span><span class="comment-syntax"> =</span>
<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Generate primitive for ternarysequential</span><span class="named-paragraph-number">6.1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
Expand Down
18 changes: 9 additions & 9 deletions inform7/Figures/timings-diagnostics.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
100.0% in inform7 run
70.4% in compilation to Inter
49.7% in //Sequence::undertake_queued_tasks//
70.7% in compilation to Inter
49.8% in //Sequence::undertake_queued_tasks//
4.9% in //MajorNodes::pre_pass//
3.5% in //MajorNodes::pass_1//
1.8% in //ImperativeDefinitions::assess_all//
1.6% in //RTPhrasebook::compile_entries//
1.4% in //RTKindConstructors::compile//
1.4% in //RTPhrasebook::compile_entries//
1.0% in //Sequence::lint_inter//
0.6% in //MajorNodes::pass_2//
0.6% in //Sequence::undertake_queued_tasks//
0.6% in //World::stage_V//
0.4% in //ImperativeDefinitions::compile_first_block//
0.4% in //Sequence::undertake_queued_tasks//
0.4% in //Sequence::undertake_queued_tasks//
0.2% in //CompletionModule::compile//
0.2% in //InferenceSubjects::emit_all//
0.2% in //RTKindConstructors::compile_permissions//
0.2% in //Task::make_built_in_kind_constructors//
3.1% not specifically accounted for
26.0% in running Inter pipeline
9.9% in step 14/15: generate inform6 -> auto.inf
2.9% not specifically accounted for
25.9% in running Inter pipeline
10.1% in step 14/15: generate inform6 -> auto.inf
5.7% in step 5/15: load-binary-kits
5.3% in step 6/15: make-synoptic-module
1.8% in step 9/15: make-identifiers-unique
Expand All @@ -27,6 +27,6 @@
0.4% in step 7/15: shorten-wiring
0.2% in step 11/15: eliminate-redundant-labels
0.2% in step 8/15: detect-indirect-calls
1.5% not specifically accounted for
1.2% not specifically accounted for
3.0% in supervisor
0.5% not specifically accounted for
0.3% not specifically accounted for
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"is": {
"type": "kit",
"title": "BasicInformExtrasKit",
"version": "10.2.0-beta+6W34"
"version": "10.2.0-beta+6W35"
},
"kit-details": {
"has-priority": 1
Expand Down
2 changes: 1 addition & 1 deletion inform7/Internal/Inter/BasicInformKit/kit_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"is": {
"type": "kit",
"title": "BasicInformKit",
"version": "10.2.0-beta+6W34"
"version": "10.2.0-beta+6W35"
},
"needs": [ {
"unless": {
Expand Down
2 changes: 1 addition & 1 deletion inform7/Internal/Inter/CommandParserKit/kit_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"is": {
"type": "kit",
"title": "CommandParserKit",
"version": "10.2.0-beta+6W34"
"version": "10.2.0-beta+6W35"
},
"needs": [ {
"need": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"is": {
"type": "kit",
"title": "EnglishLanguageKit",
"version": "10.2.0-beta+6W34"
"version": "10.2.0-beta+6W35"
},
"needs": [ {
"need": {
Expand Down
2 changes: 1 addition & 1 deletion inform7/Internal/Inter/WorldModelKit/kit_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"is": {
"type": "kit",
"title": "WorldModelKit",
"version": "10.2.0-beta+6W34"
"version": "10.2.0-beta+6W35"
},
"needs": [ {
"need": {
Expand Down
17 changes: 16 additions & 1 deletion inter/final-module/Chapter 4/Inform 6 Code.w
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ it corresponds directly to the |or| keyword of Inform 6, so generating it is tri
@<Basic arithmetic and logical operations@> =
case PLUS_BIP: WRITE("("); VNODE_1C; WRITE(" + "); VNODE_2C; WRITE(")"); break;
case MINUS_BIP: WRITE("("); VNODE_1C; WRITE(" - "); VNODE_2C; WRITE(")"); break;
case UNARYMINUS_BIP: WRITE("(-("); VNODE_1C; WRITE("))"); break;
case UNARYMINUS_BIP: @<Handle unary minus@>; break;
case TIMES_BIP: WRITE("("); VNODE_1C; WRITE("*"); VNODE_2C; WRITE(")"); break;
case DIVIDE_BIP: WRITE("("); VNODE_1C; WRITE("/"); VNODE_2C; WRITE(")"); break;
case MODULO_BIP: WRITE("("); VNODE_1C; WRITE("%%"); VNODE_2C; WRITE(")"); break;
Expand All @@ -298,6 +298,21 @@ it corresponds directly to the |or| keyword of Inform 6, so generating it is tri
case TERNARYSEQUENTIAL_BIP: @<Generate primitive for ternarysequential@>; break;
case RANDOM_BIP: WRITE("random("); VNODE_1C; WRITE(")"); break;

@ In general, Inform 6 is able to constant-fold, that is, to evaluate expressions
between constants at compile time: for example, |5+6| will be compiled as |11|,
not as code to add |5| to |6|. But in just a few contexts, notably as case values
in |switch| statements, constants won't fold. This in particular affects unary
minus, so that |(-(23))| is not syntactically valid as a switch case. So we
omit the brackets for applications of unary minus which are simple enough to
do so. (See Jira bug I7-2304.)

@<Handle unary minus@> =
if (Inode::get_construct_ID(InterTree::first_child(P)) == VAL_IST) {
WRITE("-"); VNODE_1C;
} else {
WRITE("(-("); VNODE_1C; WRITE("))");
}

@ But the unfortunate |!ternarysequential a b c| needs some gymnastics. It
would be trivial to generate to C with the serial comma operator: |(a, b, c)|
evaluates |a|, then throws that away and evaluates |b|, then throws that away
Expand Down

0 comments on commit 1c18007

Please sign in to comment.