Skip to content

Commit b83c90d

Browse files
committed
Update embedding and JS API
1 parent 88beb71 commit b83c90d

File tree

2 files changed

+66
-55
lines changed

2 files changed

+66
-55
lines changed

document/core/appendix/embedding.rst

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,30 +188,40 @@ Modules
188188
.. index:: import
189189
.. _embed-module-imports:
190190

191-
:math:`\F{module\_imports}(\module) : (\name, \name, \externtype)^\ast`
192-
.......................................................................
191+
:math:`\F{module\_imports}(\module) : (\name, (\name, \externtype)^\ast)^\ast`
192+
..............................................................................
193193

194194
1. Pre-condition: :math:`\module` is :ref:`valid <valid-module>` with the external import types :math:`\externtype^\ast` and external export types :math:`{\externtype'}^\ast`.
195195

196-
2. Let :math:`\import^\ast` be the :ref:`imports <syntax-import>` of :math:`\module`.
196+
2. Let :math:`\importmod^\ast` be the :ref:`import modules <syntax-importmod>` of :math:`\module`.
197197

198-
3. Assert: the length of :math:`\import^\ast` equals the length of :math:`\externtype^\ast`.
198+
3. Assert: the sum of the lengths of the items of :math:`\importmod^\ast` equals the length of :math:`\externtype^\ast`.
199199

200-
4. For each :math:`\import_i` in :math:`\import^\ast` and corresponding :math:`\externtype_i` in :math:`\externtype^\ast`, do:
200+
4. Let :math:`n = 0`.
201201

202-
a. Let :math:`\IMPORT~\X{nm}_{i1}~\X{nm}_{i2}~\X{xt}_i` be the deconstruction of :math:`\import_i`.
202+
5. For each :math:`\importmod_i` in :math:`\importmod^\ast`:
203203

204-
b. Let :math:`\X{result}_i` be the triple :math:`(\X{nm}_{i1}, \X{nm}_{i2}, \externtype_i)`.
204+
a. Let :math:`\IMPORTMOD~\X{nm}_1~\X{imports}` be the deconstruction of :math:`\importmod_i`.
205205

206-
5. Return the concatenation of all :math:`\X{result}_i`, in index order.
206+
b. For each :math:`\import_j` in :math:`\X{imports}` and corresponding :math:`\externtype_n` in :math:`\externtype^\ast`, do:
207+
208+
i. Let :math:`\IMPORT~\X{nm}_2~\X{xt}_j` be the deconstruction of :math:`\import_j`.
209+
210+
ii. Let :math:`\X{resultimport}_n` be the pair :math:`(\X{nm}_2, \externtype_n)`.
211+
212+
iii. Increment :math:`n`.
213+
214+
c. Let :math:`\X{result}_i` be the pair :math:`(\X{nm}_1, \X{resultimports})`, where :math:`\X{resultimports}` is the concatenation of all :math:`\X{resultimport}_i`, in index order.
215+
216+
6. Return the concatenation of all :math:`\X{result}_i`, in index order.
207217

208-
6. Post-condition: each :math:`\externtype_i` is :ref:`valid <valid-externtype>` under the empty :ref:`context <context>`.
218+
7. Post-condition: each :math:`\externtype_i` is :ref:`valid <valid-externtype>` under the empty :ref:`context <context>`.
209219

