| <!DOCTYPE html> |
| |
| <html lang="en" data-content_root="./"> |
| <head> |
| <meta charset="utf-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" /> |
| |
| <title>NanoWasm — NanoWasm documentation</title> |
| <link rel="stylesheet" type="text/css" href="_static/pygments.css?v=5ecbeea2" /> |
| <link rel="stylesheet" type="text/css" href="_static/basic.css?v=b08954a9" /> |
| <link rel="stylesheet" type="text/css" href="_static/alabaster.css?v=27fed22d" /> |
| <script src="_static/documentation_options.js?v=5929fcd5"></script> |
| <script src="_static/doctools.js?v=9bcbadda"></script> |
| <script src="_static/sphinx_highlight.js?v=dc90522c"></script> |
| <script>window.MathJax = {"tex": {"maxBuffer": 30720, "macros": {"multicolumn": ["", 2]}}}</script> |
| <script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script> |
| <link rel="index" title="Index" href="genindex.html" /> |
| <link rel="search" title="Search" href="search.html" /> |
| |
| <link rel="stylesheet" href="_static/custom.css" type="text/css" /> |
| |
| |
| |
| |
| |
| </head><body> |
| |
| |
| <div class="document"> |
| <div class="documentwrapper"> |
| |
| |
| <div class="body" role="main"> |
| |
| <section id="nanowasm"> |
| <h1>NanoWasm<a class="headerlink" href="#nanowasm" title="Link to this heading">¶</a></h1> |
| <p><em>NanoWasm</em> is a small language with simple types and instructions.</p> |
| <section id="abstract-syntax"> |
| <h2>Abstract Syntax<a class="headerlink" href="#abstract-syntax" title="Link to this heading">¶</a></h2> |
| <p>The <em>abstract syntax</em> of types is as follows:</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}} |
| & {\mathit{mut}} & ::= & \mathsf{mut} \\[0.8ex] |
| & {\mathit{valtype}} & ::= & \mathsf{i{\scriptstyle 32}} ~~|~~ \mathsf{i{\scriptstyle 64}} ~~|~~ \mathsf{f{\scriptstyle 32}} ~~|~~ \mathsf{f{\scriptstyle 64}} \\[0.8ex] |
| & {\mathit{functype}} & ::= & {{\mathit{valtype}}^\ast} \rightarrow {{\mathit{valtype}}^\ast} \\[0.8ex] |
| & {\mathit{globaltype}} & ::= & {{\mathit{mut}}^?}~{\mathit{valtype}} \\ |
| \end{array}\end{split}\]</div> |
| <p>Instructions take the following form:</p> |
| <div class="math notranslate nohighlight" id="syntax-i32"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}} |
| & {\mathit{const}} & ::= & 0 ~~|~~ 1 ~~|~~ 2 ~~|~~ \dots \\[0.8ex] |
| & {\mathit{instr}} & ::= & \mathsf{nop} \\ |
| & & | & \mathsf{drop} \\ |
| & & | & \mathsf{select} \\ |
| & & | & {\mathit{valtype}}{.}\mathsf{const}~{\mathit{const}} \\ |
| & & | & \mathsf{local{.}get}~{\mathit{localidx}} \\ |
| & & | & \mathsf{local{.}set}~{\mathit{localidx}} \\ |
| & & | & \mathsf{global{.}get}~{\mathit{globalidx}} \\ |
| & & | & \mathsf{global{.}set}~{\mathit{globalidx}} \\ |
| \end{array}\end{split}\]</div> |
| <p>The instruction <span class="math notranslate nohighlight">\(\mathsf{nop}\)</span> does nothing, |
| <span class="math notranslate nohighlight">\(\mathsf{drop}\)</span> removes an operand from the stack, |
| <span class="math notranslate nohighlight">\(\mathsf{select}\)</span> picks one of two operands depending on a condition value. |
| The instruction <span class="math notranslate nohighlight">\(t{.}\mathsf{const}~c\)</span> pushed the constant <span class="math notranslate nohighlight">\(c\)</span> to the stack. |
| The remaining instructions access local and global variables.</p> |
| </section> |
| <section id="validation"> |
| <h2>Validation<a class="headerlink" href="#validation" title="Link to this heading">¶</a></h2> |
| <p>NanoWasm instructions are <em>type-checked</em> under a context that assigns types to indices:</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}} |
| & {\mathit{context}} & ::= & \{ \begin{array}[t]{@{}l@{}l@{}} |
| \mathsf{globals}~{{\mathit{globaltype}}^\ast} , \mathsf{locals}~{{\mathit{valtype}}^\ast} \} \\ |
| \end{array} \\ |
| \end{array}\end{split}\]</div> |
| <section id="mathsf-nop"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{nop}\)</span><a class="headerlink" href="#mathsf-nop" title="Link to this heading">¶</a></h3> |
| <p><span class="math notranslate nohighlight">\(\mathsf{nop}\)</span> is <a class="reference internal" href="#valid-val"><span class="std std-ref">valid</span></a> with <span class="math notranslate nohighlight">\(\epsilon~\rightarrow~\epsilon\)</span>.</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{array}{@{}c@{}}\displaystyle |
| \frac{ |
| }{ |
| C \vdash \mathsf{nop} : \epsilon \rightarrow \epsilon |
| } |
| \qquad |
| \end{array}\]</div> |
| </section> |
| <section id="mathsf-drop"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{drop}\)</span><a class="headerlink" href="#mathsf-drop" title="Link to this heading">¶</a></h3> |
| <p><span class="math notranslate nohighlight">\(\mathsf{drop}\)</span> is <a class="reference internal" href="#valid-val"><span class="std std-ref">valid</span></a> with <span class="math notranslate nohighlight">\(t~\rightarrow~\epsilon\)</span>.</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{array}{@{}c@{}}\displaystyle |
| \frac{ |
| }{ |
| C \vdash \mathsf{drop} : t \rightarrow \epsilon |
| } |
| \qquad |
| \end{array}\]</div> |
| </section> |
| <section id="mathsf-select"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{select}\)</span><a class="headerlink" href="#mathsf-select" title="Link to this heading">¶</a></h3> |
| <p><span class="math notranslate nohighlight">\(\mathsf{select}\)</span> is <a class="reference internal" href="#valid-val"><span class="std std-ref">valid</span></a> with <span class="math notranslate nohighlight">\(t~t~\mathsf{i{\scriptstyle 32}}~\rightarrow~t\)</span>.</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{array}{@{}c@{}}\displaystyle |
| \frac{ |
| }{ |
| C \vdash \mathsf{select} : t~t~\mathsf{i{\scriptstyle 32}} \rightarrow t |
| } |
| \qquad |
| \end{array}\]</div> |
| </section> |
| <section id="mathsf-const"> |
| <span id="valid-val"></span><h3><span class="math notranslate nohighlight">\(\mathsf{const}\)</span><a class="headerlink" href="#mathsf-const" title="Link to this heading">¶</a></h3> |
| <p><span class="math notranslate nohighlight">\((t{.}\mathsf{const}~c)\)</span> is <a class="reference internal" href="#valid-val"><span class="std std-ref">valid</span></a> with <span class="math notranslate nohighlight">\(\epsilon~\rightarrow~t\)</span>.</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{array}{@{}c@{}}\displaystyle |
| \frac{ |
| }{ |
| C \vdash t{.}\mathsf{const}~c : \epsilon \rightarrow t |
| } |
| \qquad |
| \end{array}\]</div> |
| </section> |
| <section id="mathsf-local-get"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{local{.}get}\)</span><a class="headerlink" href="#mathsf-local-get" title="Link to this heading">¶</a></h3> |
| <p><span class="math notranslate nohighlight">\((\mathsf{local{.}get}~x)\)</span> is <a class="reference internal" href="#valid-val"><span class="std std-ref">valid</span></a> with <span class="math notranslate nohighlight">\(\epsilon~\rightarrow~t\)</span> if:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li><p><span class="math notranslate nohighlight">\(C{.}\mathsf{locals}{}[x]\)</span> exists.</p></li> |
| <li><p><span class="math notranslate nohighlight">\(C{.}\mathsf{locals}{}[x]\)</span> is of the form <span class="math notranslate nohighlight">\(t\)</span>.</p></li> |
| </ul> |
| </div></blockquote> |
| <div class="math notranslate nohighlight"> |
| \[\begin{array}{@{}c@{}}\displaystyle |
| \frac{ |
| C{.}\mathsf{locals}{}[x] = t |
| }{ |
| C \vdash \mathsf{local{.}get}~x : \epsilon \rightarrow t |
| } |
| \qquad |
| \end{array}\]</div> |
| </section> |
| <section id="mathsf-local-set"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{local{.}set}\)</span><a class="headerlink" href="#mathsf-local-set" title="Link to this heading">¶</a></h3> |
| <p><span class="math notranslate nohighlight">\((\mathsf{local{.}set}~x)\)</span> is <a class="reference internal" href="#valid-val"><span class="std std-ref">valid</span></a> with <span class="math notranslate nohighlight">\(t~\rightarrow~\epsilon\)</span> if:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li><p><span class="math notranslate nohighlight">\(C{.}\mathsf{locals}{}[x]\)</span> exists.</p></li> |
| <li><p><span class="math notranslate nohighlight">\(C{.}\mathsf{locals}{}[x]\)</span> is of the form <span class="math notranslate nohighlight">\(t\)</span>.</p></li> |
| </ul> |
| </div></blockquote> |
| <div class="math notranslate nohighlight"> |
| \[\begin{array}{@{}c@{}}\displaystyle |
| \frac{ |
| C{.}\mathsf{locals}{}[x] = t |
| }{ |
| C \vdash \mathsf{local{.}set}~x : t \rightarrow \epsilon |
| } |
| \qquad |
| \end{array}\]</div> |
| </section> |
| <section id="mathsf-global-get"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{global{.}get}\)</span><a class="headerlink" href="#mathsf-global-get" title="Link to this heading">¶</a></h3> |
| <p><span class="math notranslate nohighlight">\((\mathsf{global{.}get}~x)\)</span> is <a class="reference internal" href="#valid-val"><span class="std std-ref">valid</span></a> with <span class="math notranslate nohighlight">\(\epsilon~\rightarrow~t\)</span> if:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li><p><span class="math notranslate nohighlight">\(C{.}\mathsf{globals}{}[x]\)</span> exists.</p></li> |
| <li><p><span class="math notranslate nohighlight">\(C{.}\mathsf{globals}{}[x]\)</span> is of the form <span class="math notranslate nohighlight">\(({\mathsf{mut}^?}~t)\)</span>.</p></li> |
| </ul> |
| </div></blockquote> |
| <div class="math notranslate nohighlight"> |
| \[\begin{array}{@{}c@{}}\displaystyle |
| \frac{ |
| C{.}\mathsf{globals}{}[x] = {\mathsf{mut}^?}~t |
| }{ |
| C \vdash \mathsf{global{.}get}~x : \epsilon \rightarrow t |
| } |
| \qquad |
| \end{array}\]</div> |
| </section> |
| <section id="mathsf-global-set"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{global{.}set}\)</span><a class="headerlink" href="#mathsf-global-set" title="Link to this heading">¶</a></h3> |
| <p><span class="math notranslate nohighlight">\((\mathsf{global{.}get}~x)\)</span> is <a class="reference internal" href="#valid-val"><span class="std std-ref">valid</span></a> with <span class="math notranslate nohighlight">\(t~\rightarrow~\epsilon\)</span> if:</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li><p><span class="math notranslate nohighlight">\(C{.}\mathsf{globals}{}[x]\)</span> exists.</p></li> |
| <li><p><span class="math notranslate nohighlight">\(C{.}\mathsf{globals}{}[x]\)</span> is of the form <span class="math notranslate nohighlight">\((\mathsf{mut}~t)\)</span>.</p></li> |
| </ul> |
| </div></blockquote> |
| <div class="math notranslate nohighlight"> |
| \[\begin{array}{@{}c@{}}\displaystyle |
| \frac{ |
| C{.}\mathsf{globals}{}[x] = \mathsf{mut}~t |
| }{ |
| C \vdash \mathsf{global{.}get}~x : t \rightarrow \epsilon |
| } |
| \qquad |
| \end{array}\]</div> |
| </section> |
| </section> |
| <section id="execution"> |
| <h2>Execution<a class="headerlink" href="#execution" title="Link to this heading">¶</a></h2> |
| <p>NanoWasm execution requires a suitable definition of state and configuration:</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}} |
| & {\mathit{addr}} & ::= & 0 ~~|~~ 1 ~~|~~ 2 ~~|~~ \dots \\ |
| & {\mathit{moduleinst}} & ::= & \{ \begin{array}[t]{@{}l@{}l@{}} |
| \mathsf{globals}~{{\mathit{addr}}^\ast} \} \\ |
| \end{array} \\[0.8ex] |
| & {\mathit{val}} & ::= & \mathsf{const}~{\mathit{valtype}}~{\mathit{const}} \\[0.8ex] |
| & {\mathit{store}} & ::= & \{ \begin{array}[t]{@{}l@{}l@{}} |
| \mathsf{globals}~{{\mathit{val}}^\ast} \} \\ |
| \end{array} \\ |
| & {\mathit{frame}} & ::= & \{ \begin{array}[t]{@{}l@{}l@{}} |
| \mathsf{locals}~{{\mathit{val}}^\ast} , \mathsf{module}~{\mathit{moduleinst}} \} \\ |
| \end{array} \\ |
| & {\mathit{state}} & ::= & {\mathit{store}} ; {\mathit{frame}} \\ |
| & {\mathit{config}} & ::= & {\mathit{state}} ; {{\mathit{instr}}^\ast} \\ |
| \end{array}\end{split}\]</div> |
| <p>We define the following auxiliary functions for accessing and updating the state:</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}lcl@{}l@{}} |
| {\mathrm{local}}((s ; f), x) & = & f{.}\mathsf{locals}{}[x] \\ |
| {\mathrm{global}}((s ; f), x) & = & s{.}\mathsf{globals}{}[f{.}\mathsf{module}{.}\mathsf{globals}{}[x]] \\[0.8ex] |
| {\mathrm{update}}_{\mathit{local}}((s ; f), x, v) & = & s ; f{}[{.}\mathsf{locals}{}[x] = v] \\ |
| {\mathrm{update}}_{\mathit{global}}((s ; f), x, v) & = & s{}[{.}\mathsf{globals}{}[f{.}\mathsf{module}{.}\mathsf{globals}{}[x]] = v] ; f \\ |
| \end{array}\end{split}\]</div> |
| <p>With that, execution is defined as follows:</p> |
| <section id="id1"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{nop}\)</span><a class="headerlink" href="#id1" title="Link to this heading">¶</a></h3> |
| <ol class="arabic simple"> |
| <li><p>Do nothing.</p></li> |
| </ol> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rcl@{}l@{}} |
| & \mathsf{nop} & \hookrightarrow & \epsilon \\ |
| \end{array}\end{split}\]</div> |
| </section> |
| <section id="id2"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{drop}\)</span><a class="headerlink" href="#id2" title="Link to this heading">¶</a></h3> |
| <ol class="arabic simple"> |
| <li><p>Assert: Due to validation, a value is on the top of the stack.</p></li> |
| <li><p>Pop the value <span class="math notranslate nohighlight">\({\mathit{val}}\)</span> from the stack.</p></li> |
| </ol> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rcl@{}l@{}} |
| & {\mathit{val}}~\mathsf{drop} & \hookrightarrow & \epsilon \\ |
| \end{array}\end{split}\]</div> |
| </section> |
| <section id="id3"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{select}\)</span><a class="headerlink" href="#id3" title="Link to this heading">¶</a></h3> |
| <ol class="arabic simple"> |
| <li><p>Assert: Due to validation, a value of valtype <span class="math notranslate nohighlight">\(\mathsf{i{\scriptstyle 32}}\)</span> is on the top of the stack.</p></li> |
| <li><p>Pop the value <span class="math notranslate nohighlight">\((\mathsf{i{\scriptstyle 32}}{.}\mathsf{const}~c)\)</span> from the stack.</p></li> |
| <li><p>Assert: Due to validation, a value is on the top of the stack.</p></li> |
| <li><p>Pop the value <span class="math notranslate nohighlight">\({\mathit{val}}_2\)</span> from the stack.</p></li> |
| <li><p>Assert: Due to validation, a value is on the top of the stack.</p></li> |
| <li><p>Pop the value <span class="math notranslate nohighlight">\({\mathit{val}}_1\)</span> from the stack.</p></li> |
| <li><p>If <span class="math notranslate nohighlight">\(c \neq 0\)</span>, then:</p> |
| <ol class="loweralpha simple"> |
| <li><p>Push the value <span class="math notranslate nohighlight">\({\mathit{val}}_1\)</span> to the stack.</p></li> |
| </ol> |
| </li> |
| <li><p>Else:</p> |
| <ol class="loweralpha simple"> |
| <li><p>Push the value <span class="math notranslate nohighlight">\({\mathit{val}}_2\)</span> to the stack.</p></li> |
| </ol> |
| </li> |
| </ol> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rcl@{}l@{}} |
| & {\mathit{val}}_1~{\mathit{val}}_2~(\mathsf{i{\scriptstyle 32}}{.}\mathsf{const}~c)~\mathsf{select} & \hookrightarrow & {\mathit{val}}_1 & \quad \mbox{if}~ c \neq 0 \\[0.8ex] |
| & {\mathit{val}}_1~{\mathit{val}}_2~(\mathsf{i{\scriptstyle 32}}{.}\mathsf{const}~c)~\mathsf{select} & \hookrightarrow & {\mathit{val}}_2 & \quad \mbox{otherwise} \\ |
| \end{array}\end{split}\]</div> |
| </section> |
| <section id="mathsf-local-get-x"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{local{.}get}~x\)</span><a class="headerlink" href="#mathsf-local-get-x" title="Link to this heading">¶</a></h3> |
| <ol class="arabic simple"> |
| <li><p>Let <span class="math notranslate nohighlight">\(z\)</span> be the current state.</p></li> |
| <li><p>Let <span class="math notranslate nohighlight">\({\mathit{val}}\)</span> be <span class="math notranslate nohighlight">\({\mathrm{local}}(z, x)\)</span>.</p></li> |
| <li><p>Push the value <span class="math notranslate nohighlight">\({\mathit{val}}\)</span> to the stack.</p></li> |
| </ol> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rcl@{}l@{}} |
| & z ; (\mathsf{local{.}get}~x) & \hookrightarrow & z ; {\mathit{val}} & \quad \mbox{if}~ {\mathit{val}} = {\mathrm{local}}(z, x) \\ |
| \end{array}\end{split}\]</div> |
| </section> |
| <section id="mathsf-local-set-x"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{local{.}set}~x\)</span><a class="headerlink" href="#mathsf-local-set-x" title="Link to this heading">¶</a></h3> |
| <ol class="arabic simple"> |
| <li><p>Assert: Due to validation, a value is on the top of the stack.</p></li> |
| <li><p>Pop the value <span class="math notranslate nohighlight">\({\mathit{val}}\)</span> from the stack.</p></li> |
| </ol> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rcl@{}l@{}} |
| & z ; {\mathit{val}}~(\mathsf{local{.}set}~x) & \hookrightarrow & {z'} ; \epsilon & \quad \mbox{if}~ {z'} = {\mathrm{update}}_{\mathit{local}}(z, x, {\mathit{val}}) \\ |
| \end{array}\end{split}\]</div> |
| </section> |
| <section id="mathsf-global-get-x"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{global{.}get}~x\)</span><a class="headerlink" href="#mathsf-global-get-x" title="Link to this heading">¶</a></h3> |
| <ol class="arabic simple"> |
| <li><p>Let <span class="math notranslate nohighlight">\(z\)</span> be the current state.</p></li> |
| <li><p>Let <span class="math notranslate nohighlight">\({\mathit{val}}\)</span> be <span class="math notranslate nohighlight">\({\mathrm{global}}(z, x)\)</span>.</p></li> |
| <li><p>Push the value <span class="math notranslate nohighlight">\({\mathit{val}}\)</span> to the stack.</p></li> |
| </ol> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rcl@{}l@{}} |
| & z ; (\mathsf{global{.}get}~x) & \hookrightarrow & z ; {\mathit{val}} & \quad \mbox{if}~ {\mathit{val}} = {\mathrm{global}}(z, x) \\ |
| \end{array}\end{split}\]</div> |
| </section> |
| <section id="mathsf-global-set-x"> |
| <h3><span class="math notranslate nohighlight">\(\mathsf{global{.}set}~x\)</span><a class="headerlink" href="#mathsf-global-set-x" title="Link to this heading">¶</a></h3> |
| <ol class="arabic simple"> |
| <li><p>Assert: Due to validation, a value is on the top of the stack.</p></li> |
| <li><p>Pop the value <span class="math notranslate nohighlight">\({\mathit{val}}\)</span> from the stack.</p></li> |
| </ol> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rcl@{}l@{}} |
| & z ; {\mathit{val}}~(\mathsf{global{.}set}~x) & \hookrightarrow & {z'} ; \epsilon & \quad \mbox{if}~ {z'} = {\mathrm{update}}_{\mathit{global}}(z, x, {\mathit{val}}) \\ |
| \end{array}\end{split}\]</div> |
| </section> |
| </section> |
| <section id="binary-format"> |
| <h2>Binary Format<a class="headerlink" href="#binary-format" title="Link to this heading">¶</a></h2> |
| <p>The following grammars define the binary representation of NanoWasm programs.</p> |
| <p>First, constants are represented in LEB format:</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} |
| & {\mathtt{byte}} & ::= & \mathtt{0x00} ~~|~~ \ldots ~~|~~ \mathtt{0xFF} \\[0.8ex] |
| & {\mathtt{u}}(N) & ::= & n{:}{\mathtt{byte}} & \quad\Rightarrow\quad{} & n & \quad \mbox{if}~ n < {2^{7}} \land n < {2^{N}} \\ |
| & & | & n{:}{\mathtt{byte}}~~m{:}{\mathtt{u}}(N - 7) & \quad\Rightarrow\quad{} & {2^{7}} \cdot m + (n - {2^{7}}) & \quad \mbox{if}~ n \geq {2^{7}} \land N > 7 \\[0.8ex] |
| & {\mathtt{u32}} & ::= & {\mathtt{u}}(32) \\ |
| & {\mathtt{u64}} & ::= & {\mathtt{u}}(64) \\[0.8ex] |
| & {\mathtt{f}}(N) & ::= & {b^\ast}{:}{{\mathtt{byte}}^{N / 8}} & \quad\Rightarrow\quad{} & {\mathrm{float}}(N, {b^\ast}) \\[0.8ex] |
| & {\mathtt{f32}} & ::= & {\mathtt{f}}(32) \\ |
| & {\mathtt{f64}} & ::= & {\mathtt{f}}(64) \\ |
| \end{array}\end{split}\]</div> |
| <p>Types are encoded as follows:</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} |
| & {\mathtt{valtype}} & ::= & \mathtt{0x7F} & \quad\Rightarrow\quad{} & \mathsf{i{\scriptstyle 32}} \\ |
| & & | & \mathtt{0x7E} & \quad\Rightarrow\quad{} & \mathsf{i{\scriptstyle 64}} \\ |
| & & | & \mathtt{0x7D} & \quad\Rightarrow\quad{} & \mathsf{f{\scriptstyle 32}} \\ |
| & & | & \mathtt{0x7C} & \quad\Rightarrow\quad{} & \mathsf{f{\scriptstyle 64}} \\[0.8ex] |
| & {\mathtt{mut}} & ::= & \mathtt{0x00} & \quad\Rightarrow\quad{} & \epsilon \\ |
| & & | & \mathtt{0x01} & \quad\Rightarrow\quad{} & \mathsf{mut} \\[0.8ex] |
| & {\mathtt{globaltype}} & ::= & t{:}{\mathtt{valtype}}~~{\mathit{mut}}{:}{\mathtt{mut}} & \quad\Rightarrow\quad{} & {\mathit{mut}}~t \\ |
| & {\mathtt{resulttype}} & ::= & n{:}{\mathtt{u32}}~~{(t{:}{\mathtt{valtype}})^{n}} & \quad\Rightarrow\quad{} & {t^{n}} \\ |
| & {\mathtt{functype}} & ::= & \mathtt{0x60}~~{t_1^\ast}{:}{\mathtt{resulttype}}~~{t_2^\ast}{:}{\mathtt{resulttype}} & \quad\Rightarrow\quad{} & {t_1^\ast} \rightarrow {t_2^\ast} \\ |
| \end{array}\end{split}\]</div> |
| <p>Finally, instruction opcodes:</p> |
| <div class="math notranslate nohighlight"> |
| \[\begin{split}\begin{array}[t]{@{}l@{}rrl@{}l@{}l@{}l@{}} |
| & {\mathtt{globalidx}} & ::= & x{:}{\mathtt{u32}} & \quad\Rightarrow\quad{} & x \\ |
| & {\mathtt{localidx}} & ::= & x{:}{\mathtt{u32}} & \quad\Rightarrow\quad{} & x \\[0.8ex] |
| & {\mathtt{instr}} & ::= & \mathtt{0x01} & \quad\Rightarrow\quad{} & \mathsf{nop} \\ |
| & & | & \mathtt{0x1A} & \quad\Rightarrow\quad{} & \mathsf{drop} \\ |
| & & | & \mathtt{0x1B} & \quad\Rightarrow\quad{} & \mathsf{select} \\ |
| & & | & \mathtt{0x20}~~x{:}{\mathtt{localidx}} & \quad\Rightarrow\quad{} & \mathsf{local{.}get}~x \\ |
| & & | & \mathtt{0x21}~~x{:}{\mathtt{localidx}} & \quad\Rightarrow\quad{} & \mathsf{local{.}set}~x \\ |
| & & | & \mathtt{0x23}~~x{:}{\mathtt{globalidx}} & \quad\Rightarrow\quad{} & \mathsf{global{.}get}~x \\ |
| & & | & \mathtt{0x24}~~x{:}{\mathtt{globalidx}} & \quad\Rightarrow\quad{} & \mathsf{global{.}set}~x \\ |
| & & | & \mathtt{0x41}~~n{:}{\mathtt{u32}} & \quad\Rightarrow\quad{} & \mathsf{i{\scriptstyle 32}}{.}\mathsf{const}~n \\ |
| & & | & \mathtt{0x42}~~n{:}{\mathtt{u64}} & \quad\Rightarrow\quad{} & \mathsf{i{\scriptstyle 64}}{.}\mathsf{const}~n \\ |
| & & | & \mathtt{0x43}~~p{:}{\mathtt{f32}} & \quad\Rightarrow\quad{} & \mathsf{f{\scriptstyle 32}}{.}\mathsf{const}~p \\ |
| & & | & \mathtt{0x44}~~p{:}{\mathtt{f64}} & \quad\Rightarrow\quad{} & \mathsf{f{\scriptstyle 64}}{.}\mathsf{const}~p \\ |
| \end{array}\end{split}\]</div> |
| </section> |
| </section> |
| |
| |
| </div> |
| |
| </div> |
| <div class="clearer"></div> |
| </div> |
| <div class="footer"> |
| ©. |
| |
| | |
| Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.2.3</a> |
| & <a href="https://alabaster.readthedocs.io">Alabaster 1.0.0</a> |
| |
| | |
| <a href="_sources/NanoWasm.rst.txt" |
| rel="nofollow">Page source</a> |
| </div> |
| |
| |
| |
| |
| </body> |
| </html> |