8000 Text format for modules · WebAssembly/spec@cc8a6a3 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc8a6a3

Browse files
committed
Text format for modules
1 parent 74d752f commit cc8a6a3

File tree

8 files changed

+246
-484
lines changed

8 files changed

+246
-484
lines changed

document/core/text/conventions.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ which were denoted by the corresponding :ref:`identifiers <text-id>`.
112112
Unnamed indices are associated with empty (${:eps}) entries in these lists.
113113
Fields have *dependent* name spaces, and hence a separate list of field identifiers per type.
114114

115+
In addition, the field ${:TYPEDEFS} records the :ref:`defined type <syntax-deftype>` associated with each :ref:`type index <syntax-typeidx>`.
116+
They are needed to look up the number of parameters of :ref:`function types <syntax-functype>` when used in a :ref:`function definition <text-func>`,
117+
in order to produce the correct indices for :ref:`locals <syntax-local>`.
118+
115119
An identifier context is *well-formed* if no index space contains duplicate identifiers.
116120
For fields, names need only be unique within a single type.
117121

document/core/text/modules.rst

Lines changed: 106 additions & 401 deletions
Large diffs are not rendered by default.

document/core/util/macros.def

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@
418418
.. Modules, non-terminals
419419

420420
.. |module| mathdef:: \xref{syntax/modules}{syntax-module}{\X{module}}
421+
.. |decl| mathdef:: \xref{syntax/modules}{syntax-decl}{\X{decl}}
421422
.. |type| mathdef:: \xref{syntax/types}{syntax-rectype}{\X{type}}
422423
.. |func| mathdef:: \xref{syntax/modules}{syntax-func}{\X{func}}
423424
.. |local| mathdef:: \xref{syntax/modules}{syntax-local}{\X{local}}
@@ -442,6 +443,20 @@
442443
.. |globalsxx| mathdef:: \xref{syntax/modules}{syntax-externidx}{\F{globals}}
443444
.. |tagsxx| mathdef:: \xref{syntax/modules}{syntax-externidx}{\F{tags}}
444445

446+
.. |typesd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{types}}
447+
.. |importsd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{imports}}
448+
.. |tagsd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{tags}}
449+
.. |globalsd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{globals}}
450+
.. |memsd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{mems}}
451+
.. |tablesd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{tables}}
452+
.. |funcsd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{funcs}}
453+
.. |datasd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{datas}}
454+
.. |elemsd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{elems}}
455+
.. |startsd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{starts}}
456+
.. |exportsd| mathdef:: \xref{syntax/modules}{syntax-decl}{\F{exports}}
457+
458+
.. |ordered| mathdef:: \xref{syntax/modules}{aux-ordered}{\F{ordered}}
459+
445460

446461
.. Instructions, terminals
447462

@@ -965,26 +980,26 @@
965980
.. |TfX#1| mathdef:: {\T{f}#1}
966981

967982
.. |TuN| mathdef:: \xref{text/values}{text-int}{\TuX{{\kern-0.1em N}}}
968-
.. |Tu1| mathdef:: \xref{text/values}{text-int}{\TuX{\T{1}}}
969-
.. |Tu8| mathdef:: \xref{text/values}{text-int}{\TuX{\T{8}}}
970-
.. |Tu16| mathdef:: \xref{text/values}{text-int}{\TuX{\T{16}}}
971-
.. |Tu32| mathdef:: \xref{text/values}{text-int}{\TuX{\T{32}}}
972-
.. |Tu64| mathdef:: \xref{text/values}{text-int}{\TuX{\T{64}}}
983+
.. |Tu1| mathdef:: \xref{text/values}{text-int}{\T{u1}}
984+
.. |Tu8| mathdef:: \xref{text/values}{text-int}{\T{u8}}
985+
.. |Tu16| mathdef:: \xref{text/values}{text-int}{\T{u16}}
986+
.. |Tu32| mathdef:: \xref{text/values}{text-int}{\T{u32}}
987+
.. |Tu64| mathdef:: \xref{text/values}{text-int}{\T{u64}}
973988

974989
.. |TsN| mathdef:: \xref{text/values}{text-int}{\TsX{\kern-0.1em N}}
975-
.. |Ts32| mathdef:: \xref{text/values}{text-int}{\TsX{\T{32}}}
976-
.. |Ts64| mathdef:: \xref{text/values}{text-int}{\TsX{\T{64}}}
990+
.. |Ts32| mathdef:: \xref{text/values}{text-int}{\T{s32}}
991+
.. |Ts64| mathdef:: \xref{text/values}{text-int}{\T{s64}}
977992

978993
.. |TiN| mathdef:: \xref{text/values}{text-int}{\TiX{\kern-0.1em N}}
979-
.. |Ti8| mathdef:: \xref{text/values}{text-int}{\TiX{\T{8}}}
980-
.. |Ti16| mathdef:: \xref{text/values}{text-int}{\TiX{\T{16}}}
981-
.. |Ti32| mathdef:: \xref{text/values}{text-int}{\TiX{\T{32}}}
982-
.. |Ti64| mathdef:: \xref{text/values}{text-int}{\TiX{\T{64}}}
994+
.. |Ti8| mathdef:: \xref{text/values}{text-int}{\T{i8}}
995+
.. |Ti16| mathdef:: \xref{text/values}{text-int}{\T{i16}}
996+
.. |Ti32| mathdef:: \xref{text/values}{text-int}{\T{i32}}
997+
.. |Ti64| mathdef:: \xref{text/values}{text-int}{\T{i64}}
983998

