Skip to content

Commit 5b85658

Browse files
committed
Merge branch 'main' into wasm-3.0
2 parents ba81d7a + e6afe0a commit 5b85658

File tree

8 files changed

+128
-60
lines changed

8 files changed

+128
-60
lines changed

.github/workflows/w3c-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
jobs:
1212
publish-to-w3c-TR:
13+
if: github.repository == 'WebAssembly/spec'
1314
runs-on: ubuntu-latest
1415
steps:
1516
- name: Checkout repo

document/core/appendix/properties.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,14 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow
717717

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

720+
* Let :math:`m` be the length of :math:`\moduleinst.\MIFUNCS`.
721+
720722
* Let :math:`n` be the length of :math:`\moduleinst.\MIDATAS`.
721723

724+
* Let :math:`x^\ast` be the sequence of :ref:`function indices <syntax-funcidx>` from :math:`0` to :math:`m-1`.
725+
722726
* Then the module instance is valid with :ref:`context <context>`
723-
:math:`\{\CTYPES~\deftype^\ast,` :math:`\CFUNCS~\functype^\ast,` :math:`\CTABLES~\tabletype^\ast,` :math:`\CMEMS~\memtype^\ast,` :math:`\CGLOBALS~\globaltype^\ast,` :math:`\CELEMS~\reftype^\ast,` :math:`\CDATAS~{\ok}^n\}`.
727+
:math:`\{\CTYPES~\deftype^\ast,` :math:`\CFUNCS~\functype^\ast,` :math:`\CTABLES~\tabletype^\ast,` :math:`\CMEMS~\memtype^\ast,` :math:`\CGLOBALS~\globaltype^\ast,` :math:`\CELEMS~\reftype^\ast,` :math:`\CDATAS~{\ok}^n,` :math:`\CREFS~x^\ast\}`.
724728

725729
.. math::
726730
~\\[-1ex]
@@ -762,7 +766,8 @@ where :math:`\val_1 \gg^+_S \val_2` denotes the transitive closure of the follow
762766
\CMEMS & \memtype^\ast, \\
763767
\CGLOBALS & \globaltype^\ast, \\
764768
\CELEMS & \reftype^\ast, \\
765-
\CDATAS & {\ok}^n ~\}
769+
\CDATAS & {\ok}^n, \\
770+
\CREFS & 0 \dots (|\funcaddr^\ast|-1) ~\}
766771
\end{array}
767772
\end{array}
768773
}

document/core/exec/instructions.rst

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 99 additions & 12 deletions
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
@@ -128,6 +129,8 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
128129
text: struct address; url: exec/runtime.html#syntax-structaddr
129130
text: array address; url: exec/runtime.html#syntax-arrayaddr
130131
text: host address; url: exec/runtime.html#syntax-hostaddr
132+
text: extern address; url: exec/runtime.html#syntax-externaddr
133+
text: page size; url: exec/runtime.html#page-size
131134
url: syntax/types.html#syntax-numtype
132135
text: i32
133136
text: i64
@@ -181,6 +184,11 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
181184
urlPrefix: https://heycam.github.io/webidl/; spec: WebIDL
182185
type: dfn
183186
text: create a namespace object; url: create-a-namespace-object
187+
urlPrefix: https://tc39.es/proposal-resizablearraybuffer/; spec: ResizableArrayBuffer proposal
188+
type: dfn
189+
text: handled; url: sec-hostresizearraybuffer
190+
text: IsFixedLengthArrayBuffer; url: sec-isfixedarraybuffer
191+
text: HostResizeArrayBuffer; url: sec-hostresizearraybuffer
184192
</pre>
185193