210220
.. math::
211221
~ \\
212222
\begin{array}{lclll}
213-
\F{module\_imports}(m) &=& (\X{nm}_1, \X{nm}_2, \externtype)^\ast \\
214-
&& \qquad (\iff (\IMPORT~\X{nm}_1~\X{nm}_2~\X{xt}^\ast)^\ast \in m \wedge {} \vdashmodule m : \externtype^\ast \rightarrow {\externtype'}^\ast) \\
223+
\F{module\_imports}(m) &=& (\X{nm}_1, (\X{nm}_2, \externtype)^\ast)^\ast \\
224+
&& \qquad (\iff (\IMPORTMOD~\X{nm}_1~(\IMPORT~\X{nm}_2~\X{xt})^\ast)^\ast \in m \wedge {} \vdashmodule m : \externtype^\ast \rightarrow {\externtype'}^\ast) \\
215225
\end{array}
216226
217227

document/js-api/index.bs

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -498,55 +498,56 @@ To <dfn>instantiate imported strings</dfn> with module |module| and |importedStr
498498
1. Let |exportsObject| be the result of [=instantiate imported strings=] with |module| and |importedStringModule|
499499
1. [=map/set|Set=] |builtinOrStringImports|[|importedStringModule|] to |exportsObject|
500500
1. Let |imports| be « ».
501-
1. [=list/iterate|For each=] (|moduleName|, |componentName|, |externtype|) of [=module_imports=](|module|),
501+
1. [=list/iterate|For each=] (|moduleName|, |moduleImports|) of [=module_imports=](|module|),
502502
1. If |builtinOrStringImports| [=map/exist|contains=] |moduleName|,
503503
1. Let |o| be |builtinOrStringImports|[|moduleName|].
504-
1. If |o| [=is not an Object=] or if |o| [=map/exist|does not contain=] |componentName|,
504+
1. If |o| [=is not an Object=] or if |o| [=map/exist|does not contain=] |itemName|,
505505
1. Set |o| to [=?=] [$Get$](|importObject|, |moduleName|).
506506
1. Else,
507507
1. Let |o| be [=?=] [$Get$](|importObject|, |moduleName|).
508-
1. If |o| [=is not an Object=], throw a {{TypeError}} exception.
509-
1. Let |v| be [=?=] [$Get$](|o|, |componentName|).
510-
1. If |externtype| is of the form [=external-type/func=] |functype|,
511-
1. If [$IsCallable$](|v|) is false, throw a {{LinkError}} exception.
512-
1. If |v| has a \[[FunctionAddress]] internal slot, and therefore is an [=Exported Function=],
513-
1. Let |funcaddr| be the value of |v|'s \[[FunctionAddress]] internal slot.
514-
1. Otherwise,
515-
1. [=Create a host function=] from |v| and |functype|, and let |funcaddr| be the result.
516-
1. Let |index| be the number of external functions in |imports|. This value |index| is known as the <dfn>index of the host function</dfn> |funcaddr|.
517-
1. Let |externfunc| be the [=external value=] [=external value|func=] |funcaddr|.
518-
1. [=list/Append=] |externfunc| to |imports|.
519-
1. If |externtype| is of the form [=external-type/global=] <var ignore>mut</var> |valtype|,
520-
1. If |v| [=implements=] {{Global}},
521-
1. Let |globaladdr| be |v|.\[[Global]].
522-
1. Otherwise,
523-
1. If |valtype| is [=i64=] and |v| [=is not a BigInt=],
524-
1. Throw a {{LinkError}} exception.
525-
1. If |valtype| is one of [=i32=], [=f32=] or [=f64=] and |v| [=is not a Number=],
526-
1. Throw a {{LinkError}} exception.
527-
1. If |valtype| is [=v128=],
528-
1. Throw a {{LinkError}} exception.
529-
1. Let |value| be [=ToWebAssemblyValue=](|v|, |valtype|). If this operation throws a {{TypeError}}, catch it, and throw a {{LinkError}} exception.
530-
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
531-
1. Let (|store|, |globaladdr|) be [=global_alloc=](|store|, [=const=] |valtype|, |value|).
532-
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
533-
1. Let |externglobal| be [=external value|global=] |globaladdr|.
534-
1. [=list/Append=] |externglobal| to |imports|.
535-
1. If |externtype| is of the form [=external-type/mem=] <var ignore>memtype</var>,
536-
1. If |v| does not [=implement=] {{Memory}}, throw a {{LinkError}} exception.
537-
1. Let |externmem| be the [=external value=] [=external value|mem=] |v|.\[[Memory]].
538-
1. [=list/Append=] |externmem| to |imports|.
539-
1. If |externtype| is of the form [=external-type/table=] <var ignore>tabletype</var>,
540-
1. If |v| does not [=implement=] {{Table}}, throw a {{LinkError}} exception.
541-
1. Let |tableaddr| be |v|.\[[Table]].
542-
1. Let |externtable| be the [=external value=] [=external value|table=] |tableaddr|.
543-
1. [=list/Append=] |externtable| to |imports|.
544-
1. If |externtype| is of the form [=external-type/tag=] |attribute| <var ignore>functype</var>,
545-
1. Assert: |attribute| is [=tagtype/attribute/exception=].
546-
1. If |v| does not [=implement=] {{Tag}}, throw a {{LinkError}} exception.
547-
1. Let |tagaddr| be |v|.\[[Address]].
548-
1. Let |externtag| be the [=external value=] [=external value/tag=] |tagaddr|.
549-
1. [=list/Append=] |externtag| to |imports|.
508+
1. [=list/iterate|For each=] (|itemName|, |externtype|) of |moduleImports|,
509+
1. If |o| [=is not an Object=], throw a {{TypeError}} exception.
510+
1. Let |v| be [=?=] [$Get$](|o|, |itemName|).
511+
1. If |externtype| is of the form [=external-type/func=] |functype|,
512+
1. If [$IsCallable$](|v|) is false, throw a {{LinkError}} exception.
513+
1. If |v| has a \[[FunctionAddress]] internal slot, and therefore is an [=Exported Function=],
514+
1. Let |funcaddr| be the value of |v|'s \[[FunctionAddress]] internal slot.
515+
1. Otherwise,
516+
1. [=Create a host function=] from |v| and |functype|, and let |funcaddr| be the result.
517+
1. Let |index| be the number of external functions in |imports|. This value |index| is known as the <dfn>index of the host function</dfn> |funcaddr|.
518+
1. Let |externfunc| be the [=external value=] [=external value|func=] |funcaddr|.
519+
1. [=list/Append=] |externfunc| to |imports|.
520+
1. If |externtype| is of the form [=external-type/global=] <var ignore>mut</var> |valtype|,
521+
1. If |v| [=implements=] {{Global}},
522+
1. Let |globaladdr| be |v|.\[[Global]].
523+
1. Otherwise,
524+
1. If |valtype| is [=i64=] and |v| [=is not a BigInt=],
525+
1. Throw a {{LinkError}} exception.
526+
1. If |valtype| is one of [=i32=], [=f32=] or [=f64=] and |v| [=is not a Number=],
527+
1. Throw a {{LinkError}} exception.
528+
1. If |valtype| is [=v128=],
529+
1. Throw a {{LinkError}} exception.
530+
1. Let |value| be [=ToWebAssemblyValue=](|v|, |valtype|). If this operation throws a {{TypeError}}, catch it, and throw a {{LinkError}} exception.
531+
1. Let |store| be the [=surrounding agent=]'s [=associated store=].
532+
1. Let (|store|, |globaladdr|) be [=global_alloc=](|store|, [=const=] |valtype|, |value|).
533+
1. Set the [=surrounding agent=]'s [=associated store=] to |store|.
534+
1. Let |externglobal| be [=external value|global=] |globaladdr|.
535+
1. [=list/Append=] |externglobal| to |imports|.
536+
1. If |externtype| is of the form [=external-type/mem=] <var ignore>memtype</var>,
537+
1. If |v| does not [=implement=] {{Memory}}, throw a {{LinkError}} exception.
538+
1. Let |externmem| be the [=external value=] [=external value|mem=] |v|.\[[Memory]].
539+
1. [=list/Append=] |externmem| to |imports|.
540+
1. If |externtype| is of the form [=external-type/table=] <var ignore>tabletype</var>,
541+
1. If |v| does not [=implement=] {{Table}}, throw a {{LinkError}} exception.
542+
1. Let |tableaddr| be |v|.\[[Table]].
543+
1. Let |externtable| be the [=external value=] [=external value|table=] |tableaddr|.
544+
1. [=list/Append=] |externtable| to |imports|.
545+
1. If |externtype| is of the form [=external-type/tag=] |attribute| <var ignore>functype</var>,
546+
1. Assert: |attribute| is [=tagtype/attribute/exception=].
547+
1. If |v| does not [=implement=] {{Tag}}, throw a {{LinkError}} exception.
548+
1. Let |tagaddr| be |v|.\[[Address]].
549+
1. Let |externtag| be the [=external value=] [=external value/tag=] |tagaddr|.
550+
1. [=list/Append=] |externtag| to |imports|.
550551
1. Return |imports|.
551552

552553
Note: This algorithm only verifies the right kind of JavaScript values are passed.

0 commit comments

Comments
 (0)