984999
.. |TfN| mathdef:: \xref{text/values}{text-float}{\TfX{\kern-0.1em N}}
9851000
.. |TfNmag| mathdef:: \xref{text/values}{text-float}{\TfX{N}\T{mag}}
986-
.. |Tf32| mathdef:: \xref{text/values}{text-float}{\TfX{\T{32}}}
987-
.. |Tf64| mathdef:: \xref{text/values}{text-float}{\TfX{\T{64}}}
1001+
.. |Tf32| mathdef:: \xref{text/values}{text-float}{\T{f32}}
1002+
.. |Tf64| mathdef:: \xref{text/values}{text-float}{\T{f64}}
9881003

9891004
.. |Tstring| mathdef:: \xref{text/values}{text-string}{\T{string}}
9901005
.. |Tstringelem| mathdef:: \xref{text/values}{text-string}{\T{stringelem}}
@@ -1030,6 +1045,7 @@
10301045

10311046
.. Indices, non-terminals
10321047

1048+
.. |Tidx| mathdef:: \xref{text/modules}{text-idx}{\T{idx}}
10331049
.. |Ttypeidx| mathdef:: \xref{text/modules}{text-typeidx}{\T{typeidx}}
10341050
.. |Tfuncidx| mathdef:: \xref{text/modules}{text-funcidx}{\T{funcidx}}
10351051
.. |Ttableidx| mathdef:: \xref{text/modules}{text-tableidx}{\T{tableidx}}
@@ -1046,7 +1062,7 @@
10461062
.. Modules, non-terminals
10471063

10481064
.. |Tmodule| mathdef:: \xref{text/modules}{text-module}{\T{module}}
1049-
.. |Tmodulefield| mathdef:: \xref{text/modules}{text-modulefield}{\T{modulefield}}
1065+
.. |Tdecl| mathdef:: \xref{text/modules}{text-decl}{\T{decl}}
10501066
.. |Ttype| mathdef:: \xref{text/types}{text-type}{\T{type}}
10511067
.. |Ttypeuse| mathdef:: \xref{text/types}{text-typeuse}{\T{typeuse}}
10521068
.. |Tfunc| mathdef:: \xref{text/modules}{text-func}{\T{func}}

specification/wasm-3.0/3.1-numerics.scalar.spectec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def $truncz(rat) : int
7777
def $truncz hint(builtin)
7878
;;def $truncz(+-q) = +-n -- if n <- nat /\ $(q - 1) < n <= q
7979

80-
def $ceilz(rat) : int
80+
def $ceilz(rat) : int hint(show $ceil(%)) hint(macro none)
8181
def $ceilz hint(builtin)
8282
;;def $ceilz(+-q) = +-n -- if n <- nat /\ q <= n < $(q + 1)
8383

specification/wasm-3.0/6.1-text.values.spectec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ syntax idctxt hint(desc "identifier context") hint(macro "I" "I%") =
147147
LOCALS (name?)* hint(desc "local"),
148148
LABELS (name?)* hint(desc "label"),
149149
FIELDS ((name?)*)* hint(desc "field"),
150-
TYPEDEFS (subtype?)* hint(desc "type definitions")
150+
TYPEDEFS (deftype?)* hint(desc "type definitions")
151151
}
152152

153153
syntax I = idctxt
154154

155-
def $concat_idctxt(idctxt*) : idctxt hint(show (++) %2)
155+
def $concat_idctxt(idctxt*) : idctxt hint(show (++) %)
156156
def $concat_idctxt(eps) = {}
157157
def $concat_idctxt(I I') = I ++ $concat_idctxt(I'*)
158158

specification/wasm-3.0/6.2-text.types.spectec

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,21 @@ grammar Texterntype_(I) : (externtype, idctxt) =
160160
grammar Ttypeuse_(I)/base : (typeidx, idctxt) =
161161
| "(" "type" x:Ttypeidx_(I) ")" => (x, I')
162162
----
163-
-- if I.TYPEDEFS[x] = SUB FINAL (FUNC t_1* -> t_2*)
163+
-- if I.TYPEDEFS[x] = _DEF (REC st*) i
164+
-- if st*[i] = SUB FINAL (FUNC t_1* -> t_2*)
164165
-- if I' = {LOCALS (eps)^(|t_1*|)}
165166
| "(" "type" x:Ttypeidx_(I) ")" (t_1,id?)*:Tparam_(I)* t_2*:Tresult_(I)* => (x, I')
166167
----
167-
-- if I.TYPEDEFS[x] = SUB FINAL (FUNC t_1* -> t_2*)
168+
-- if I.TYPEDEFS[x] = _DEF (REC st*) i
169+
-- if st*[i] = SUB FINAL (FUNC t_1* -> t_2*)
168170
-- if I' = {LOCALS (id?)*}
169171
-- Idctxt_ok: |- I' : OK
170172
| ...
171173

172174
grammar Ttypeuse_(I)/abbrev : (typeidx, idctxt) = ... | (t_1,id?)*:Tparam_(I)* t_2*:Tresult_(I)* == "(" "type" x:Ttypeidx_(I) ")" Tparam_(I)* Tresult_(I)*
173175
----
174-
-- if I.TYPEDEFS[x] = SUB FINAL (FUNC t_1* -> t_2*)
175-
-- (if I.TYPEDEFS[i] =/= SUB FINAL (FUNC t_1* -> t_2*))^(i<x)
176+
-- if I.TYPEDEFS[x] = _DEF (REC (SUB FINAL (FUNC t_1* -> t_2*))) 0
177+
-- (if I.TYPEDEFS[i] =/= _DEF (REC (SUB FINAL (FUNC t_1* -> t_2*))) 0)^(i<x)
176178

177179
;; TODO(5, rossberg): This does not yet formalise how new type definitions are
178180
;; appended to the module if needed for implicit type uses.

0 commit comments

Comments
 (0)
0