Skip to content

Commit 3ec1e39

Browse files
committed
Merge branch 'wasm3'
2 parents ff7ca55 + 24ab598 commit 3ec1e39

File tree

8 files changed

+164
-60
lines changed

8 files changed

+164
-60
lines changed

.github/workflows/w3c-publish.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish to W3C TR space
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths: [ .github/**, document/** ]
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
jobs:
12+
publish-to-w3c-TR:
13+
if: github.repository == 'WebAssembly/spec'
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@v2
18+
with:
19+
submodules: "recursive"
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: 16
24+
- name: Setup Bikeshed
25+
run: pip install bikeshed && bikeshed update
26+
- name: Setup TexLive
27+
run: sudo apt-get update -y && sudo apt-get install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
28+
- name: Setup Sphinx
29+
run: pip install six && pip install sphinx==5.1.0
30+
- name: Publish all specs to their https://www.w3.org/TR/ URLs
31+
run: cd document && make -e WD-echidna-CI
32+
env:
33+
STATUS: --md-status=WD
34+
W3C_ECHIDNA_TOKEN_CORE: ${{ secrets.W3C_ECHIDNA_TOKEN_CORE }}
35+
W3C_ECHIDNA_TOKEN_JSAPI: ${{ secrets.W3C_ECHIDNA_TOKEN_JSAPI }}
36+
W3C_ECHIDNA_TOKEN_WEBAPI: ${{ secrets.W3C_ECHIDNA_TOKEN_WEBAPI }}
37+
YARN_ENABLE_IMMUTABLE_INSTALLS: false

document/core/appendix/properties.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -825,10 +825,14 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow
825825

826826
* Let :math:`\reftype^\ast` be the concatenation of all :math:`\reftype_i` in order.
827827

828+
* Let :math:`m` be the length of :math:`\moduleinst.\MIFUNCS`.
829+
828830
* Let :math:`n` be the length of :math:`\moduleinst.\MIDATAS`.
829831

832+
* Let :math:`x^\ast` be the sequence of :ref:`function indices <syntax-funcidx>` from :math:`0` to :math:`m-1`.
833+
830834
* Then the module instance is valid with :ref:`context <context>`
831-
:math:`\{\CTYPES~\deftype^\ast,` :math:`\CFUNCS~\functype^\ast,` :math:`\CTABLES~\tabletype^\ast,` :math:`\CMEMS~\memtype^\ast,` :math:`\CGLOBALS~\globaltype^\ast,` \CTAGS~\tagtype^\ast, :math:`\CELEMS~\reftype^\ast,` :math:`\CDATAS~{\ok}^n\}`.
835+
:math:`\{\CTYPES~\deftype^\ast,` :math:`\CFUNCS~\functype^\ast,` :math:`\CTABLES~\tabletype^\ast,` :math:`\CMEMS~\memtype^\ast,` :math:`\CGLOBALS~\globaltype^\ast,` \CTAGS~\tagtype^\ast, :math:`\CELEMS~\reftype^\ast,` :math:`\CDATAS~{\ok}^n,` :math:`\CREFS~x^\ast\}`.
832836

833837
.. math::
834838
~\\[-1ex]
@@ -874,7 +878,8 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow
874878
\CGLOBALS & \globaltype^\ast, \\
875879
\CTAGS & \tagtype^\ast, \\
876880
\CELEMS & \reftype^\ast, \\
877-
\CDATAS & {\ok}^n ~\}
881+
\CDATAS & {\ok}^n, \\
882+
\CREFS & 0 \dots (|\funcaddr^\ast|-1) ~\}
878883
\end{array}
879884
\end{array}
880885
}

document/core/exec/instructions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ Most other vector instructions are defined in terms of numeric operators that ar
18801880

18811881
.. math::
18821882
\begin{array}{lcl@{\qquad}l}
1883-
(\V128\K{.}\VCONST~c_1)~\V128\K{.}\vunop &\stepto& (\V128\K{.}\VCONST~c)
1883+
(\V128\K{.}\VCONST~c_1)~\shape\K{.}\vunop &\stepto& (\V128\K{.}\VCONST~c)
18841884
& (\iff c = \vunop_{\shape}(c_1))
18851885
\end{array}
18861886

document/core/valid/instructions.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ The following auxiliary function denotes the number of lanes in a vector shape,
961961
\frac{
962962
\laneidx < \dim(\shape)
963963
}{
964-
C \vdashinstr t\K{x}N\K{.}\EXTRACTLANE\K{\_}\sx^?~\laneidx : [\V128] \to [\unpacked(\shape)]
964+
C \vdashinstr \shape\K{.}\EXTRACTLANE\K{\_}\sx^?~\laneidx : [\V128] \to [\unpacked(\shape)]
965965
}
966966
967967

document/js-api/index.bs

+99-12
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMASCRIPT
6161
text: NativeError Object Structure; url: sec-nativeerror-object-structure
6262
text: 𝔽; url: #𝔽
6363
text: ℤ; url: #ℤ
64+
text: SameValue; url: sec-samevalue
6465
type: abstract-op
6566
text: CreateMethodProperty; url: sec-createmethodproperty
6667
urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: dfn
@@ -129,6 +130,8 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
129130
text: struct address; url: exec/runtime.html#syntax-structaddr
130131
text: array address; url: exec/runtime.html#syntax-arrayaddr
131132
text: host address; url: exec/runtime.html#syntax-hostaddr
133+
text: extern address; url: exec/runtime.html#syntax-externaddr
134+
text: page size; url: exec/runtime.html#page-size
132135
url: syntax/types.html#syntax-numtype
133136
text: i32
134137
text: i64
@@ -191,6 +194,11 @@ urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL
191194
text: create a namespace object; url: create-a-namespace-object
192195
urlPrefix: https://webassembly.github.io/js-types/js-api/; spec: WebAssembly JS API (JS Type Reflection)
193196
type: abstract-op; text: FromValueType; url: abstract-opdef-fromvaluetype
197+
urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: ResizableArrayBuffer proposal
198+
type: dfn
199+
text: handled; url: sec-hostresizearraybuffer
200+
text: IsFixedLengthArrayBuffer; url: sec-isfixedarraybuffer
201+
text: HostResizeArrayBuffer; url: sec-hostresizearraybuffer
194202
</pre>
195203

196204
<pre class='link-defaults'>
@@ -643,6 +651,8 @@ dictionary MemoryDescriptor {
643651
interface Memory {
644652
constructor(MemoryDescriptor descriptor);
645653
unsigned long grow([EnforceRange] unsigned long delta);
654+
ArrayBuffer toFixedLengthBuffer();
655+
ArrayBuffer toResizableBuffer();
646656
readonly attribute ArrayBuffer buffer;
647657
};
648658
</pre>
@@ -655,10 +665,27 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
655665
* \[[BufferObject]] : an {{ArrayBuffer}} whose [=Data Block=] is [=identified with=] the above memory address
656666

657667
<div algorithm>
658-
To <dfn>create a memory buffer</dfn> from a [=memory address=] |memaddr|, perform the following steps:
668+
To <dfn>create a fixed length memory buffer</dfn> from a [=memory address=] |memaddr|, perform the following steps:
669+
670+
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
671+
1. Let |buffer| be a new {{ArrayBuffer}} with the internal slots \[[ArrayBufferData]], \[[ArrayBufferByteLength]], and \[[ArrayBufferDetachKey]].
672+
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
673+
1. Set |buffer|.\[[ArrayBufferByteLength]] to the length of |block|.
674+
1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory".
675+
1. Return |buffer|.
676+
</div>
677+
678+
<div algorithm>
679+
To <dfn>create a resizable memory buffer</dfn> from a [=memory address=] |memaddr| and a |maxsize|, perform the following steps:
659680

660681
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
661-
1. Let |buffer| be a new {{ArrayBuffer}} whose \[[ArrayBufferData]] is |block| and \[[ArrayBufferByteLength]] is set to the length of |block|.
682+
1. Let |length| be the length of |block|.
683+
1. If |maxsize| &gt; (65536 &times; 65536),
684+
1. Throw a {{RangeError}} exception.
685+
1. Let |buffer| be a new {{ArrayBuffer}} with the internal slots \[[ArrayBufferData]], \[[ArrayBufferByteLength]], \[[ArrayBufferMaxByteLength]], and \[[ArrayBufferDetachKey]].
686+
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
687+
1. Set |buffer|.\[[ArrayBufferByteLength]] to |length|.
688+
1. Set |buffer|.\[[ArrayBufferMaxByteLength]] is |maxsize|.
662689
1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory".
663690
1. Return |buffer|.
664691
</div>
@@ -667,7 +694,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
667694
To <dfn>initialize a memory object</dfn> |memory| from a [=memory address=] |memaddr|, perform the following steps:
668695
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
669696
1. Assert: |map|[|memaddr|] doesn't [=map/exist=].
670-
1. Let |buffer| be the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|.
697+
1. Let |buffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|.
671698
1. Set |memory|.\[[Memory]] to |memaddr|.
672699
1. Set |memory|.\[[BufferObject]] to |buffer|.
673700
1. [=map/Set=] |map|[|memaddr|] to |memory|.
@@ -697,36 +724,96 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
697724
</div>
698725

699726
<div algorithm>
700-
To <dfn>reset the Memory buffer</dfn> of |memaddr|, perform the following steps:
727+
To <dfn>refresh the Memory buffer</dfn> of |memaddr|, perform the following steps:
701728

702729
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
703730
1. Assert: |map|[|memaddr|] [=map/exists=].
704731
1. Let |memory| be |map|[|memaddr|].
705-
1. Perform [=!=] [$DetachArrayBuffer$](|memory|.\[[BufferObject]], "WebAssembly.Memory").
706-
1. Let |buffer| be the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|.
707-
1. Set |memory|.\[[BufferObject]] to |buffer|.
732+
1. Let |buffer| be |memory|.\[[BufferObject]].
733+
1. If [=IsFixedLengthArrayBuffer=](|buffer|) is true,
734+
1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory").
735+
1. Let |buffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|.
736+
1. Set |memory|.\[[BufferObject]] to |buffer|.
737+
1. Otherwise,
738+
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
739+
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
740+
1. Set |buffer|.\[[ArrayBufferByteLength]] to the length of |block|.
708741
</div>
709742

710-
<div algorithm=dom-Memory-grow>
711-
The <dfn method for="Memory">grow(|delta|)</dfn> method, when invoked, performs the following steps:
743+
<div algorithm>
744+
To <dfn>grow the memory buffer</dfn> associated with a [=memory address=] |memaddr| by |delta|, perform the following steps:
745+
712746
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
713-
1. Let |memaddr| be **this**.\[[Memory]].
714747
1. Let |ret| be the [=mem_size=](|store|, |memaddr|).
715748
1. Let |store| be [=mem_grow=](|store|, |memaddr|, |delta|).
716749
1. If |store| is [=error=], throw a {{RangeError}} exception.
717750
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
718-
1. [=Reset the memory buffer=] of |memaddr|.
751+
1. [=Refresh the memory buffer=] of |memaddr|.
719752
1. Return |ret|.
720753
</div>
721754

755+
<div algorithm=dom-Memory-grow>
756+
The <dfn method for="Memory">grow(|delta|)</dfn> method, when invoked, performs the following steps:
757+
1. Let |memaddr| be **this**.\[[Memory]].
758+
1. Return the result of [=grow the memory buffer|growing the memory buffer=] associated with |memaddr| by |delta|.
759+
</div>
760+
722761
Immediately after a WebAssembly [=memory.grow=] instruction executes, perform the following steps:
723762

724763
<div algorithm="memory.grow">
725764
1. If the top of the stack is not [=i32.const=] (−1),
726765
1. Let |frame| be the [=current frame=].
727766
1. Assert: due to validation, |frame|.[=frame/module=].[=moduleinst/memaddrs=][0] exists.
728767
1. Let |memaddr| be the memory address |frame|.[=frame/module=].[=moduleinst/memaddrs=][0].
729-
1. [=Reset the memory buffer=] of |memaddr|.
768+
1. [=Refresh the memory buffer=] of |memaddr|.
769+
</div>
770+
771+
<div algorithm=dom-Memory-toFixedLengthBuffer>
772+
The <dfn method for="Memory">toFixedLengthBuffer()</dfn> method, when invoked, performs the following steps:
773+
1. Let |buffer| be **this**.\[[BufferObject]].
774+
1. If [=IsFixedLengthArrayBuffer=](|buffer|) is true, return |buffer|.
775+
1. Let |memaddr| be **this**.\[[Memory]].
776+
1. Let |fixedBuffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|.
777+
1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory").
778+
1. Set **this**.\[[BufferObject]] to |fixedBuffer|.
779+
1. Return |fixedBuffer|.
780+
</div>
781+
782+
<div algorithm=dom-Memory-toResizableBuffer>
783+
The <dfn method for="Memory">toResizableBuffer()</dfn> method, when invoked, performs the following steps:
784+
1. Let |buffer| be **this**.\[[BufferObject]].
785+
1. If [=IsFixedLengthArrayBuffer=](|buffer|) is false, return |buffer|.
786+
1. Let |memaddr| be **this**.\[[Memory]].
787+
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
788+
1. Let |memtype| be [=mem_type=](|store|, |memaddr|).
789+
1. If |memtype| has a max,
790+
1. Let |maxsize| be the max value in |memtype|.
791+
1. Otherwise,
792+
1. Let |maxsize| be 65536 &times; 65536.
793+
1. Let |resizableBuffer| be the result of [=create a resizable memory buffer|creating a resizable memory buffer=] from |memaddr| and |maxsize|.
794+
1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory").
795+
1. Set **this**.\[[BufferObject]] to |resizableBuffer|.
796+
1. Return |resizableBuffer|.
797+
</div>
798+
799+
{{ArrayBuffer}} objects returned by a {{Memory}} object must have a size that is a multiple of a WebAssembly [=page size=] (the constant 65536). For this reason [=HostResizeArrayBuffer=] is redefined as follows.
800+
801+
<div algorithm>
802+
The <dfn>abstract operation [=HostResizeArrayBuffer=]</dfn> takes arguments |buffer| (an {{ArrayBuffer}}) and |newLength|. It performs the following steps when called.
803+
804+
1. If |buffer|.\[[ArrayBufferDetachKey]] is "WebAssembly.Memory",
805+
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
806+
1. Assert: |buffer| is the \[[BufferObject]] of exactly one value in |map|.
807+
1. [=map/iterate|For each=] |memaddr| &rarr; |mem| in |map|,
808+
1. If [=SameValue=](|mem|.\[[BufferObject]], |buffer|) is true,
809+
1. Assert: |buffer|.\[[ArrayBufferByteLength]] modulo 65536 is 0.
810+
1. Let |lengthDelta| be |newLength| - |buffer|.\[[ArrayBufferByteLength]].
811+
1. If |lengthDelta| &lt; 0 or |lengthDelta| modulo 65536 is not 0,
812+
1. Throw a {{RangeError}} exception.
813+
1. Let |delta| be |lengthDelta| &div; 65536.
814+
1. [=Grow the memory buffer=] associated with |memaddr| by |delta|.
815+
1. Return <emu-const>handled</emu-const>.
816+
1. Otherwise, return <emu-const>unhandled</emu-const>.
730817
</div>
731818

732819
<div algorithm>

interpreter/dune

+8-21
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
(library
44
(public_name wasm)
5-
; The 'wasm' module shall not be part of the library, as it would start the
6-
; Wasm REPL every time in all the dependencies.
7-
; We exclude the 'wast' module as it is only used for the JS build.
8-
; 'smallint' is a separate test module.
9-
(modules :standard \ main wasm smallint wast)
10-
(libraries menhirLib)
5+
(modules :standard \ main wasm wast smallint)
116
)
127

138
(executable
@@ -32,26 +27,18 @@
3227
(preprocess (pps js_of_ocaml-ppx))
3328
)
3429

35-
(rule
36-
(targets wasm.ml)
37-
(deps main/main.ml)
38-
(action (copy main/main.ml wasm.ml))
39-
)
30+
(env (_ (flags (-w +a-4-27-42-44-45-70 -warn-error +a-3))))
4031

4132
(subdir text
42-
(rule
43-
(target lexer.ml)
44-
(deps lexer.mll)
45-
(action
46-
(chdir %{workspace_root}
47-
(run %{bin:ocamllex} -ml -q -o %{target} %{deps})
48-
)
49-
)
50-
)
33+
(ocamllex (modules lexer))
5134
(menhir (modules parser))
5235
)
5336

54-
(env (_ (flags (-w +a-4-27-42-44-45-70 -warn-error +a-3))))
37+
(rule
38+
(targets wasm.ml)
39+
(deps main/main.ml)
40+
(action (copy main/main.ml wasm.ml))
41+
)
5542

5643
(rule
5744
(alias runtest)

interpreter/dune-project

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
(lang dune 2.9)
22

33
(name wasm)
4-
5-
(generate_opam_files true)
6-
(using menhir 2.1)
7-
(implicit_transitive_deps false)
8-
94
(license Apache-2.0)
105
(source (github WebAssembly/spec))
116

127
(authors "Andreas Rossberg <[email protected]")
138
(maintainers "Andreas Rossberg <[email protected]")
149

10+
(generate_opam_files true)
11+
(using menhir 2.1)
12+
(implicit_transitive_deps false)
13+
1514
(package
1615
(name wasm)
1716
(synopsis "Library to read and write WebAssembly (Wasm) files and manipulate their AST")

interpreter/text/parse.ml

+7-18
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,19 @@ sig
99
val parse_channel : in_channel -> t
1010
end
1111

12-
let provider buf () =
13-
let tok = Lexer.token buf in
14-
let start = Lexing.lexeme_start_p buf in
15-
let stop = Lexing.lexeme_end_p buf in
16-
tok, start, stop
17-
18-
let convert_pos buf =
19-
{ Source.left = Lexer.convert_pos buf.Lexing.lex_start_p;
20-
Source.right = Lexer.convert_pos buf.Lexing.lex_curr_p
12+
let convert_pos lexbuf =
13+
{ Source.left = Lexer.convert_pos lexbuf.Lexing.lex_start_p;
14+
Source.right = Lexer.convert_pos lexbuf.Lexing.lex_curr_p
2115
}
2216

2317
let make (type a) (start : _ -> _ -> a) : (module S with type t = a) =
2418
(module struct
2519
type t = a
2620

27-
let parse name buf =
28-
Lexing.set_filename buf name;
29-
try
30-
MenhirLib.Convert.Simplified.traditional2revised start (provider buf)
31-
with
32-
| Parser.Error ->
33-
raise (Syntax (convert_pos buf, "unexpected token"))
34-
| Syntax (region, s) when region <> Source.no_region ->
35-
raise (Syntax (convert_pos buf, s))
21+
let parse name lexbuf =
22+
Lexing.set_filename lexbuf name;
23+
try start Lexer.token lexbuf with Parser.Error ->
24+
raise (Syntax (convert_pos lexbuf, "unexpected token"))
3625

3726
let parse_string s =
3827
parse "string" (Lexing.from_string ~with_positions:true s)

0 commit comments

Comments
 (0)