186194
<pre class='link-defaults'>
@@ -618,6 +626,8 @@ dictionary MemoryDescriptor {
618626
interface Memory {
619627
constructor(MemoryDescriptor descriptor);
620628
unsigned long grow([EnforceRange] unsigned long delta);
629+
ArrayBuffer toFixedLengthBuffer();
630+
ArrayBuffer toResizableBuffer();
621631
readonly attribute ArrayBuffer buffer;
622632
};
623633
</pre>
@@ -630,10 +640,27 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
630640
* \[[BufferObject]] : an {{ArrayBuffer}} whose [=Data Block=] is [=identified with=] the above memory address
631641

632642
<div algorithm>
633-
To <dfn>create a memory buffer</dfn> from a [=memory address=] |memaddr|, perform the following steps:
643+
To <dfn>create a fixed length memory buffer</dfn> from a [=memory address=] |memaddr|, perform the following steps:
644+
645+
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
646+
1. Let |buffer| be a new {{ArrayBuffer}} with the internal slots \[[ArrayBufferData]], \[[ArrayBufferByteLength]], and \[[ArrayBufferDetachKey]].
647+
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
648+
1. Set |buffer|.\[[ArrayBufferByteLength]] to the length of |block|.
649+
1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory".
650+
1. Return |buffer|.
651+
</div>
652+
653+
<div algorithm>
654+
To <dfn>create a resizable memory buffer</dfn> from a [=memory address=] |memaddr| and a |maxsize|, perform the following steps:
634655

635656
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
636-
1. Let |buffer| be a new {{ArrayBuffer}} whose \[[ArrayBufferData]] is |block| and \[[ArrayBufferByteLength]] is set to the length of |block|.
657+
1. Let |length| be the length of |block|.
658+
1. If |maxsize| &gt; (65536 &times; 65536),
659+
1. Throw a {{RangeError}} exception.
660+
1. Let |buffer| be a new {{ArrayBuffer}} with the internal slots \[[ArrayBufferData]], \[[ArrayBufferByteLength]], \[[ArrayBufferMaxByteLength]], and \[[ArrayBufferDetachKey]].
661+
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
662+
1. Set |buffer|.\[[ArrayBufferByteLength]] to |length|.
663+
1. Set |buffer|.\[[ArrayBufferMaxByteLength]] is |maxsize|.
637664
1. Set |buffer|.\[[ArrayBufferDetachKey]] to "WebAssembly.Memory".
638665
1. Return |buffer|.
639666
</div>
@@ -642,7 +669,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
642669
To <dfn>initialize a memory object</dfn> |memory| from a [=memory address=] |memaddr|, perform the following steps:
643670
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
644671
1. Assert: |map|[|memaddr|] doesn't [=map/exist=].
645-
1. Let |buffer| be the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|.
672+
1. Let |buffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|.
646673
1. Set |memory|.\[[Memory]] to |memaddr|.
647674
1. Set |memory|.\[[BufferObject]] to |buffer|.
648675
1. [=map/Set=] |map|[|memaddr|] to |memory|.
@@ -672,36 +699,96 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
672699
</div>
673700

674701
<div algorithm>
675-
To <dfn>reset the Memory buffer</dfn> of |memaddr|, perform the following steps:
702+
To <dfn>refresh the Memory buffer</dfn> of |memaddr|, perform the following steps:
676703

677704
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
678705
1. Assert: |map|[|memaddr|] [=map/exists=].
679706
1. Let |memory| be |map|[|memaddr|].
680-
1. Perform [=!=] [$DetachArrayBuffer$](|memory|.\[[BufferObject]], "WebAssembly.Memory").
681-
1. Let |buffer| be the result of [=create a memory buffer|creating a memory buffer=] from |memaddr|.
682-
1. Set |memory|.\[[BufferObject]] to |buffer|.
707+
1. Let |buffer| be |memory|.\[[BufferObject]].
708+
1. If [=IsFixedLengthArrayBuffer=](|buffer|) is true,
709+
1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory").
710+
1. Let |buffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|.
711+
1. Set |memory|.\[[BufferObject]] to |buffer|.
712+
1. Otherwise,
713+
1. Let |block| be a [=Data Block=] which is [=identified with=] the underlying memory of |memaddr|.
714+
1. Set |buffer|.\[[ArrayBufferData]] to |block|.
715+
1. Set |buffer|.\[[ArrayBufferByteLength]] to the length of |block|.
683716
</div>
684717

685-
<div algorithm=dom-Memory-grow>
686-
The <dfn method for="Memory">grow(|delta|)</dfn> method, when invoked, performs the following steps:
718+
<div algorithm>
719+
To <dfn>grow the memory buffer</dfn> associated with a [=memory address=] |memaddr| by |delta|, perform the following steps:
720+
687721
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
688-
1. Let |memaddr| be **this**.\[[Memory]].
689722
1. Let |ret| be the [=mem_size=](|store|, |memaddr|).
690723
1. Let |store| be [=mem_grow=](|store|, |memaddr|, |delta|).
691724
1. If |store| is [=error=], throw a {{RangeError}} exception.
692725
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
693-
1. [=Reset the memory buffer=] of |memaddr|.
726+
1. [=Refresh the memory buffer=] of |memaddr|.
694727
1. Return |ret|.
695728
</div>
696729

730+
<div algorithm=dom-Memory-grow>
731+
The <dfn method for="Memory">grow(|delta|)</dfn> method, when invoked, performs the following steps:
732+
1. Let |memaddr| be **this**.\[[Memory]].
733+
1. Return the result of [=grow the memory buffer|growing the memory buffer=] associated with |memaddr| by |delta|.
734+
</div>
735+
697736
Immediately after a WebAssembly [=memory.grow=] instruction executes, perform the following steps:
698737

699738
<div algorithm="memory.grow">
700739
1. If the top of the stack is not [=i32.const=] (−1),
701740
1. Let |frame| be the [=current frame=].
702741
1. Assert: due to validation, |frame|.[=frame/module=].[=moduleinst/memaddrs=][0] exists.
703742
1. Let |memaddr| be the memory address |frame|.[=frame/module=].[=moduleinst/memaddrs=][0].
704-
1. [=Reset the memory buffer=] of |memaddr|.
743+
1. [=Refresh the memory buffer=] of |memaddr|.
744+
</div>
745+
746+
<div algorithm=dom-Memory-toFixedLengthBuffer>
747+
The <dfn method for="Memory">toFixedLengthBuffer()</dfn> method, when invoked, performs the following steps:
748+
1. Let |buffer| be **this**.\[[BufferObject]].
749+
1. If [=IsFixedLengthArrayBuffer=](|buffer|) is true, return |buffer|.
750+
1. Let |memaddr| be **this**.\[[Memory]].
751+
1. Let |fixedBuffer| be the result of [=create a fixed length memory buffer|creating a fixed length memory buffer=] from |memaddr|.
752+
1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory").
753+
1. Set **this**.\[[BufferObject]] to |fixedBuffer|.
754+
1. Return |fixedBuffer|.
755+
</div>
756+
757+
<div algorithm=dom-Memory-toResizableBuffer>
758+
The <dfn method for="Memory">toResizableBuffer()</dfn> method, when invoked, performs the following steps:
759+
1. Let |buffer| be **this**.\[[BufferObject]].
760+
1. If [=IsFixedLengthArrayBuffer=](|buffer|) is false, return |buffer|.
761+
1. Let |memaddr| be **this**.\[[Memory]].
762+
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
763+
1. Let |memtype| be [=mem_type=](|store|, |memaddr|).
764+
1. If |memtype| has a max,
765+
1. Let |maxsize| be the max value in |memtype|.
766+
1. Otherwise,
767+
1. Let |maxsize| be 65536 &times; 65536.
768+
1. Let |resizableBuffer| be the result of [=create a resizable memory buffer|creating a resizable memory buffer=] from |memaddr| and |maxsize|.
769+
1. Perform [=!=] [$DetachArrayBuffer$](|buffer|, "WebAssembly.Memory").
770+
1. Set **this**.\[[BufferObject]] to |resizableBuffer|.
771+
1. Return |resizableBuffer|.
772+
</div>
773+
774+
{{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.
775+
776+
<div algorithm>
777+
The <dfn>abstract operation [=HostResizeArrayBuffer=]</dfn> takes arguments |buffer| (an {{ArrayBuffer}}) and |newLength|. It performs the following steps when called.
778+
779+
1. If |buffer|.\[[ArrayBufferDetachKey]] is "WebAssembly.Memory",
780+
1. Let |map| be the [=surrounding agent=]'s associated [=Memory object cache=].
781+
1. Assert: |buffer| is the \[[BufferObject]] of exactly one value in |map|.
782+
1. [=map/iterate|For each=] |memaddr| &rarr; |mem| in |map|,
783+
1. If [=SameValue=](|mem|.\[[BufferObject]], |buffer|) is true,
784+
1. Assert: |buffer|.\[[ArrayBufferByteLength]] modulo 65536 is 0.
785+
1. Let |lengthDelta| be |newLength| - |buffer|.\[[ArrayBufferByteLength]].
786+
1. If |lengthDelta| &lt; 0 or |lengthDelta| modulo 65536 is not 0,
787+
1. Throw a {{RangeError}} exception.
788+
1. Let |delta| be |lengthDelta| &div; 65536.
789+
1. [=Grow the memory buffer=] associated with |memaddr| by |delta|.
790+
1. Return <emu-const>handled</emu-const>.
791+
1. Otherwise, return <emu-const>unhandled</emu-const>.
705792
</div>
706793

707794
<div algorithm>

interpreter/dune

Lines changed: 8 additions & 21 deletions
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 7 additions & 18 deletions
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)