Skip to content

Commit

Permalink
Unify phony assignment into assignment
Browse files Browse the repository at this point in the history
But now we have an "updating assignment" for the original concept
of an assignment
  • Loading branch information
dneto0 committed Oct 6, 2021
1 parent 0ec0077 commit a1603b5
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions wgsl/index.bs
Expand Up @@ -4829,19 +4829,29 @@ compound_statement

## Assignment Statement ## {#assignment}

An <dfn noexport dfn-for="statement">assignment</dfn> statement replaces the contents of a variable,
or a portion of a variable, with a new value.
An <dfn noexport dfn-for="statement">assignment</dfn> evaluates an expression,
and optionally stores it in memory (thus updating the contents of a variable).

The
expression to the left of the equals token is the <dfn noexport>left-hand side</dfn>,
<pre class='def'>
assignment_statement
: (unary_expression | UNDERSCORE) EQUAL short_circuit_or_expression
</pre>


The text to the left of the equals token is the <dfn noexport>left-hand side</dfn>,
and the
expression to the right of the equals token is the <dfn noexport>right-hand side</dfn>.

### Updating Assignment ### {#updating-assignment-section}

When the [=left-hand side=] of an assignment is an expression, the assignment is an <dfn noexport>updating assignment</dfn>:
The value of the right-hand side is written to the memory referenced by the left-hand side.

<table class='data'>
<thead>
<tr><th style="width:40%">Precondition<th>Statement<th>Description
</thead>
<tr algorithm="assignment">
<tr algorithm="updating assignment">
<td>|r|: ref<|SC|,|T|,|A|>,<br>
|A| is [=access/write=] or [=access/read_write=]<br>
|e|: |T|,<br>
Expand All @@ -4858,8 +4868,8 @@ expression to the right of the equals token is the <dfn noexport>right-hand side
(OpStore)
</table>

In the simplest case, the left hand side of the assignment statement is the
name of a variable. See [[#forming-references-and-pointers]] for other cases.
In the simplest case, the left hand side is the name of a variable.
See [[#forming-references-and-pointers]] for other cases.

<div class='example wgsl' heading='Assignments'>
<xmp highlight='rust'>
Expand Down Expand Up @@ -4888,18 +4898,11 @@ name of a variable. See [[#forming-references-and-pointers]] for other cases.
</xmp>
</div>

<pre class='def'>
assignment_statement
: unary_expression EQUAL short_circuit_or_expression
If unary_expression is a variable, this maps to OpStore to the variable.
Otherwise, unary expression is a pointer expression in an Assigning (L-value) context
which maps to OpAccessChain followed by OpStore
</pre>
### Phony Assignment ### {#phony-assignment-section}

## Phony-Assignment Statement ## {#phony-assignment-statement}

A <dfn dfn-for="statement" noexport>phony-assignment</dfn> statement evaluates an expression,
and does nothing with the resulting value.
When the [=left-hand side=] of an assignment is an underscore token,
the assignment is an <dfn noexport>phony assignment</dfn>:
The right-hand side is evaluated, and then ignored.

<table class='data'>
<thead>
Expand All @@ -4918,7 +4921,8 @@ and does nothing with the resulting value.
A phony-assignment is useful for:
* Calling a function that returns a value, but clearly expressing that the resulting value
is not needed.
* Establishing a particular variable as part of the [=resource interface of a shader|shader's resource interface=].
* [=statically accessed|Statically accessing=] a variable, thus establishing it as a part of
the [=resource interface of a shader|shader's resource interface=].

Note: A variable's store type may not be constructible, e.g. it contains an atomic type, or a runtime-sized array.
In these cases, use a pointer to the variable's contents instead.
Expand Down Expand Up @@ -4963,12 +4967,6 @@ A phony-assignment is useful for:
</xmp>
</div>

<pre class='def'>
phony_assignment_statement
: UNDERSCORE EQUAL short_circuit_or_expression
</pre>


## Control flow TODO ## {#control-flow}

### Sequence TODO ### {#sequence-statement}
Expand Down Expand Up @@ -5162,9 +5160,9 @@ for_statement
: FOR PAREN_LEFT for_header PAREN_RIGHT compound_statement

for_header
: (variable_statement | assignment_statement | phony_assignment_statement | func_call_statement)? SEMICOLON
: (variable_statement | assignment_statement | func_call_statement)? SEMICOLON
short_circuit_or_expression? SEMICOLON
(assignment_statement | phony_assignment_statement | func_call_statement)?
(assignment_statement | func_call_statement)?
</pre>

The <dfn dfn-for="statement">for</dfn> statement takes the form
Expand Down Expand Up @@ -5453,7 +5451,6 @@ statement
| continue_statement SEMICOLON
| DISCARD SEMICOLON
| assignment_statement SEMICOLON
| phony_assignment_statement SEMICOLON
| compound_statement
</pre>

Expand Down

0 comments on commit a1603b5

Please sign in to comment.