This repository was archived by the owner on Nov 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
[spec/interpreter/test] Add table bulk instructions missing from bulk op proposal #35
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4fd1af5
Interpreter
rossberg 405a5fa
[spec] Add table.size/grow/fill
rossberg dd03821
[test] More tests for table instructions
rossberg 31574fb
Eps
rossberg fa45692
Reorder byte codes for slightly more consistency
rossberg 10e7345
[interpreter] Adjust segment encoding to match bulk proposal
rossberg daeaa93
Comments and tweaks to JS API
rossberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -522,6 +522,162 @@ Table Instructions | |
\end{array} | ||
|
||
|
||
.. _exec-table.size: | ||
|
||
:math:`\TABLESIZE~x` | ||
.................... | ||
|
||
1. Let :math:`F` be the :ref:`current <exec-notation-textual>` :ref:`frame <syntax-frame>`. | ||
|
||
2. Assert: due to :ref:`validation <valid-table.size>`, :math:`F.\AMODULE.\MITABLES[x]` exists. | ||
|
||
3. Let :math:`a` be the :ref:`table address <syntax-tableaddr>` :math:`F.\AMODULE.\MITABLES[x]`. | ||
|
||
4. Assert: due to :ref:`validation <valid-table.size>`, :math:`S.\STABLES[a]` exists. | ||
|
||
5. Let :math:`\X{tab}` be the :ref:`table instance <syntax-tableinst>` :math:`S.\STABLES[a]`. | ||
|
||
6. Let :math:`\X{sz}` be the length of :math:`\X{tab}.\TIELEM`. | ||
|
||
7. Push the value :math:`\I32.\CONST~\X{sz}` to the stack. | ||
|
||
.. math:: | ||
\begin{array}{l} | ||
\begin{array}{lcl@{\qquad}l} | ||
S; F; \TABLESIZE~x &\stepto& S; F; (\I32.\CONST~\X{sz}) | ||
\end{array} | ||
\\ \qquad | ||
(\iff |S.\STABLES[F.\AMODULE.\MITABLES[x]].\TIELEM| = \X{sz}) \\ | ||
\end{array} | ||
|
||
|
||
.. _exec-table.grow: | ||
|
||
:math:`\TABLEGROW~x` | ||
.................... | ||
|
||
1. Let :math:`F` be the :ref:`current <exec-notation-textual>` :ref:`frame <syntax-frame>`. | ||
|
||
2. Assert: due to :ref:`validation <valid-table.grow>`, :math:`F.\AMODULE.\MITABLES[x]` exists. | ||
|
||
3. Let :math:`a` be the :ref:`table address <syntax-tableaddr>` :math:`F.\AMODULE.\MITABLES[x]`. | ||
|
||
4. Assert: due to :ref:`validation <valid-table.grow>`, :math:`S.\STABLES[a]` exists. | ||
|
||
5. Let :math:`\X{tab}` be the :ref:`table instance <syntax-tableinst>` :math:`S.\STABLES[a]`. | ||
|
||
6. Let :math:`\X{sz}` be the length of :math:`S.\STABLES[a]`. | ||
|
||
7. Assert: due to :ref:`validation <valid-table.grow>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack. | ||
|
||
8. Pop the value :math:`\I32.\CONST~n` from the stack. | ||
|
||
9. Assert: due to :ref:`validation <valid-table.fill>`, a :ref:`reference value <syntax-ref>` is on the top of the stack. | ||
|
||
10. Pop the value :math:`\val` from the stack. | ||
|
||
11. Either, try :ref:`growing <grow-table>` :math:`\X{table}` by :math:`n` entries with initialization value :math:`\val`: | ||
|
||
a. If it succeeds, push the value :math:`\I32.\CONST~\X{sz}` to the stack. | ||
|
||
b. Else, push the value :math:`\I32.\CONST~(-1)` to the stack. | ||
|
||
12. Or, push the value :math:`\I32.\CONST~(-1)` to the stack. | ||
|
||
.. math:: | ||
~\\[-1ex] | ||
\begin{array}{l} | ||
\begin{array}{lcl@{\qquad}l} | ||
S; F; \val~(\I32.\CONST~n)~\TABLEGROW~x &\stepto& S'; F; (\I32.\CONST~\X{sz}) | ||
\end{array} | ||
\\ \qquad | ||
\begin{array}[t]{@{}r@{~}l@{}} | ||
(\iff & F.\AMODULE.\MITABLES[x] = a \\ | ||
\wedge & \X{sz} = |S.\STABLES[a].\TIELEM| \\ | ||
\wedge & S' = S \with \STABLES[a] = \growtable(S.\STABLES[a], n, \val)) \\ | ||
\end{array} | ||
\\[1ex] | ||
\begin{array}{lcl@{\qquad}l} | ||
S; F; (\I32.\CONST~n)~\TABLEGROW~x &\stepto& S; F; (\I32.\CONST~{-1}) | ||
\end{array} | ||
\end{array} | ||
|
||
.. note:: | ||
The |TABLEGROW| instruction is non-deterministic. | ||
It may either succeed, returning the old table size :math:`\X{sz}`, | ||
or fail, returning :math:`{-1}`. | ||
Failure *must* occur if the referenced table instance has a maximum size defined that would be exceeded. | ||
However, failure *can* occur in other cases as well. | ||
In practice, the choice depends on the :ref:`resources <impl-exec>` available to the :ref:`embedder <embedder>`. | ||
|
||
|
||
.. _exec-table.fill: | ||
|
||
:math:`\TABLEFILL~x` | ||
.................... | ||
|
||
1. Let :math:`F` be the :ref:`current <exec-notation-textual>` :ref:`frame <syntax-frame>`. | ||
|
||
2. Assert: due to :ref:`validation <valid-table.fill>`, :math:`F.\AMODULE.\MITABLES[x]` exists. | ||
|
||
3. Let :math:`a` be the :ref:`table address <syntax-tableaddr>` :math:`F.\AMODULE.\MITABLES[x]`. | ||
|
||
4. Assert: due to :ref:`validation <valid-table.fill>`, :math:`S.\STABLES[a]` exists. | ||
|
||
5. Let :math:`\X{tab}` be the :ref:`table instance <syntax-tableinst>` :math:`S.\STABLES[a]`. | ||
|
||
6. Assert: due to :ref:`validation <valid-table.fill>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically this is possibly a little dodgy (ditto subsequent clauses, ditto clauses for TABLESET): since we're directly manipulating the stack in the recursive call below, asserting that this is true as a consequence of validation is questionable. I'm not sure it's worth fixing though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, fair point. I think there are actually a few other such assertions already where, strictly speaking, having the right value on the stack is rather a consequence of soundness. |
||
|
||
7. Pop the value :math:`\I32.\CONST~n` from the stack. | ||
|
||
8. Assert: due to :ref:`validation <valid-table.fill>`, a :ref:`reference value <syntax-ref>` is on the top of the stack. | ||
|
||
9. Pop the value :math:`\val` from the stack. | ||
|
||
10. Assert: due to :ref:`validation <valid-table.fill>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack. | ||
|
||
11. Pop the value :math:`\I32.\CONST~i` from the stack. | ||
|
||
12. If :math:`n` is :math:`0`, then: | ||
|
||
a. If :math:`i` is larger than the length of :math:`\X{tab}.\TIELEM`, then: | ||
|
||
i. Trap. | ||
|
||
12. Else: | ||
|
||
a. Push the value :math:`\I32.CONST~i` to the stack. | ||
|
||
b. Push the value :math:`\val` to the stack. | ||
|
||
c. Execute the instruction :math:`\TABLESET~x`. | ||
|
||
d. Push the value :math:`\I32.CONST~(i+1)` to the stack. | ||
|
||
e. Push the value :math:`\val` to the stack. | ||
|
||
f. Push the value :math:`\I32.CONST~(n-1)` to the stack. | ||
|
||
c. Execute the instruction :math:`\TABLEFILL~x`. | ||
|
||
.. math:: | ||
\begin{array}{l} | ||
\begin{array}{lcl@{\qquad}l} | ||
S; F; (\I32.\CONST~i)~\val~(\I32.\CONST~(n+1))~(\TABLEFILL~x) &\stepto& S'; F; (\I32.\CONST~i)~\val~(\TABLESET~x)~(\I32.\CONST~(i+1))~\val~(\I32.\CONST~n)~(\TABLEFILL~x) | ||
\end{array} \\ | ||
\begin{array}{lcl@{\qquad}l} | ||
S; F; (\I32.\CONST~i)~\val~(\I32.\CONST~0)~(\TABLEFILL~x) &\stepto& S'; F; \epsilon | ||
\end{array} | ||
\\ \qquad | ||
(\iff i \leq |\STABLES[F.\AMODULE.\MITABLES[x]]|) \\ | ||
\begin{array}{lcl@{\qquad}l} | ||
S; F; (\I32.\CONST~i)~\val~(\I32.\CONST~0)~(\TABLEFILL~x) &\stepto& S; F; \TRAP | ||
\end{array} | ||
\\ \qquad | ||
(\otherwise) \\ | ||
\end{array} | ||
|
||
|
||
.. index:: memory instruction, memory index, store, frame, address, memory address, memory instance, value, integer, limits, value type, bit width | ||
pair: execution; instruction | ||
single: abstract syntax; instruction | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're missing any handling of the initializer argument here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed. That meant also adjusting the meta function and the embedding interface accordingly to support an initialisation value.