├── .eslintrc ├── .gitignore ├── .gitmodules ├── .travis.yml ├── LICENSE ├── README.md ├── appveyor.yml ├── bin ├── wast-parser.js └── wast2ast.js ├── package.json ├── results-extra └── wast-parser-22.js ├── results ├── .gitignore ├── address.js ├── align.js ├── binary.js ├── br.js ├── br_if.js ├── br_table.js ├── break-drop.js ├── call.js ├── comments.js ├── conversions.js ├── custom.js ├── custom_section.js ├── endianness.js ├── f32.js ├── f32_bitwise.js ├── f32_cmp.js ├── f64.js ├── f64_bitwise.js ├── f64_cmp.js ├── fac.js ├── float_literals.js ├── float_memory.js ├── float_misc.js ├── forward.js ├── get_local.js ├── globals.js ├── i32.js ├── i64.js ├── inline-module.js ├── int_exprs.js ├── int_literals.js ├── labels.js ├── left-to-right.js ├── memory.js ├── memory_grow.js ├── memory_redundancy.js ├── memory_trap.js ├── names.js ├── resizing.js ├── return.js ├── select.js ├── set_local.js ├── skip-stack-guard-page.js ├── start.js ├── store_retval.js ├── switch.js ├── tee_local.js ├── token.js ├── traps.js ├── typecheck.js ├── unreachable.js ├── unwind.js ├── utf8-custom-section-id.js ├── utf8-import-field.js ├── utf8-import-module.js └── utf8-invalid-encoding.js ├── test └── test.js ├── testsuite-extra └── wast-parser-22.wast └── wast.pegjs /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | env: { 3 | node: true 4 | }, 5 | rules: { 6 | strict: [2, 'global'], 7 | semi: [2, 'always'], 8 | quotes: [1, 'single'], 9 | no-mixed-requires: 1, 10 | no-unused-vars: 1, 11 | camelcase: 0, 12 | key-spacing: 0, 13 | no-multi-spaces: 0, 14 | no-eval: 1, 15 | no-shadow: 1, 16 | new-cap: 1 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | package-lock.json 3 | index.js 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "testsuite"] 2 | path = testsuite 3 | url = https://github.com/WebAssembly/testsuite.git 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | os: 2 | - linux 3 | - osx 4 | sudo: false 5 | env: 6 | matrix: 7 | - TRAVIS_NODE_VERSION="10" 8 | - TRAVIS_NODE_VERSION="9" 9 | - TRAVIS_NODE_VERSION="8" 10 | - TRAVIS_NODE_VERSION="7" 11 | - TRAVIS_NODE_VERSION="6" 12 | - TRAVIS_NODE_VERSION="5" 13 | - TRAVIS_NODE_VERSION="4" 14 | install: 15 | - rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION 16 | - npm --version 17 | - npm install 18 | script: npm test 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2018 Aliaksei Chapyzhenka 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebAssembly parser 2 | [![NPM version](https://img.shields.io/npm/v/wast-parser.svg)](https://www.npmjs.org/package/wast-parser) 3 | [![Travis](https://travis-ci.org/drom/wast-parser.svg)](https://travis-ci.org/drom/wast-parser) 4 | [![appVeyor](https://ci.appveyor.com/api/projects/status/vg09awtk5rgargkb?svg=true)](https://ci.appveyor.com/project/drom/wast-parser) 5 | 6 | Takes WebAssembly S-expression (WAST) string and returns abstract syntax tree ([AST](https://github.com/drom/wast-spec)). 7 | 8 | Inspired by [esprima](https://github.com/jquery/esprima) 9 | 10 | ## Use 11 | ### Node.js 12 | 13 | ``` 14 | npm i wast-parser --save 15 | ``` 16 | 17 | ```js 18 | var parser = require('wast-parser'); 19 | ``` 20 | 21 | ### CLI 22 | First install globally `npm i wast-parser -g` 23 | then invoke with a wast file `wast-parser > parsed_wast.json` 24 | 25 | ## Functions 26 | ### .parse() 27 | 28 | ```js 29 | var ast = parser.parse('(module)'); 30 | ``` 31 | 32 | ## Testing 33 | `npm test` 34 | 35 | ## Generating tests 36 | `npm run testgen` 37 | 38 | ## License 39 | MIT [LICENSE](https://github.com/drom/wast-parser/blob/master/LICENSE). 40 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - nodejs_version: 10.2.1 4 | - nodejs_version: 9 5 | - nodejs_version: 8 6 | - nodejs_version: 7 7 | - nodejs_version: 6 8 | - nodejs_version: 5 9 | - nodejs_version: 4 10 | 11 | install: 12 | - ps: Install-Product node $env:nodejs_version 13 | - npm install 14 | 15 | test_script: 16 | - node --version 17 | - npm --version 18 | - npm test 19 | 20 | build: off 21 | -------------------------------------------------------------------------------- /bin/wast-parser.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict' 3 | 4 | const fs = require('fs') 5 | const parser = require('../') 6 | 7 | const filename = process.argv.splice(2)[0] 8 | const file = fs.readFileSync(filename) 9 | const json = parser.parse(file.toString()) 10 | 11 | process.stdout.write(JSON.stringify(json)) 12 | -------------------------------------------------------------------------------- /bin/wast2ast.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | var fs = require('fs'), 6 | path = require('path'), 7 | jsof = require('jsof'), 8 | parser = require('../'); 9 | 10 | function runner (name, dst, report) { 11 | return function (err, data) { 12 | var result; 13 | if (err) { throw err; } 14 | try { 15 | result = parser.parse(data); 16 | } catch (err1) { 17 | console.log('\x1b[31m' + name + '\x1b[0m'); 18 | console.log(err1); 19 | report.fail++; 20 | return; 21 | } 22 | console.log('\x1b[32m' + name + '\x1b[0m'); 23 | fs.writeFile( 24 | path.resolve(dst, name + '.js'), 25 | jsof.s(result) + '\n', 26 | function (err2) { 27 | if (err2) { throw err2; } 28 | report.pass++; 29 | } 30 | ); 31 | }; 32 | } 33 | 34 | var report = { pass: 0, fail: 0 }; 35 | 36 | [ 37 | { src: '../testsuite/', dst: '../results/' }, 38 | { src: '../testsuite-extra/', dst: '../results-extra/' } 39 | ] 40 | .map(function (job) { 41 | return { 42 | src: path.resolve(__dirname, job.src), 43 | dst: path.resolve(__dirname, job.dst) 44 | }; 45 | }) 46 | .map(function (job) { 47 | return { 48 | src: job.src, 49 | dst: job.dst, 50 | files: ( 51 | fs.readdirSync(job.src) 52 | .filter(function (fileName) { 53 | return fileName.match('^(.*).wast$'); 54 | }) 55 | ) 56 | }; 57 | }) 58 | .forEach(function (job) { 59 | job.files.forEach(function (wastFileName) { 60 | var matchArr = wastFileName.match('^(.*).wast$'); 61 | fs.readFile( 62 | path.resolve(job.src, wastFileName), 63 | 'utf8', 64 | runner(matchArr[1], job.dst, report) 65 | ); 66 | }); 67 | }); 68 | 69 | process.on('exit', function () { 70 | console.log('\x1b[32mpass: ' + report.pass + '\x1b[0m / \x1b[31mfail: ' + report.fail + '\x1b[0m'); 71 | }); 72 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wast-parser", 3 | "version": "0.33.0", 4 | "description": "wast parser", 5 | "main": "index.js", 6 | "files": [ 7 | "index.js", 8 | "bin/wast-parser.js" 9 | ], 10 | "scripts": { 11 | "test": "git submodule init && git submodule update --remote && git submodule status && mocha --timeout 5000 test", 12 | "testgen": "bin/wast2ast.js", 13 | "prepublish": "pegjs -o index.js wast.pegjs" 14 | }, 15 | "bin": { 16 | "wast-parser": "./bin/wast-parser.js" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git+https://github.com/drom/wast-parser.git" 21 | }, 22 | "keywords": [ 23 | "wasm", 24 | "wast" 25 | ], 26 | "author": "drom@drom.io", 27 | "license": "MIT", 28 | "bugs": { 29 | "url": "https://github.com/drom/wast-parser/issues" 30 | }, 31 | "homepage": "https://github.com/drom/wast-parser#readme", 32 | "devDependencies": { 33 | "chai": "^4.1.2", 34 | "eslint": "^5.4.0", 35 | "jsof": "^0.3.2", 36 | "mocha": "^5.2.0", 37 | "pegjs": "^0.10.0" 38 | }, 39 | "dependencies": {} 40 | } 41 | -------------------------------------------------------------------------------- /results-extra/wast-parser-22.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [{ 4 | kind: 'module', 5 | body: [ 6 | { 7 | kind: 'export', 8 | name: { 9 | kind: 'literal', 10 | value: 'add' 11 | }, 12 | id: { 13 | kind: 'identifier', 14 | name: 'add' 15 | } 16 | }, 17 | { 18 | kind: 'func', 19 | id: { 20 | kind: 'identifier', 21 | name: 'add' 22 | }, 23 | expos: [], 24 | imp: null, 25 | type: null, 26 | params: [ 27 | { 28 | kind: 'param', 29 | id: { 30 | kind: 'identifier', 31 | name: 'x' 32 | }, 33 | items: [{ 34 | kind: 'item', 35 | type: 'f64' 36 | }] 37 | }, 38 | { 39 | kind: 'param', 40 | id: { 41 | kind: 'identifier', 42 | name: 'y' 43 | }, 44 | items: [{ 45 | kind: 'item', 46 | type: 'f64' 47 | }] 48 | } 49 | ], 50 | result: { 51 | kind: 'result', 52 | type: 'f64' 53 | }, 54 | local: [], 55 | body: [{ 56 | kind: 'binop', 57 | type: 'f64', 58 | operator: 'add', 59 | left: { 60 | kind: 'get_local', 61 | id: { 62 | kind: 'identifier', 63 | name: 'x' 64 | } 65 | }, 66 | right: { 67 | kind: 'get_local', 68 | id: { 69 | kind: 'identifier', 70 | name: 'y' 71 | } 72 | } 73 | }] 74 | } 75 | ] 76 | }] 77 | } 78 | -------------------------------------------------------------------------------- /results/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /results/break-drop.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'module', 6 | body: [ 7 | { 8 | kind: 'func', 9 | id: null, 10 | expos: [{ 11 | kind: 'literal', 12 | value: 'br' 13 | }], 14 | imp: null, 15 | type: null, 16 | params: [], 17 | result: null, 18 | local: [], 19 | body: [{ 20 | kind: 'block', 21 | result: null, 22 | id: null, 23 | body: [{ 24 | kind: 'br', 25 | id: { 26 | kind: 'literal', 27 | value: 0, 28 | raw: '0' 29 | }, 30 | expr: null 31 | }] 32 | }] 33 | }, 34 | { 35 | kind: 'func', 36 | id: null, 37 | expos: [{ 38 | kind: 'literal', 39 | value: 'br_if' 40 | }], 41 | imp: null, 42 | type: null, 43 | params: [], 44 | result: null, 45 | local: [], 46 | body: [{ 47 | kind: 'block', 48 | result: null, 49 | id: null, 50 | body: [{ 51 | kind: 'br_if', 52 | id: { 53 | kind: 'literal', 54 | value: 0, 55 | raw: '0' 56 | }, 57 | test: { 58 | kind: 'const', 59 | type: 'i32', 60 | init: '1' 61 | }, 62 | expr: null 63 | }] 64 | }] 65 | }, 66 | { 67 | kind: 'func', 68 | id: null, 69 | expos: [{ 70 | kind: 'literal', 71 | value: 'br_table' 72 | }], 73 | imp: null, 74 | type: null, 75 | params: [], 76 | result: null, 77 | local: [], 78 | body: [{ 79 | kind: 'block', 80 | result: null, 81 | id: null, 82 | body: [{ 83 | kind: 'br_table', 84 | exprs: [{ 85 | kind: 'const', 86 | type: 'i32', 87 | init: '0' 88 | }], 89 | body: [{ 90 | kind: 'literal', 91 | value: 0, 92 | raw: '0' 93 | }] 94 | }] 95 | }] 96 | } 97 | ] 98 | }, 99 | { 100 | kind: 'assert_return', 101 | invoke: { 102 | kind: 'invoke', 103 | id: null, 104 | name: 'br', 105 | body: [] 106 | }, 107 | expr: null 108 | }, 109 | { 110 | kind: 'assert_return', 111 | invoke: { 112 | kind: 'invoke', 113 | id: null, 114 | name: 'br_if', 115 | body: [] 116 | }, 117 | expr: null 118 | }, 119 | { 120 | kind: 'assert_return', 121 | invoke: { 122 | kind: 'invoke', 123 | id: null, 124 | name: 'br_table', 125 | body: [] 126 | }, 127 | expr: null 128 | } 129 | ] 130 | } 131 | -------------------------------------------------------------------------------- /results/comments.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'module', 6 | body: [] 7 | }, 8 | { 9 | kind: 'module', 10 | body: [] 11 | }, 12 | { 13 | kind: 'module', 14 | body: [] 15 | }, 16 | { 17 | kind: 'module', 18 | body: [] 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /results/custom.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'module', 6 | body: [ 7 | 'binary', 8 | { 9 | kind: 'literal', 10 | value: '\\00asm' 11 | }, 12 | { 13 | kind: 'literal', 14 | value: '\\01\\00\\00\\00' 15 | }, 16 | { 17 | kind: 'literal', 18 | value: '\\00\\24\\10' 19 | }, 20 | { 21 | kind: 'literal', 22 | value: 'a custom section' 23 | }, 24 | { 25 | kind: 'literal', 26 | value: 'this is the payload' 27 | }, 28 | { 29 | kind: 'literal', 30 | value: '\\00\\20\\10' 31 | }, 32 | { 33 | kind: 'literal', 34 | value: 'a custom section' 35 | }, 36 | { 37 | kind: 'literal', 38 | value: 'this is payload' 39 | }, 40 | { 41 | kind: 'literal', 42 | value: '\\00\\11\\10' 43 | }, 44 | { 45 | kind: 'literal', 46 | value: 'a custom section' 47 | }, 48 | { 49 | kind: 'literal', 50 | value: '' 51 | }, 52 | { 53 | kind: 'literal', 54 | value: '\\00\\10\\00' 55 | }, 56 | { 57 | kind: 'literal', 58 | value: '' 59 | }, 60 | { 61 | kind: 'literal', 62 | value: 'this is payload' 63 | }, 64 | { 65 | kind: 'literal', 66 | value: '\\00\\01\\00' 67 | }, 68 | { 69 | kind: 'literal', 70 | value: '' 71 | }, 72 | { 73 | kind: 'literal', 74 | value: '' 75 | }, 76 | { 77 | kind: 'literal', 78 | value: '\\00\\24\\10' 79 | }, 80 | { 81 | kind: 'literal', 82 | value: '\\00\\00custom sectio\\00' 83 | }, 84 | { 85 | kind: 'literal', 86 | value: 'this is the payload' 87 | }, 88 | { 89 | kind: 'literal', 90 | value: '\\00\\24\\10' 91 | }, 92 | { 93 | kind: 'literal', 94 | value: '\\ef\\bb\\bfa custom sect' 95 | }, 96 | { 97 | kind: 'literal', 98 | value: 'this is the payload' 99 | }, 100 | { 101 | kind: 'literal', 102 | value: '\\00\\24\\10' 103 | }, 104 | { 105 | kind: 'literal', 106 | value: 'a custom sect\\e2\\8c\\a3' 107 | }, 108 | { 109 | kind: 'literal', 110 | value: 'this is the payload' 111 | }, 112 | { 113 | kind: 'literal', 114 | value: '\\00\\1f\\16' 115 | }, 116 | { 117 | kind: 'literal', 118 | value: 'module within a module' 119 | }, 120 | { 121 | kind: 'literal', 122 | value: '\\00asm' 123 | }, 124 | { 125 | kind: 'literal', 126 | value: '\\01\\00\\00\\00' 127 | } 128 | ] 129 | }, 130 | { 131 | kind: 'module', 132 | body: [ 133 | 'binary', 134 | { 135 | kind: 'literal', 136 | value: '\\00asm' 137 | }, 138 | { 139 | kind: 'literal', 140 | value: '\\01\\00\\00\\00' 141 | }, 142 | { 143 | kind: 'literal', 144 | value: '\\00\\0e\\06' 145 | }, 146 | { 147 | kind: 'literal', 148 | value: 'custom' 149 | }, 150 | { 151 | kind: 'literal', 152 | value: 'payload' 153 | }, 154 | { 155 | kind: 'literal', 156 | value: '\\00\\0e\\06' 157 | }, 158 | { 159 | kind: 'literal', 160 | value: 'custom' 161 | }, 162 | { 163 | kind: 'literal', 164 | value: 'payload' 165 | }, 166 | { 167 | kind: 'literal', 168 | value: '\\01\\01\\00' 169 | }, 170 | { 171 | kind: 'literal', 172 | value: '\\00\\0e\\06' 173 | }, 174 | { 175 | kind: 'literal', 176 | value: 'custom' 177 | }, 178 | { 179 | kind: 'literal', 180 | value: 'payload' 181 | }, 182 | { 183 | kind: 'literal', 184 | value: '\\00\\0e\\06' 185 | }, 186 | { 187 | kind: 'literal', 188 | value: 'custom' 189 | }, 190 | { 191 | kind: 'literal', 192 | value: 'payload' 193 | }, 194 | { 195 | kind: 'literal', 196 | value: '\\02\\01\\00' 197 | }, 198 | { 199 | kind: 'literal', 200 | value: '\\00\\0e\\06' 201 | }, 202 | { 203 | kind: 'literal', 204 | value: 'custom' 205 | }, 206 | { 207 | kind: 'literal', 208 | value: 'payload' 209 | }, 210 | { 211 | kind: 'literal', 212 | value: '\\00\\0e\\06' 213 | }, 214 | { 215 | kind: 'literal', 216 | value: 'custom' 217 | }, 218 | { 219 | kind: 'literal', 220 | value: 'payload' 221 | }, 222 | { 223 | kind: 'literal', 224 | value: '\\03\\01\\00' 225 | }, 226 | { 227 | kind: 'literal', 228 | value: '\\00\\0e\\06' 229 | }, 230 | { 231 | kind: 'literal', 232 | value: 'custom' 233 | }, 234 | { 235 | kind: 'literal', 236 | value: 'payload' 237 | }, 238 | { 239 | kind: 'literal', 240 | value: '\\00\\0e\\06' 241 | }, 242 | { 243 | kind: 'literal', 244 | value: 'custom' 245 | }, 246 | { 247 | kind: 'literal', 248 | value: 'payload' 249 | }, 250 | { 251 | kind: 'literal', 252 | value: '\\04\\01\\00' 253 | }, 254 | { 255 | kind: 'literal', 256 | value: '\\00\\0e\\06' 257 | }, 258 | { 259 | kind: 'literal', 260 | value: 'custom' 261 | }, 262 | { 263 | kind: 'literal', 264 | value: 'payload' 265 | }, 266 | { 267 | kind: 'literal', 268 | value: '\\00\\0e\\06' 269 | }, 270 | { 271 | kind: 'literal', 272 | value: 'custom' 273 | }, 274 | { 275 | kind: 'literal', 276 | value: 'payload' 277 | }, 278 | { 279 | kind: 'literal', 280 | value: '\\05\\01\\00' 281 | }, 282 | { 283 | kind: 'literal', 284 | value: '\\00\\0e\\06' 285 | }, 286 | { 287 | kind: 'literal', 288 | value: 'custom' 289 | }, 290 | { 291 | kind: 'literal', 292 | value: 'payload' 293 | }, 294 | { 295 | kind: 'literal', 296 | value: '\\00\\0e\\06' 297 | }, 298 | { 299 | kind: 'literal', 300 | value: 'custom' 301 | }, 302 | { 303 | kind: 'literal', 304 | value: 'payload' 305 | }, 306 | { 307 | kind: 'literal', 308 | value: '\\06\\01\\00' 309 | }, 310 | { 311 | kind: 'literal', 312 | value: '\\00\\0e\\06' 313 | }, 314 | { 315 | kind: 'literal', 316 | value: 'custom' 317 | }, 318 | { 319 | kind: 'literal', 320 | value: 'payload' 321 | }, 322 | { 323 | kind: 'literal', 324 | value: '\\00\\0e\\06' 325 | }, 326 | { 327 | kind: 'literal', 328 | value: 'custom' 329 | }, 330 | { 331 | kind: 'literal', 332 | value: 'payload' 333 | }, 334 | { 335 | kind: 'literal', 336 | value: '\\07\\01\\00' 337 | }, 338 | { 339 | kind: 'literal', 340 | value: '\\00\\0e\\06' 341 | }, 342 | { 343 | kind: 'literal', 344 | value: 'custom' 345 | }, 346 | { 347 | kind: 'literal', 348 | value: 'payload' 349 | }, 350 | { 351 | kind: 'literal', 352 | value: '\\00\\0e\\06' 353 | }, 354 | { 355 | kind: 'literal', 356 | value: 'custom' 357 | }, 358 | { 359 | kind: 'literal', 360 | value: 'payload' 361 | }, 362 | { 363 | kind: 'literal', 364 | value: '\\09\\01\\00' 365 | }, 366 | { 367 | kind: 'literal', 368 | value: '\\00\\0e\\06' 369 | }, 370 | { 371 | kind: 'literal', 372 | value: 'custom' 373 | }, 374 | { 375 | kind: 'literal', 376 | value: 'payload' 377 | }, 378 | { 379 | kind: 'literal', 380 | value: '\\00\\0e\\06' 381 | }, 382 | { 383 | kind: 'literal', 384 | value: 'custom' 385 | }, 386 | { 387 | kind: 'literal', 388 | value: 'payload' 389 | }, 390 | { 391 | kind: 'literal', 392 | value: '\\0a\\01\\00' 393 | }, 394 | { 395 | kind: 'literal', 396 | value: '\\00\\0e\\06' 397 | }, 398 | { 399 | kind: 'literal', 400 | value: 'custom' 401 | }, 402 | { 403 | kind: 'literal', 404 | value: 'payload' 405 | }, 406 | { 407 | kind: 'literal', 408 | value: '\\00\\0e\\06' 409 | }, 410 | { 411 | kind: 'literal', 412 | value: 'custom' 413 | }, 414 | { 415 | kind: 'literal', 416 | value: 'payload' 417 | }, 418 | { 419 | kind: 'literal', 420 | value: '\\0b\\01\\00' 421 | }, 422 | { 423 | kind: 'literal', 424 | value: '\\00\\0e\\06' 425 | }, 426 | { 427 | kind: 'literal', 428 | value: 'custom' 429 | }, 430 | { 431 | kind: 'literal', 432 | value: 'payload' 433 | }, 434 | { 435 | kind: 'literal', 436 | value: '\\00\\0e\\06' 437 | }, 438 | { 439 | kind: 'literal', 440 | value: 'custom' 441 | }, 442 | { 443 | kind: 'literal', 444 | value: 'payload' 445 | } 446 | ] 447 | }, 448 | { 449 | kind: 'module', 450 | body: [ 451 | 'binary', 452 | { 453 | kind: 'literal', 454 | value: '\\00asm' 455 | }, 456 | { 457 | kind: 'literal', 458 | value: '\\01\\00\\00\\00' 459 | }, 460 | { 461 | kind: 'literal', 462 | value: '\\01\\07\\01\\60\\02\\7f\\7f\\01\\7f' 463 | }, 464 | { 465 | kind: 'literal', 466 | value: '\\00\\1a\\06' 467 | }, 468 | { 469 | kind: 'literal', 470 | value: 'custom' 471 | }, 472 | { 473 | kind: 'literal', 474 | value: 'this is the payload' 475 | }, 476 | { 477 | kind: 'literal', 478 | value: '\\03\\02\\01\\00' 479 | }, 480 | { 481 | kind: 'literal', 482 | value: '\\07\\0a\\01\\06\\61\\64\\64\\54\\77\\6f\\00\\00' 483 | }, 484 | { 485 | kind: 'literal', 486 | value: '\\0a\\09\\01\\07\\00\\20\\00\\20\\01\\6a\\0b' 487 | }, 488 | { 489 | kind: 'literal', 490 | value: '\\00\\1b\\07' 491 | }, 492 | { 493 | kind: 'literal', 494 | value: 'custom2' 495 | }, 496 | { 497 | kind: 'literal', 498 | value: 'this is the payload' 499 | } 500 | ] 501 | }, 502 | { 503 | kind: 'assert_malformed', 504 | module: { 505 | kind: 'module', 506 | body: [ 507 | 'binary', 508 | { 509 | kind: 'literal', 510 | value: '\\00asm' 511 | }, 512 | { 513 | kind: 'literal', 514 | value: '\\01\\00\\00\\00' 515 | }, 516 | { 517 | kind: 'literal', 518 | value: '\\00' 519 | } 520 | ] 521 | }, 522 | failure: { 523 | kind: 'literal', 524 | value: 'unexpected end' 525 | } 526 | }, 527 | { 528 | kind: 'assert_malformed', 529 | module: { 530 | kind: 'module', 531 | body: [ 532 | 'binary', 533 | { 534 | kind: 'literal', 535 | value: '\\00asm' 536 | }, 537 | { 538 | kind: 'literal', 539 | value: '\\01\\00\\00\\00' 540 | }, 541 | { 542 | kind: 'literal', 543 | value: '\\00\\00' 544 | } 545 | ] 546 | }, 547 | failure: { 548 | kind: 'literal', 549 | value: 'unexpected end' 550 | } 551 | }, 552 | { 553 | kind: 'assert_malformed', 554 | module: { 555 | kind: 'module', 556 | body: [ 557 | 'binary', 558 | { 559 | kind: 'literal', 560 | value: '\\00asm' 561 | }, 562 | { 563 | kind: 'literal', 564 | value: '\\01\\00\\00\\00' 565 | }, 566 | { 567 | kind: 'literal', 568 | value: '\\00\\00\\00\\05\\01\\00\\07\\00\\00' 569 | } 570 | ] 571 | }, 572 | failure: { 573 | kind: 'literal', 574 | value: 'unexpected end' 575 | } 576 | }, 577 | { 578 | kind: 'assert_malformed', 579 | module: { 580 | kind: 'module', 581 | body: [ 582 | 'binary', 583 | { 584 | kind: 'literal', 585 | value: '\\00asm' 586 | }, 587 | { 588 | kind: 'literal', 589 | value: '\\01\\00\\00\\00' 590 | }, 591 | { 592 | kind: 'literal', 593 | value: '\\00\\26\\10' 594 | }, 595 | { 596 | kind: 'literal', 597 | value: 'a custom section' 598 | }, 599 | { 600 | kind: 'literal', 601 | value: 'this is the payload' 602 | } 603 | ] 604 | }, 605 | failure: { 606 | kind: 'literal', 607 | value: 'unexpected end' 608 | } 609 | }, 610 | { 611 | kind: 'assert_malformed', 612 | module: { 613 | kind: 'module', 614 | body: [ 615 | 'binary', 616 | { 617 | kind: 'literal', 618 | value: '\\00asm' 619 | }, 620 | { 621 | kind: 'literal', 622 | value: '\\01\\00\\00\\00' 623 | }, 624 | { 625 | kind: 'literal', 626 | value: '\\00\\25\\10' 627 | }, 628 | { 629 | kind: 'literal', 630 | value: 'a custom section' 631 | }, 632 | { 633 | kind: 'literal', 634 | value: 'this is the payload' 635 | }, 636 | { 637 | kind: 'literal', 638 | value: '\\00\\24\\10' 639 | }, 640 | { 641 | kind: 'literal', 642 | value: 'a custom section' 643 | }, 644 | { 645 | kind: 'literal', 646 | value: 'this is the payload' 647 | } 648 | ] 649 | }, 650 | failure: { 651 | kind: 'literal', 652 | value: 'invalid section id' 653 | } 654 | }, 655 | { 656 | kind: 'assert_malformed', 657 | module: { 658 | kind: 'module', 659 | body: [ 660 | 'binary', 661 | { 662 | kind: 'literal', 663 | value: '\\00asm' 664 | }, 665 | { 666 | kind: 'literal', 667 | value: '\\01\\00\\00\\00' 668 | }, 669 | { 670 | kind: 'literal', 671 | value: '\\01\\07\\01\\60\\02\\7f\\7f\\01\\7f' 672 | }, 673 | { 674 | kind: 'literal', 675 | value: '\\00\\25\\10' 676 | }, 677 | { 678 | kind: 'literal', 679 | value: 'a custom section' 680 | }, 681 | { 682 | kind: 'literal', 683 | value: 'this is the payload' 684 | }, 685 | { 686 | kind: 'literal', 687 | value: '\\03\\02\\01\\00' 688 | }, 689 | { 690 | kind: 'literal', 691 | value: '\\0a\\09\\01\\07\\00\\20\\00\\20\\01\\6a\\0b' 692 | }, 693 | { 694 | kind: 'literal', 695 | value: '\\00\\1b\\07' 696 | }, 697 | { 698 | kind: 'literal', 699 | value: 'custom2' 700 | }, 701 | { 702 | kind: 'literal', 703 | value: 'this is the payload' 704 | } 705 | ] 706 | }, 707 | failure: { 708 | kind: 'literal', 709 | value: 'function and code section have inconsistent lengths' 710 | } 711 | }, 712 | { 713 | kind: 'assert_malformed', 714 | module: { 715 | kind: 'module', 716 | body: [ 717 | 'binary', 718 | { 719 | kind: 'literal', 720 | value: '\\00asm\\01\\00\\00\\00' 721 | }, 722 | { 723 | kind: 'literal', 724 | value: '\\00asm\\01\\00\\00\\00' 725 | } 726 | ] 727 | }, 728 | failure: { 729 | kind: 'literal', 730 | value: 'length out of bounds' 731 | } 732 | } 733 | ] 734 | } 735 | -------------------------------------------------------------------------------- /results/custom_section.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'module', 6 | body: [ 7 | 'binary', 8 | { 9 | kind: 'literal', 10 | value: '\\00asm' 11 | }, 12 | { 13 | kind: 'literal', 14 | value: '\\01\\00\\00\\00' 15 | }, 16 | { 17 | kind: 'literal', 18 | value: '\\00\\24\\10' 19 | }, 20 | { 21 | kind: 'literal', 22 | value: 'a custom section' 23 | }, 24 | { 25 | kind: 'literal', 26 | value: 'this is the payload' 27 | }, 28 | { 29 | kind: 'literal', 30 | value: '\\00\\20\\10' 31 | }, 32 | { 33 | kind: 'literal', 34 | value: 'a custom section' 35 | }, 36 | { 37 | kind: 'literal', 38 | value: 'this is payload' 39 | }, 40 | { 41 | kind: 'literal', 42 | value: '\\00\\11\\10' 43 | }, 44 | { 45 | kind: 'literal', 46 | value: 'a custom section' 47 | }, 48 | { 49 | kind: 'literal', 50 | value: '' 51 | }, 52 | { 53 | kind: 'literal', 54 | value: '\\00\\10\\00' 55 | }, 56 | { 57 | kind: 'literal', 58 | value: '' 59 | }, 60 | { 61 | kind: 'literal', 62 | value: 'this is payload' 63 | }, 64 | { 65 | kind: 'literal', 66 | value: '\\00\\01\\00' 67 | }, 68 | { 69 | kind: 'literal', 70 | value: '' 71 | }, 72 | { 73 | kind: 'literal', 74 | value: '' 75 | }, 76 | { 77 | kind: 'literal', 78 | value: '\\00\\24\\10' 79 | }, 80 | { 81 | kind: 'literal', 82 | value: '\\00\\00custom sectio\\00' 83 | }, 84 | { 85 | kind: 'literal', 86 | value: 'this is the payload' 87 | }, 88 | { 89 | kind: 'literal', 90 | value: '\\00\\24\\10' 91 | }, 92 | { 93 | kind: 'literal', 94 | value: '\\ef\\bb\\bfa custom sect' 95 | }, 96 | { 97 | kind: 'literal', 98 | value: 'this is the payload' 99 | }, 100 | { 101 | kind: 'literal', 102 | value: '\\00\\24\\10' 103 | }, 104 | { 105 | kind: 'literal', 106 | value: 'a custom sect\\e2\\8c\\a3' 107 | }, 108 | { 109 | kind: 'literal', 110 | value: 'this is the payload' 111 | }, 112 | { 113 | kind: 'literal', 114 | value: '\\00\\1f\\16' 115 | }, 116 | { 117 | kind: 'literal', 118 | value: 'module within a module' 119 | }, 120 | { 121 | kind: 'literal', 122 | value: '\\00asm' 123 | }, 124 | { 125 | kind: 'literal', 126 | value: '\\01\\00\\00\\00' 127 | } 128 | ] 129 | }, 130 | { 131 | kind: 'module', 132 | body: [ 133 | 'binary', 134 | { 135 | kind: 'literal', 136 | value: '\\00asm' 137 | }, 138 | { 139 | kind: 'literal', 140 | value: '\\01\\00\\00\\00' 141 | }, 142 | { 143 | kind: 'literal', 144 | value: '\\00\\0e\\06' 145 | }, 146 | { 147 | kind: 'literal', 148 | value: 'custom' 149 | }, 150 | { 151 | kind: 'literal', 152 | value: 'payload' 153 | }, 154 | { 155 | kind: 'literal', 156 | value: '\\00\\0e\\06' 157 | }, 158 | { 159 | kind: 'literal', 160 | value: 'custom' 161 | }, 162 | { 163 | kind: 'literal', 164 | value: 'payload' 165 | }, 166 | { 167 | kind: 'literal', 168 | value: '\\01\\01\\00' 169 | }, 170 | { 171 | kind: 'literal', 172 | value: '\\00\\0e\\06' 173 | }, 174 | { 175 | kind: 'literal', 176 | value: 'custom' 177 | }, 178 | { 179 | kind: 'literal', 180 | value: 'payload' 181 | }, 182 | { 183 | kind: 'literal', 184 | value: '\\00\\0e\\06' 185 | }, 186 | { 187 | kind: 'literal', 188 | value: 'custom' 189 | }, 190 | { 191 | kind: 'literal', 192 | value: 'payload' 193 | }, 194 | { 195 | kind: 'literal', 196 | value: '\\02\\01\\00' 197 | }, 198 | { 199 | kind: 'literal', 200 | value: '\\00\\0e\\06' 201 | }, 202 | { 203 | kind: 'literal', 204 | value: 'custom' 205 | }, 206 | { 207 | kind: 'literal', 208 | value: 'payload' 209 | }, 210 | { 211 | kind: 'literal', 212 | value: '\\00\\0e\\06' 213 | }, 214 | { 215 | kind: 'literal', 216 | value: 'custom' 217 | }, 218 | { 219 | kind: 'literal', 220 | value: 'payload' 221 | }, 222 | { 223 | kind: 'literal', 224 | value: '\\03\\01\\00' 225 | }, 226 | { 227 | kind: 'literal', 228 | value: '\\00\\0e\\06' 229 | }, 230 | { 231 | kind: 'literal', 232 | value: 'custom' 233 | }, 234 | { 235 | kind: 'literal', 236 | value: 'payload' 237 | }, 238 | { 239 | kind: 'literal', 240 | value: '\\00\\0e\\06' 241 | }, 242 | { 243 | kind: 'literal', 244 | value: 'custom' 245 | }, 246 | { 247 | kind: 'literal', 248 | value: 'payload' 249 | }, 250 | { 251 | kind: 'literal', 252 | value: '\\04\\01\\00' 253 | }, 254 | { 255 | kind: 'literal', 256 | value: '\\00\\0e\\06' 257 | }, 258 | { 259 | kind: 'literal', 260 | value: 'custom' 261 | }, 262 | { 263 | kind: 'literal', 264 | value: 'payload' 265 | }, 266 | { 267 | kind: 'literal', 268 | value: '\\00\\0e\\06' 269 | }, 270 | { 271 | kind: 'literal', 272 | value: 'custom' 273 | }, 274 | { 275 | kind: 'literal', 276 | value: 'payload' 277 | }, 278 | { 279 | kind: 'literal', 280 | value: '\\05\\01\\00' 281 | }, 282 | { 283 | kind: 'literal', 284 | value: '\\00\\0e\\06' 285 | }, 286 | { 287 | kind: 'literal', 288 | value: 'custom' 289 | }, 290 | { 291 | kind: 'literal', 292 | value: 'payload' 293 | }, 294 | { 295 | kind: 'literal', 296 | value: '\\00\\0e\\06' 297 | }, 298 | { 299 | kind: 'literal', 300 | value: 'custom' 301 | }, 302 | { 303 | kind: 'literal', 304 | value: 'payload' 305 | }, 306 | { 307 | kind: 'literal', 308 | value: '\\06\\01\\00' 309 | }, 310 | { 311 | kind: 'literal', 312 | value: '\\00\\0e\\06' 313 | }, 314 | { 315 | kind: 'literal', 316 | value: 'custom' 317 | }, 318 | { 319 | kind: 'literal', 320 | value: 'payload' 321 | }, 322 | { 323 | kind: 'literal', 324 | value: '\\00\\0e\\06' 325 | }, 326 | { 327 | kind: 'literal', 328 | value: 'custom' 329 | }, 330 | { 331 | kind: 'literal', 332 | value: 'payload' 333 | }, 334 | { 335 | kind: 'literal', 336 | value: '\\07\\01\\00' 337 | }, 338 | { 339 | kind: 'literal', 340 | value: '\\00\\0e\\06' 341 | }, 342 | { 343 | kind: 'literal', 344 | value: 'custom' 345 | }, 346 | { 347 | kind: 'literal', 348 | value: 'payload' 349 | }, 350 | { 351 | kind: 'literal', 352 | value: '\\00\\0e\\06' 353 | }, 354 | { 355 | kind: 'literal', 356 | value: 'custom' 357 | }, 358 | { 359 | kind: 'literal', 360 | value: 'payload' 361 | }, 362 | { 363 | kind: 'literal', 364 | value: '\\09\\01\\00' 365 | }, 366 | { 367 | kind: 'literal', 368 | value: '\\00\\0e\\06' 369 | }, 370 | { 371 | kind: 'literal', 372 | value: 'custom' 373 | }, 374 | { 375 | kind: 'literal', 376 | value: 'payload' 377 | }, 378 | { 379 | kind: 'literal', 380 | value: '\\00\\0e\\06' 381 | }, 382 | { 383 | kind: 'literal', 384 | value: 'custom' 385 | }, 386 | { 387 | kind: 'literal', 388 | value: 'payload' 389 | }, 390 | { 391 | kind: 'literal', 392 | value: '\\0a\\01\\00' 393 | }, 394 | { 395 | kind: 'literal', 396 | value: '\\00\\0e\\06' 397 | }, 398 | { 399 | kind: 'literal', 400 | value: 'custom' 401 | }, 402 | { 403 | kind: 'literal', 404 | value: 'payload' 405 | }, 406 | { 407 | kind: 'literal', 408 | value: '\\00\\0e\\06' 409 | }, 410 | { 411 | kind: 'literal', 412 | value: 'custom' 413 | }, 414 | { 415 | kind: 'literal', 416 | value: 'payload' 417 | }, 418 | { 419 | kind: 'literal', 420 | value: '\\0b\\01\\00' 421 | }, 422 | { 423 | kind: 'literal', 424 | value: '\\00\\0e\\06' 425 | }, 426 | { 427 | kind: 'literal', 428 | value: 'custom' 429 | }, 430 | { 431 | kind: 'literal', 432 | value: 'payload' 433 | }, 434 | { 435 | kind: 'literal', 436 | value: '\\00\\0e\\06' 437 | }, 438 | { 439 | kind: 'literal', 440 | value: 'custom' 441 | }, 442 | { 443 | kind: 'literal', 444 | value: 'payload' 445 | } 446 | ] 447 | }, 448 | { 449 | kind: 'module', 450 | body: [ 451 | 'binary', 452 | { 453 | kind: 'literal', 454 | value: '\\00asm' 455 | }, 456 | { 457 | kind: 'literal', 458 | value: '\\01\\00\\00\\00' 459 | }, 460 | { 461 | kind: 'literal', 462 | value: '\\01\\07\\01\\60\\02\\7f\\7f\\01\\7f' 463 | }, 464 | { 465 | kind: 'literal', 466 | value: '\\00\\1a\\06' 467 | }, 468 | { 469 | kind: 'literal', 470 | value: 'custom' 471 | }, 472 | { 473 | kind: 'literal', 474 | value: 'this is the payload' 475 | }, 476 | { 477 | kind: 'literal', 478 | value: '\\03\\02\\01\\00' 479 | }, 480 | { 481 | kind: 'literal', 482 | value: '\\07\\0a\\01\\06\\61\\64\\64\\54\\77\\6f\\00\\00' 483 | }, 484 | { 485 | kind: 'literal', 486 | value: '\\0a\\09\\01\\07\\00\\20\\00\\20\\01\\6a\\0b' 487 | }, 488 | { 489 | kind: 'literal', 490 | value: '\\00\\1b\\07' 491 | }, 492 | { 493 | kind: 'literal', 494 | value: 'custom2' 495 | }, 496 | { 497 | kind: 'literal', 498 | value: 'this is the payload' 499 | } 500 | ] 501 | }, 502 | { 503 | kind: 'assert_malformed', 504 | module: { 505 | kind: 'module', 506 | body: [ 507 | 'binary', 508 | { 509 | kind: 'literal', 510 | value: '\\00asm' 511 | }, 512 | { 513 | kind: 'literal', 514 | value: '\\01\\00\\00\\00' 515 | }, 516 | { 517 | kind: 'literal', 518 | value: '\\00' 519 | } 520 | ] 521 | }, 522 | failure: { 523 | kind: 'literal', 524 | value: 'unexpected end' 525 | } 526 | }, 527 | { 528 | kind: 'assert_malformed', 529 | module: { 530 | kind: 'module', 531 | body: [ 532 | 'binary', 533 | { 534 | kind: 'literal', 535 | value: '\\00asm' 536 | }, 537 | { 538 | kind: 'literal', 539 | value: '\\01\\00\\00\\00' 540 | }, 541 | { 542 | kind: 'literal', 543 | value: '\\00\\00' 544 | } 545 | ] 546 | }, 547 | failure: { 548 | kind: 'literal', 549 | value: 'unexpected end' 550 | } 551 | }, 552 | { 553 | kind: 'assert_malformed', 554 | module: { 555 | kind: 'module', 556 | body: [ 557 | 'binary', 558 | { 559 | kind: 'literal', 560 | value: '\\00asm' 561 | }, 562 | { 563 | kind: 'literal', 564 | value: '\\01\\00\\00\\00' 565 | }, 566 | { 567 | kind: 'literal', 568 | value: '\\00\\26\\10' 569 | }, 570 | { 571 | kind: 'literal', 572 | value: 'a custom section' 573 | }, 574 | { 575 | kind: 'literal', 576 | value: 'this is the payload' 577 | } 578 | ] 579 | }, 580 | failure: { 581 | kind: 'literal', 582 | value: 'unexpected end' 583 | } 584 | }, 585 | { 586 | kind: 'assert_malformed', 587 | module: { 588 | kind: 'module', 589 | body: [ 590 | 'binary', 591 | { 592 | kind: 'literal', 593 | value: '\\00asm' 594 | }, 595 | { 596 | kind: 'literal', 597 | value: '\\01\\00\\00\\00' 598 | }, 599 | { 600 | kind: 'literal', 601 | value: '\\00\\25\\10' 602 | }, 603 | { 604 | kind: 'literal', 605 | value: 'a custom section' 606 | }, 607 | { 608 | kind: 'literal', 609 | value: 'this is the payload' 610 | }, 611 | { 612 | kind: 'literal', 613 | value: '\\00\\24\\10' 614 | }, 615 | { 616 | kind: 'literal', 617 | value: 'a custom section' 618 | }, 619 | { 620 | kind: 'literal', 621 | value: 'this is the payload' 622 | } 623 | ] 624 | }, 625 | failure: { 626 | kind: 'literal', 627 | value: 'invalid section id' 628 | } 629 | }, 630 | { 631 | kind: 'assert_malformed', 632 | module: { 633 | kind: 'module', 634 | body: [ 635 | 'binary', 636 | { 637 | kind: 'literal', 638 | value: '\\00asm' 639 | }, 640 | { 641 | kind: 'literal', 642 | value: '\\01\\00\\00\\00' 643 | }, 644 | { 645 | kind: 'literal', 646 | value: '\\01\\07\\01\\60\\02\\7f\\7f\\01\\7f' 647 | }, 648 | { 649 | kind: 'literal', 650 | value: '\\00\\25\\10' 651 | }, 652 | { 653 | kind: 'literal', 654 | value: 'a custom section' 655 | }, 656 | { 657 | kind: 'literal', 658 | value: 'this is the payload' 659 | }, 660 | { 661 | kind: 'literal', 662 | value: '\\03\\02\\01\\00' 663 | }, 664 | { 665 | kind: 'literal', 666 | value: '\\0a\\09\\01\\07\\00\\20\\00\\20\\01\\6a\\0b' 667 | }, 668 | { 669 | kind: 'literal', 670 | value: '\\00\\1b\\07' 671 | }, 672 | { 673 | kind: 'literal', 674 | value: 'custom2' 675 | }, 676 | { 677 | kind: 'literal', 678 | value: 'this is the payload' 679 | } 680 | ] 681 | }, 682 | failure: { 683 | kind: 'literal', 684 | value: 'function and code section have inconsistent lengths' 685 | } 686 | }, 687 | { 688 | kind: 'assert_malformed', 689 | module: { 690 | kind: 'module', 691 | body: [ 692 | 'binary', 693 | { 694 | kind: 'literal', 695 | value: '\\00asm\\01\\00\\00\\00' 696 | }, 697 | { 698 | kind: 'literal', 699 | value: '\\00asm\\01\\00\\00\\00' 700 | } 701 | ] 702 | }, 703 | failure: { 704 | kind: 'literal', 705 | value: 'length out of bounds' 706 | } 707 | } 708 | ] 709 | } 710 | -------------------------------------------------------------------------------- /results/fac.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'module', 6 | body: [ 7 | { 8 | kind: 'func', 9 | id: null, 10 | expos: [{ 11 | kind: 'literal', 12 | value: 'fac-rec' 13 | }], 14 | imp: null, 15 | type: null, 16 | params: [{ 17 | kind: 'param', 18 | id: null, 19 | items: [{ 20 | kind: 'item', 21 | type: 'i64' 22 | }] 23 | }], 24 | result: { 25 | kind: 'result', 26 | type: 'i64' 27 | }, 28 | local: [], 29 | body: [{ 30 | kind: 'if', 31 | id: null, 32 | result: { 33 | kind: 'result', 34 | type: 'i64' 35 | }, 36 | body: [ 37 | { 38 | kind: 'relop', 39 | type: 'i64', 40 | operator: 'eq', 41 | left: { 42 | kind: 'get_local', 43 | id: { 44 | kind: 'literal', 45 | value: 0, 46 | raw: '0' 47 | } 48 | }, 49 | right: { 50 | kind: 'const', 51 | type: 'i64', 52 | init: '0' 53 | } 54 | }, 55 | { 56 | kind: 'then', 57 | id: null, 58 | body: [{ 59 | kind: 'const', 60 | type: 'i64', 61 | init: '1' 62 | }] 63 | }, 64 | { 65 | kind: 'else', 66 | id: null, 67 | body: [{ 68 | kind: 'binop', 69 | type: 'i64', 70 | operator: 'mul', 71 | left: { 72 | kind: 'get_local', 73 | id: { 74 | kind: 'literal', 75 | value: 0, 76 | raw: '0' 77 | } 78 | }, 79 | right: { 80 | kind: 'call', 81 | id: { 82 | kind: 'literal', 83 | value: 0, 84 | raw: '0' 85 | }, 86 | exprs: [{ 87 | kind: 'binop', 88 | type: 'i64', 89 | operator: 'sub', 90 | left: { 91 | kind: 'get_local', 92 | id: { 93 | kind: 'literal', 94 | value: 0, 95 | raw: '0' 96 | } 97 | }, 98 | right: { 99 | kind: 'const', 100 | type: 'i64', 101 | init: '1' 102 | } 103 | }] 104 | } 105 | }] 106 | } 107 | ] 108 | }] 109 | }, 110 | { 111 | kind: 'func', 112 | id: { 113 | kind: 'identifier', 114 | name: 'fac-rec-named' 115 | }, 116 | expos: [{ 117 | kind: 'literal', 118 | value: 'fac-rec-named' 119 | }], 120 | imp: null, 121 | type: null, 122 | params: [{ 123 | kind: 'param', 124 | id: { 125 | kind: 'identifier', 126 | name: 'n' 127 | }, 128 | items: [{ 129 | kind: 'item', 130 | type: 'i64' 131 | }] 132 | }], 133 | result: { 134 | kind: 'result', 135 | type: 'i64' 136 | }, 137 | local: [], 138 | body: [{ 139 | kind: 'if', 140 | id: null, 141 | result: { 142 | kind: 'result', 143 | type: 'i64' 144 | }, 145 | body: [ 146 | { 147 | kind: 'relop', 148 | type: 'i64', 149 | operator: 'eq', 150 | left: { 151 | kind: 'get_local', 152 | id: { 153 | kind: 'identifier', 154 | name: 'n' 155 | } 156 | }, 157 | right: { 158 | kind: 'const', 159 | type: 'i64', 160 | init: '0' 161 | } 162 | }, 163 | { 164 | kind: 'then', 165 | id: null, 166 | body: [{ 167 | kind: 'const', 168 | type: 'i64', 169 | init: '1' 170 | }] 171 | }, 172 | { 173 | kind: 'else', 174 | id: null, 175 | body: [{ 176 | kind: 'binop', 177 | type: 'i64', 178 | operator: 'mul', 179 | left: { 180 | kind: 'get_local', 181 | id: { 182 | kind: 'identifier', 183 | name: 'n' 184 | } 185 | }, 186 | right: { 187 | kind: 'call', 188 | id: { 189 | kind: 'identifier', 190 | name: 'fac-rec-named' 191 | }, 192 | exprs: [{ 193 | kind: 'binop', 194 | type: 'i64', 195 | operator: 'sub', 196 | left: { 197 | kind: 'get_local', 198 | id: { 199 | kind: 'identifier', 200 | name: 'n' 201 | } 202 | }, 203 | right: { 204 | kind: 'const', 205 | type: 'i64', 206 | init: '1' 207 | } 208 | }] 209 | } 210 | }] 211 | } 212 | ] 213 | }] 214 | }, 215 | { 216 | kind: 'func', 217 | id: null, 218 | expos: [{ 219 | kind: 'literal', 220 | value: 'fac-iter' 221 | }], 222 | imp: null, 223 | type: null, 224 | params: [{ 225 | kind: 'param', 226 | id: null, 227 | items: [{ 228 | kind: 'item', 229 | type: 'i64' 230 | }] 231 | }], 232 | result: { 233 | kind: 'result', 234 | type: 'i64' 235 | }, 236 | local: [{ 237 | kind: 'local', 238 | items: [ 239 | { 240 | kind: 'item', 241 | type: 'i64' 242 | }, 243 | { 244 | kind: 'item', 245 | type: 'i64' 246 | } 247 | ] 248 | }], 249 | body: [ 250 | { 251 | kind: 'set_local', 252 | id: { 253 | kind: 'literal', 254 | value: 1, 255 | raw: '1' 256 | }, 257 | init: { 258 | kind: 'get_local', 259 | id: { 260 | kind: 'literal', 261 | value: 0, 262 | raw: '0' 263 | } 264 | } 265 | }, 266 | { 267 | kind: 'set_local', 268 | id: { 269 | kind: 'literal', 270 | value: 2, 271 | raw: '2' 272 | }, 273 | init: { 274 | kind: 'const', 275 | type: 'i64', 276 | init: '1' 277 | } 278 | }, 279 | { 280 | kind: 'block', 281 | result: null, 282 | id: null, 283 | body: [{ 284 | kind: 'loop', 285 | id: null, 286 | result: null, 287 | extra: null, 288 | body: [ 289 | { 290 | kind: 'if', 291 | id: null, 292 | result: null, 293 | body: [ 294 | { 295 | kind: 'relop', 296 | type: 'i64', 297 | operator: 'eq', 298 | left: { 299 | kind: 'get_local', 300 | id: { 301 | kind: 'literal', 302 | value: 1, 303 | raw: '1' 304 | } 305 | }, 306 | right: { 307 | kind: 'const', 308 | type: 'i64', 309 | init: '0' 310 | } 311 | }, 312 | { 313 | kind: 'then', 314 | id: null, 315 | body: [{ 316 | kind: 'br', 317 | id: { 318 | kind: 'literal', 319 | value: 2, 320 | raw: '2' 321 | }, 322 | expr: null 323 | }] 324 | }, 325 | { 326 | kind: 'else', 327 | id: null, 328 | body: [ 329 | { 330 | kind: 'set_local', 331 | id: { 332 | kind: 'literal', 333 | value: 2, 334 | raw: '2' 335 | }, 336 | init: { 337 | kind: 'binop', 338 | type: 'i64', 339 | operator: 'mul', 340 | left: { 341 | kind: 'get_local', 342 | id: { 343 | kind: 'literal', 344 | value: 1, 345 | raw: '1' 346 | } 347 | }, 348 | right: { 349 | kind: 'get_local', 350 | id: { 351 | kind: 'literal', 352 | value: 2, 353 | raw: '2' 354 | } 355 | } 356 | } 357 | }, 358 | { 359 | kind: 'set_local', 360 | id: { 361 | kind: 'literal', 362 | value: 1, 363 | raw: '1' 364 | }, 365 | init: { 366 | kind: 'binop', 367 | type: 'i64', 368 | operator: 'sub', 369 | left: { 370 | kind: 'get_local', 371 | id: { 372 | kind: 'literal', 373 | value: 1, 374 | raw: '1' 375 | } 376 | }, 377 | right: { 378 | kind: 'const', 379 | type: 'i64', 380 | init: '1' 381 | } 382 | } 383 | } 384 | ] 385 | } 386 | ] 387 | }, 388 | { 389 | kind: 'br', 390 | id: { 391 | kind: 'literal', 392 | value: 0, 393 | raw: '0' 394 | }, 395 | expr: null 396 | } 397 | ] 398 | }] 399 | }, 400 | { 401 | kind: 'get_local', 402 | id: { 403 | kind: 'literal', 404 | value: 2, 405 | raw: '2' 406 | } 407 | } 408 | ] 409 | }, 410 | { 411 | kind: 'func', 412 | id: null, 413 | expos: [{ 414 | kind: 'literal', 415 | value: 'fac-iter-named' 416 | }], 417 | imp: null, 418 | type: null, 419 | params: [{ 420 | kind: 'param', 421 | id: { 422 | kind: 'identifier', 423 | name: 'n' 424 | }, 425 | items: [{ 426 | kind: 'item', 427 | type: 'i64' 428 | }] 429 | }], 430 | result: { 431 | kind: 'result', 432 | type: 'i64' 433 | }, 434 | local: [ 435 | { 436 | kind: 'local', 437 | items: [{ 438 | kind: 'item', 439 | name: 'i', 440 | type: 'i64' 441 | }] 442 | }, 443 | { 444 | kind: 'local', 445 | items: [{ 446 | kind: 'item', 447 | name: 'res', 448 | type: 'i64' 449 | }] 450 | } 451 | ], 452 | body: [ 453 | { 454 | kind: 'set_local', 455 | id: { 456 | kind: 'identifier', 457 | name: 'i' 458 | }, 459 | init: { 460 | kind: 'get_local', 461 | id: { 462 | kind: 'identifier', 463 | name: 'n' 464 | } 465 | } 466 | }, 467 | { 468 | kind: 'set_local', 469 | id: { 470 | kind: 'identifier', 471 | name: 'res' 472 | }, 473 | init: { 474 | kind: 'const', 475 | type: 'i64', 476 | init: '1' 477 | } 478 | }, 479 | { 480 | kind: 'block', 481 | result: null, 482 | id: { 483 | kind: 'identifier', 484 | name: 'done' 485 | }, 486 | body: [{ 487 | kind: 'loop', 488 | id: { 489 | kind: 'identifier', 490 | name: 'loop' 491 | }, 492 | result: null, 493 | extra: null, 494 | body: [ 495 | { 496 | kind: 'if', 497 | id: null, 498 | result: null, 499 | body: [ 500 | { 501 | kind: 'relop', 502 | type: 'i64', 503 | operator: 'eq', 504 | left: { 505 | kind: 'get_local', 506 | id: { 507 | kind: 'identifier', 508 | name: 'i' 509 | } 510 | }, 511 | right: { 512 | kind: 'const', 513 | type: 'i64', 514 | init: '0' 515 | } 516 | }, 517 | { 518 | kind: 'then', 519 | id: null, 520 | body: [{ 521 | kind: 'br', 522 | id: { 523 | kind: 'identifier', 524 | name: 'done' 525 | }, 526 | expr: null 527 | }] 528 | }, 529 | { 530 | kind: 'else', 531 | id: null, 532 | body: [ 533 | { 534 | kind: 'set_local', 535 | id: { 536 | kind: 'identifier', 537 | name: 'res' 538 | }, 539 | init: { 540 | kind: 'binop', 541 | type: 'i64', 542 | operator: 'mul', 543 | left: { 544 | kind: 'get_local', 545 | id: { 546 | kind: 'identifier', 547 | name: 'i' 548 | } 549 | }, 550 | right: { 551 | kind: 'get_local', 552 | id: { 553 | kind: 'identifier', 554 | name: 'res' 555 | } 556 | } 557 | } 558 | }, 559 | { 560 | kind: 'set_local', 561 | id: { 562 | kind: 'identifier', 563 | name: 'i' 564 | }, 565 | init: { 566 | kind: 'binop', 567 | type: 'i64', 568 | operator: 'sub', 569 | left: { 570 | kind: 'get_local', 571 | id: { 572 | kind: 'identifier', 573 | name: 'i' 574 | } 575 | }, 576 | right: { 577 | kind: 'const', 578 | type: 'i64', 579 | init: '1' 580 | } 581 | } 582 | } 583 | ] 584 | } 585 | ] 586 | }, 587 | { 588 | kind: 'br', 589 | id: { 590 | kind: 'identifier', 591 | name: 'loop' 592 | }, 593 | expr: null 594 | } 595 | ] 596 | }] 597 | }, 598 | { 599 | kind: 'get_local', 600 | id: { 601 | kind: 'identifier', 602 | name: 'res' 603 | } 604 | } 605 | ] 606 | }, 607 | { 608 | kind: 'func', 609 | id: null, 610 | expos: [{ 611 | kind: 'literal', 612 | value: 'fac-opt' 613 | }], 614 | imp: null, 615 | type: null, 616 | params: [{ 617 | kind: 'param', 618 | id: null, 619 | items: [{ 620 | kind: 'item', 621 | type: 'i64' 622 | }] 623 | }], 624 | result: { 625 | kind: 'result', 626 | type: 'i64' 627 | }, 628 | local: [{ 629 | kind: 'local', 630 | items: [{ 631 | kind: 'item', 632 | type: 'i64' 633 | }] 634 | }], 635 | body: [ 636 | { 637 | kind: 'set_local', 638 | id: { 639 | kind: 'literal', 640 | value: 1, 641 | raw: '1' 642 | }, 643 | init: { 644 | kind: 'const', 645 | type: 'i64', 646 | init: '1' 647 | } 648 | }, 649 | { 650 | kind: 'block', 651 | result: null, 652 | id: null, 653 | body: [ 654 | { 655 | kind: 'br_if', 656 | id: { 657 | kind: 'literal', 658 | value: 0, 659 | raw: '0' 660 | }, 661 | test: { 662 | kind: 'relop', 663 | type: 'i64', 664 | operator: 'lt_s', 665 | left: { 666 | kind: 'get_local', 667 | id: { 668 | kind: 'literal', 669 | value: 0, 670 | raw: '0' 671 | } 672 | }, 673 | right: { 674 | kind: 'const', 675 | type: 'i64', 676 | init: '2' 677 | } 678 | }, 679 | expr: null 680 | }, 681 | { 682 | kind: 'loop', 683 | id: null, 684 | result: null, 685 | extra: null, 686 | body: [ 687 | { 688 | kind: 'set_local', 689 | id: { 690 | kind: 'literal', 691 | value: 1, 692 | raw: '1' 693 | }, 694 | init: { 695 | kind: 'binop', 696 | type: 'i64', 697 | operator: 'mul', 698 | left: { 699 | kind: 'get_local', 700 | id: { 701 | kind: 'literal', 702 | value: 1, 703 | raw: '1' 704 | } 705 | }, 706 | right: { 707 | kind: 'get_local', 708 | id: { 709 | kind: 'literal', 710 | value: 0, 711 | raw: '0' 712 | } 713 | } 714 | } 715 | }, 716 | { 717 | kind: 'set_local', 718 | id: { 719 | kind: 'literal', 720 | value: 0, 721 | raw: '0' 722 | }, 723 | init: { 724 | kind: 'binop', 725 | type: 'i64', 726 | operator: 'add', 727 | left: { 728 | kind: 'get_local', 729 | id: { 730 | kind: 'literal', 731 | value: 0, 732 | raw: '0' 733 | } 734 | }, 735 | right: { 736 | kind: 'const', 737 | type: 'i64', 738 | init: '-1' 739 | } 740 | } 741 | }, 742 | { 743 | kind: 'br_if', 744 | id: { 745 | kind: 'literal', 746 | value: 0, 747 | raw: '0' 748 | }, 749 | test: { 750 | kind: 'relop', 751 | type: 'i64', 752 | operator: 'gt_s', 753 | left: { 754 | kind: 'get_local', 755 | id: { 756 | kind: 'literal', 757 | value: 0, 758 | raw: '0' 759 | } 760 | }, 761 | right: { 762 | kind: 'const', 763 | type: 'i64', 764 | init: '1' 765 | } 766 | }, 767 | expr: null 768 | } 769 | ] 770 | } 771 | ] 772 | }, 773 | { 774 | kind: 'get_local', 775 | id: { 776 | kind: 'literal', 777 | value: 1, 778 | raw: '1' 779 | } 780 | } 781 | ] 782 | } 783 | ] 784 | }, 785 | { 786 | kind: 'assert_return', 787 | invoke: { 788 | kind: 'invoke', 789 | id: null, 790 | name: 'fac-rec', 791 | body: [{ 792 | kind: 'const', 793 | type: 'i64', 794 | init: '25' 795 | }] 796 | }, 797 | expr: { 798 | kind: 'const', 799 | type: 'i64', 800 | init: '7034535277573963776' 801 | } 802 | }, 803 | { 804 | kind: 'assert_return', 805 | invoke: { 806 | kind: 'invoke', 807 | id: null, 808 | name: 'fac-iter', 809 | body: [{ 810 | kind: 'const', 811 | type: 'i64', 812 | init: '25' 813 | }] 814 | }, 815 | expr: { 816 | kind: 'const', 817 | type: 'i64', 818 | init: '7034535277573963776' 819 | } 820 | }, 821 | { 822 | kind: 'assert_return', 823 | invoke: { 824 | kind: 'invoke', 825 | id: null, 826 | name: 'fac-rec-named', 827 | body: [{ 828 | kind: 'const', 829 | type: 'i64', 830 | init: '25' 831 | }] 832 | }, 833 | expr: { 834 | kind: 'const', 835 | type: 'i64', 836 | init: '7034535277573963776' 837 | } 838 | }, 839 | { 840 | kind: 'assert_return', 841 | invoke: { 842 | kind: 'invoke', 843 | id: null, 844 | name: 'fac-iter-named', 845 | body: [{ 846 | kind: 'const', 847 | type: 'i64', 848 | init: '25' 849 | }] 850 | }, 851 | expr: { 852 | kind: 'const', 853 | type: 'i64', 854 | init: '7034535277573963776' 855 | } 856 | }, 857 | { 858 | kind: 'assert_return', 859 | invoke: { 860 | kind: 'invoke', 861 | id: null, 862 | name: 'fac-opt', 863 | body: [{ 864 | kind: 'const', 865 | type: 'i64', 866 | init: '25' 867 | }] 868 | }, 869 | expr: { 870 | kind: 'const', 871 | type: 'i64', 872 | init: '7034535277573963776' 873 | } 874 | }, 875 | { 876 | kind: 'assert_exhaustion', 877 | module: { 878 | kind: 'invoke', 879 | id: null, 880 | name: 'fac-rec', 881 | body: [{ 882 | kind: 'const', 883 | type: 'i64', 884 | init: '1073741824' 885 | }] 886 | }, 887 | failure: { 888 | kind: 'literal', 889 | value: 'call stack exhausted' 890 | } 891 | } 892 | ] 893 | } 894 | -------------------------------------------------------------------------------- /results/forward.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'module', 6 | body: [ 7 | { 8 | kind: 'func', 9 | id: { 10 | kind: 'identifier', 11 | name: 'even' 12 | }, 13 | expos: [{ 14 | kind: 'literal', 15 | value: 'even' 16 | }], 17 | imp: null, 18 | type: null, 19 | params: [{ 20 | kind: 'param', 21 | id: { 22 | kind: 'identifier', 23 | name: 'n' 24 | }, 25 | items: [{ 26 | kind: 'item', 27 | type: 'i32' 28 | }] 29 | }], 30 | result: { 31 | kind: 'result', 32 | type: 'i32' 33 | }, 34 | local: [], 35 | body: [{ 36 | kind: 'if', 37 | id: null, 38 | result: { 39 | kind: 'result', 40 | type: 'i32' 41 | }, 42 | body: [ 43 | { 44 | kind: 'relop', 45 | type: 'i32', 46 | operator: 'eq', 47 | left: { 48 | kind: 'get_local', 49 | id: { 50 | kind: 'identifier', 51 | name: 'n' 52 | } 53 | }, 54 | right: { 55 | kind: 'const', 56 | type: 'i32', 57 | init: '0' 58 | } 59 | }, 60 | { 61 | kind: 'then', 62 | id: null, 63 | body: [{ 64 | kind: 'const', 65 | type: 'i32', 66 | init: '1' 67 | }] 68 | }, 69 | { 70 | kind: 'else', 71 | id: null, 72 | body: [{ 73 | kind: 'call', 74 | id: { 75 | kind: 'identifier', 76 | name: 'odd' 77 | }, 78 | exprs: [{ 79 | kind: 'binop', 80 | type: 'i32', 81 | operator: 'sub', 82 | left: { 83 | kind: 'get_local', 84 | id: { 85 | kind: 'identifier', 86 | name: 'n' 87 | } 88 | }, 89 | right: { 90 | kind: 'const', 91 | type: 'i32', 92 | init: '1' 93 | } 94 | }] 95 | }] 96 | } 97 | ] 98 | }] 99 | }, 100 | { 101 | kind: 'func', 102 | id: { 103 | kind: 'identifier', 104 | name: 'odd' 105 | }, 106 | expos: [{ 107 | kind: 'literal', 108 | value: 'odd' 109 | }], 110 | imp: null, 111 | type: null, 112 | params: [{ 113 | kind: 'param', 114 | id: { 115 | kind: 'identifier', 116 | name: 'n' 117 | }, 118 | items: [{ 119 | kind: 'item', 120 | type: 'i32' 121 | }] 122 | }], 123 | result: { 124 | kind: 'result', 125 | type: 'i32' 126 | }, 127 | local: [], 128 | body: [{ 129 | kind: 'if', 130 | id: null, 131 | result: { 132 | kind: 'result', 133 | type: 'i32' 134 | }, 135 | body: [ 136 | { 137 | kind: 'relop', 138 | type: 'i32', 139 | operator: 'eq', 140 | left: { 141 | kind: 'get_local', 142 | id: { 143 | kind: 'identifier', 144 | name: 'n' 145 | } 146 | }, 147 | right: { 148 | kind: 'const', 149 | type: 'i32', 150 | init: '0' 151 | } 152 | }, 153 | { 154 | kind: 'then', 155 | id: null, 156 | body: [{ 157 | kind: 'const', 158 | type: 'i32', 159 | init: '0' 160 | }] 161 | }, 162 | { 163 | kind: 'else', 164 | id: null, 165 | body: [{ 166 | kind: 'call', 167 | id: { 168 | kind: 'identifier', 169 | name: 'even' 170 | }, 171 | exprs: [{ 172 | kind: 'binop', 173 | type: 'i32', 174 | operator: 'sub', 175 | left: { 176 | kind: 'get_local', 177 | id: { 178 | kind: 'identifier', 179 | name: 'n' 180 | } 181 | }, 182 | right: { 183 | kind: 'const', 184 | type: 'i32', 185 | init: '1' 186 | } 187 | }] 188 | }] 189 | } 190 | ] 191 | }] 192 | } 193 | ] 194 | }, 195 | { 196 | kind: 'assert_return', 197 | invoke: { 198 | kind: 'invoke', 199 | id: null, 200 | name: 'even', 201 | body: [{ 202 | kind: 'const', 203 | type: 'i32', 204 | init: '13' 205 | }] 206 | }, 207 | expr: { 208 | kind: 'const', 209 | type: 'i32', 210 | init: '0' 211 | } 212 | }, 213 | { 214 | kind: 'assert_return', 215 | invoke: { 216 | kind: 'invoke', 217 | id: null, 218 | name: 'even', 219 | body: [{ 220 | kind: 'const', 221 | type: 'i32', 222 | init: '20' 223 | }] 224 | }, 225 | expr: { 226 | kind: 'const', 227 | type: 'i32', 228 | init: '1' 229 | } 230 | }, 231 | { 232 | kind: 'assert_return', 233 | invoke: { 234 | kind: 'invoke', 235 | id: null, 236 | name: 'odd', 237 | body: [{ 238 | kind: 'const', 239 | type: 'i32', 240 | init: '13' 241 | }] 242 | }, 243 | expr: { 244 | kind: 'const', 245 | type: 'i32', 246 | init: '1' 247 | } 248 | }, 249 | { 250 | kind: 'assert_return', 251 | invoke: { 252 | kind: 'invoke', 253 | id: null, 254 | name: 'odd', 255 | body: [{ 256 | kind: 'const', 257 | type: 'i32', 258 | init: '20' 259 | }] 260 | }, 261 | expr: { 262 | kind: 'const', 263 | type: 'i32', 264 | init: '0' 265 | } 266 | } 267 | ] 268 | } 269 | -------------------------------------------------------------------------------- /results/globals.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'module', 6 | body: [ 7 | { 8 | kind: 'global', 9 | id: { 10 | kind: 'identifier', 11 | name: 'a' 12 | }, 13 | mut: false, 14 | expo: null, 15 | impo: null, 16 | type: 'i32', 17 | body: [{ 18 | kind: 'const', 19 | type: 'i32', 20 | init: '-2' 21 | }] 22 | }, 23 | { 24 | kind: 'global', 25 | id: null, 26 | mut: false, 27 | expo: null, 28 | impo: null, 29 | type: 'f32', 30 | body: [{ 31 | kind: 'const', 32 | type: 'f32', 33 | init: '-3' 34 | }] 35 | }, 36 | { 37 | kind: 'global', 38 | id: null, 39 | mut: false, 40 | expo: null, 41 | impo: null, 42 | type: 'f64', 43 | body: [{ 44 | kind: 'const', 45 | type: 'f64', 46 | init: '-4' 47 | }] 48 | }, 49 | { 50 | kind: 'global', 51 | id: { 52 | kind: 'identifier', 53 | name: 'b' 54 | }, 55 | mut: false, 56 | expo: null, 57 | impo: null, 58 | type: 'i64', 59 | body: [{ 60 | kind: 'const', 61 | type: 'i64', 62 | init: '-5' 63 | }] 64 | }, 65 | { 66 | kind: 'global', 67 | id: { 68 | kind: 'identifier', 69 | name: 'x' 70 | }, 71 | mut: true, 72 | expo: null, 73 | impo: null, 74 | type: 'i32', 75 | body: [{ 76 | kind: 'const', 77 | type: 'i32', 78 | init: '-12' 79 | }] 80 | }, 81 | { 82 | kind: 'global', 83 | id: null, 84 | mut: true, 85 | expo: null, 86 | impo: null, 87 | type: 'f32', 88 | body: [{ 89 | kind: 'const', 90 | type: 'f32', 91 | init: '-13' 92 | }] 93 | }, 94 | { 95 | kind: 'global', 96 | id: null, 97 | mut: true, 98 | expo: null, 99 | impo: null, 100 | type: 'f64', 101 | body: [{ 102 | kind: 'const', 103 | type: 'f64', 104 | init: '-14' 105 | }] 106 | }, 107 | { 108 | kind: 'global', 109 | id: { 110 | kind: 'identifier', 111 | name: 'y' 112 | }, 113 | mut: true, 114 | expo: null, 115 | impo: null, 116 | type: 'i64', 117 | body: [{ 118 | kind: 'const', 119 | type: 'i64', 120 | init: '-15' 121 | }] 122 | }, 123 | { 124 | kind: 'func', 125 | id: null, 126 | expos: [{ 127 | kind: 'literal', 128 | value: 'get-a' 129 | }], 130 | imp: null, 131 | type: null, 132 | params: [], 133 | result: { 134 | kind: 'result', 135 | type: 'i32' 136 | }, 137 | local: [], 138 | body: [{ 139 | kind: 'get_global', 140 | id: { 141 | kind: 'identifier', 142 | name: 'a' 143 | } 144 | }] 145 | }, 146 | { 147 | kind: 'func', 148 | id: null, 149 | expos: [{ 150 | kind: 'literal', 151 | value: 'get-b' 152 | }], 153 | imp: null, 154 | type: null, 155 | params: [], 156 | result: { 157 | kind: 'result', 158 | type: 'i64' 159 | }, 160 | local: [], 161 | body: [{ 162 | kind: 'get_global', 163 | id: { 164 | kind: 'identifier', 165 | name: 'b' 166 | } 167 | }] 168 | }, 169 | { 170 | kind: 'func', 171 | id: null, 172 | expos: [{ 173 | kind: 'literal', 174 | value: 'get-x' 175 | }], 176 | imp: null, 177 | type: null, 178 | params: [], 179 | result: { 180 | kind: 'result', 181 | type: 'i32' 182 | }, 183 | local: [], 184 | body: [{ 185 | kind: 'get_global', 186 | id: { 187 | kind: 'identifier', 188 | name: 'x' 189 | } 190 | }] 191 | }, 192 | { 193 | kind: 'func', 194 | id: null, 195 | expos: [{ 196 | kind: 'literal', 197 | value: 'get-y' 198 | }], 199 | imp: null, 200 | type: null, 201 | params: [], 202 | result: { 203 | kind: 'result', 204 | type: 'i64' 205 | }, 206 | local: [], 207 | body: [{ 208 | kind: 'get_global', 209 | id: { 210 | kind: 'identifier', 211 | name: 'y' 212 | } 213 | }] 214 | }, 215 | { 216 | kind: 'func', 217 | id: null, 218 | expos: [{ 219 | kind: 'literal', 220 | value: 'set-x' 221 | }], 222 | imp: null, 223 | type: null, 224 | params: [{ 225 | kind: 'param', 226 | id: null, 227 | items: [{ 228 | kind: 'item', 229 | type: 'i32' 230 | }] 231 | }], 232 | result: null, 233 | local: [], 234 | body: [{ 235 | kind: 'set_global', 236 | id: { 237 | kind: 'identifier', 238 | name: 'x' 239 | }, 240 | init: { 241 | kind: 'get_local', 242 | id: { 243 | kind: 'literal', 244 | value: 0, 245 | raw: '0' 246 | } 247 | } 248 | }] 249 | }, 250 | { 251 | kind: 'func', 252 | id: null, 253 | expos: [{ 254 | kind: 'literal', 255 | value: 'set-y' 256 | }], 257 | imp: null, 258 | type: null, 259 | params: [{ 260 | kind: 'param', 261 | id: null, 262 | items: [{ 263 | kind: 'item', 264 | type: 'i64' 265 | }] 266 | }], 267 | result: null, 268 | local: [], 269 | body: [{ 270 | kind: 'set_global', 271 | id: { 272 | kind: 'identifier', 273 | name: 'y' 274 | }, 275 | init: { 276 | kind: 'get_local', 277 | id: { 278 | kind: 'literal', 279 | value: 0, 280 | raw: '0' 281 | } 282 | } 283 | }] 284 | }, 285 | { 286 | kind: 'func', 287 | id: null, 288 | expos: [{ 289 | kind: 'literal', 290 | value: 'get-1' 291 | }], 292 | imp: null, 293 | type: null, 294 | params: [], 295 | result: { 296 | kind: 'result', 297 | type: 'f32' 298 | }, 299 | local: [], 300 | body: [{ 301 | kind: 'get_global', 302 | id: { 303 | kind: 'literal', 304 | value: 1, 305 | raw: '1' 306 | } 307 | }] 308 | }, 309 | { 310 | kind: 'func', 311 | id: null, 312 | expos: [{ 313 | kind: 'literal', 314 | value: 'get-2' 315 | }], 316 | imp: null, 317 | type: null, 318 | params: [], 319 | result: { 320 | kind: 'result', 321 | type: 'f64' 322 | }, 323 | local: [], 324 | body: [{ 325 | kind: 'get_global', 326 | id: { 327 | kind: 'literal', 328 | value: 2, 329 | raw: '2' 330 | } 331 | }] 332 | }, 333 | { 334 | kind: 'func', 335 | id: null, 336 | expos: [{ 337 | kind: 'literal', 338 | value: 'get-5' 339 | }], 340 | imp: null, 341 | type: null, 342 | params: [], 343 | result: { 344 | kind: 'result', 345 | type: 'f32' 346 | }, 347 | local: [], 348 | body: [{ 349 | kind: 'get_global', 350 | id: { 351 | kind: 'literal', 352 | value: 5, 353 | raw: '5' 354 | } 355 | }] 356 | }, 357 | { 358 | kind: 'func', 359 | id: null, 360 | expos: [{ 361 | kind: 'literal', 362 | value: 'get-6' 363 | }], 364 | imp: null, 365 | type: null, 366 | params: [], 367 | result: { 368 | kind: 'result', 369 | type: 'f64' 370 | }, 371 | local: [], 372 | body: [{ 373 | kind: 'get_global', 374 | id: { 375 | kind: 'literal', 376 | value: 6, 377 | raw: '6' 378 | } 379 | }] 380 | }, 381 | { 382 | kind: 'func', 383 | id: null, 384 | expos: [{ 385 | kind: 'literal', 386 | value: 'set-5' 387 | }], 388 | imp: null, 389 | type: null, 390 | params: [{ 391 | kind: 'param', 392 | id: null, 393 | items: [{ 394 | kind: 'item', 395 | type: 'f32' 396 | }] 397 | }], 398 | result: null, 399 | local: [], 400 | body: [{ 401 | kind: 'set_global', 402 | id: { 403 | kind: 'literal', 404 | value: 5, 405 | raw: '5' 406 | }, 407 | init: { 408 | kind: 'get_local', 409 | id: { 410 | kind: 'literal', 411 | value: 0, 412 | raw: '0' 413 | } 414 | } 415 | }] 416 | }, 417 | { 418 | kind: 'func', 419 | id: null, 420 | expos: [{ 421 | kind: 'literal', 422 | value: 'set-6' 423 | }], 424 | imp: null, 425 | type: null, 426 | params: [{ 427 | kind: 'param', 428 | id: null, 429 | items: [{ 430 | kind: 'item', 431 | type: 'f64' 432 | }] 433 | }], 434 | result: null, 435 | local: [], 436 | body: [{ 437 | kind: 'set_global', 438 | id: { 439 | kind: 'literal', 440 | value: 6, 441 | raw: '6' 442 | }, 443 | init: { 444 | kind: 'get_local', 445 | id: { 446 | kind: 'literal', 447 | value: 0, 448 | raw: '0' 449 | } 450 | } 451 | }] 452 | } 453 | ] 454 | }, 455 | { 456 | kind: 'assert_return', 457 | invoke: { 458 | kind: 'invoke', 459 | id: null, 460 | name: 'get-a', 461 | body: [] 462 | }, 463 | expr: { 464 | kind: 'const', 465 | type: 'i32', 466 | init: '-2' 467 | } 468 | }, 469 | { 470 | kind: 'assert_return', 471 | invoke: { 472 | kind: 'invoke', 473 | id: null, 474 | name: 'get-b', 475 | body: [] 476 | }, 477 | expr: { 478 | kind: 'const', 479 | type: 'i64', 480 | init: '-5' 481 | } 482 | }, 483 | { 484 | kind: 'assert_return', 485 | invoke: { 486 | kind: 'invoke', 487 | id: null, 488 | name: 'get-x', 489 | body: [] 490 | }, 491 | expr: { 492 | kind: 'const', 493 | type: 'i32', 494 | init: '-12' 495 | } 496 | }, 497 | { 498 | kind: 'assert_return', 499 | invoke: { 500 | kind: 'invoke', 501 | id: null, 502 | name: 'get-y', 503 | body: [] 504 | }, 505 | expr: { 506 | kind: 'const', 507 | type: 'i64', 508 | init: '-15' 509 | } 510 | }, 511 | { 512 | kind: 'assert_return', 513 | invoke: { 514 | kind: 'invoke', 515 | id: null, 516 | name: 'get-1', 517 | body: [] 518 | }, 519 | expr: { 520 | kind: 'const', 521 | type: 'f32', 522 | init: '-3' 523 | } 524 | }, 525 | { 526 | kind: 'assert_return', 527 | invoke: { 528 | kind: 'invoke', 529 | id: null, 530 | name: 'get-2', 531 | body: [] 532 | }, 533 | expr: { 534 | kind: 'const', 535 | type: 'f64', 536 | init: '-4' 537 | } 538 | }, 539 | { 540 | kind: 'assert_return', 541 | invoke: { 542 | kind: 'invoke', 543 | id: null, 544 | name: 'get-5', 545 | body: [] 546 | }, 547 | expr: { 548 | kind: 'const', 549 | type: 'f32', 550 | init: '-13' 551 | } 552 | }, 553 | { 554 | kind: 'assert_return', 555 | invoke: { 556 | kind: 'invoke', 557 | id: null, 558 | name: 'get-6', 559 | body: [] 560 | }, 561 | expr: { 562 | kind: 'const', 563 | type: 'f64', 564 | init: '-14' 565 | } 566 | }, 567 | { 568 | kind: 'assert_return', 569 | invoke: { 570 | kind: 'invoke', 571 | id: null, 572 | name: 'set-x', 573 | body: [{ 574 | kind: 'const', 575 | type: 'i32', 576 | init: '6' 577 | }] 578 | }, 579 | expr: null 580 | }, 581 | { 582 | kind: 'assert_return', 583 | invoke: { 584 | kind: 'invoke', 585 | id: null, 586 | name: 'set-y', 587 | body: [{ 588 | kind: 'const', 589 | type: 'i64', 590 | init: '7' 591 | }] 592 | }, 593 | expr: null 594 | }, 595 | { 596 | kind: 'assert_return', 597 | invoke: { 598 | kind: 'invoke', 599 | id: null, 600 | name: 'set-5', 601 | body: [{ 602 | kind: 'const', 603 | type: 'f32', 604 | init: '8' 605 | }] 606 | }, 607 | expr: null 608 | }, 609 | { 610 | kind: 'assert_return', 611 | invoke: { 612 | kind: 'invoke', 613 | id: null, 614 | name: 'set-6', 615 | body: [{ 616 | kind: 'const', 617 | type: 'f64', 618 | init: '9' 619 | }] 620 | }, 621 | expr: null 622 | }, 623 | { 624 | kind: 'assert_return', 625 | invoke: { 626 | kind: 'invoke', 627 | id: null, 628 | name: 'get-x', 629 | body: [] 630 | }, 631 | expr: { 632 | kind: 'const', 633 | type: 'i32', 634 | init: '6' 635 | } 636 | }, 637 | { 638 | kind: 'assert_return', 639 | invoke: { 640 | kind: 'invoke', 641 | id: null, 642 | name: 'get-y', 643 | body: [] 644 | }, 645 | expr: { 646 | kind: 'const', 647 | type: 'i64', 648 | init: '7' 649 | } 650 | }, 651 | { 652 | kind: 'assert_return', 653 | invoke: { 654 | kind: 'invoke', 655 | id: null, 656 | name: 'get-5', 657 | body: [] 658 | }, 659 | expr: { 660 | kind: 'const', 661 | type: 'f32', 662 | init: '8' 663 | } 664 | }, 665 | { 666 | kind: 'assert_return', 667 | invoke: { 668 | kind: 'invoke', 669 | id: null, 670 | name: 'get-6', 671 | body: [] 672 | }, 673 | expr: { 674 | kind: 'const', 675 | type: 'f64', 676 | init: '9' 677 | } 678 | }, 679 | { 680 | kind: 'assert_invalid', 681 | module: { 682 | kind: 'module', 683 | body: [ 684 | { 685 | kind: 'global', 686 | id: null, 687 | mut: false, 688 | expo: null, 689 | impo: null, 690 | type: 'f32', 691 | body: [{ 692 | kind: 'const', 693 | type: 'f32', 694 | init: '0' 695 | }] 696 | }, 697 | { 698 | kind: 'func', 699 | id: null, 700 | expos: [], 701 | imp: null, 702 | type: null, 703 | params: [], 704 | result: null, 705 | local: [], 706 | body: [{ 707 | kind: 'set_global', 708 | id: { 709 | kind: 'literal', 710 | value: 0, 711 | raw: '0' 712 | }, 713 | init: { 714 | kind: 'const', 715 | type: 'i32', 716 | init: '1' 717 | } 718 | }] 719 | } 720 | ] 721 | }, 722 | failure: { 723 | kind: 'literal', 724 | value: 'global is immutable' 725 | } 726 | }, 727 | { 728 | kind: 'module', 729 | body: [ 730 | { 731 | kind: 'global', 732 | id: null, 733 | mut: true, 734 | expo: null, 735 | impo: null, 736 | type: 'f32', 737 | body: [{ 738 | kind: 'const', 739 | type: 'f32', 740 | init: '0' 741 | }] 742 | }, 743 | { 744 | kind: 'export', 745 | name: { 746 | kind: 'literal', 747 | value: 'a' 748 | }, 749 | id: { 750 | kind: 'global', 751 | id: { 752 | kind: 'literal', 753 | value: 0, 754 | raw: '0' 755 | }, 756 | mut: false, 757 | expo: null, 758 | impo: null, 759 | type: null, 760 | body: [] 761 | } 762 | } 763 | ] 764 | }, 765 | { 766 | kind: 'module', 767 | body: [{ 768 | kind: 'global', 769 | id: null, 770 | mut: true, 771 | expo: { 772 | kind: 'literal', 773 | value: 'a' 774 | }, 775 | impo: null, 776 | type: 'f32', 777 | body: [{ 778 | kind: 'const', 779 | type: 'f32', 780 | init: '0' 781 | }] 782 | }] 783 | }, 784 | { 785 | kind: 'assert_invalid', 786 | module: { 787 | kind: 'module', 788 | body: [{ 789 | kind: 'global', 790 | id: null, 791 | mut: false, 792 | expo: null, 793 | impo: null, 794 | type: 'f32', 795 | body: [{ 796 | kind: 'unop', 797 | type: 'f32', 798 | operator: 'neg', 799 | expr: { 800 | kind: 'const', 801 | type: 'f32', 802 | init: '0' 803 | } 804 | }] 805 | }] 806 | }, 807 | failure: { 808 | kind: 'literal', 809 | value: 'constant expression required' 810 | } 811 | }, 812 | { 813 | kind: 'assert_invalid', 814 | module: { 815 | kind: 'module', 816 | body: [{ 817 | kind: 'global', 818 | id: null, 819 | mut: false, 820 | expo: null, 821 | impo: null, 822 | type: 'f32', 823 | body: [{ 824 | kind: 'get_local', 825 | id: { 826 | kind: 'literal', 827 | value: 0, 828 | raw: '0' 829 | } 830 | }] 831 | }] 832 | }, 833 | failure: { 834 | kind: 'literal', 835 | value: 'constant expression required' 836 | } 837 | }, 838 | { 839 | kind: 'assert_invalid', 840 | module: { 841 | kind: 'module', 842 | body: [{ 843 | kind: 'global', 844 | id: null, 845 | mut: false, 846 | expo: null, 847 | impo: null, 848 | type: 'f32', 849 | body: [{ 850 | kind: 'unop', 851 | type: 'f32', 852 | operator: 'neg', 853 | expr: { 854 | kind: 'const', 855 | type: 'f32', 856 | init: '1' 857 | } 858 | }] 859 | }] 860 | }, 861 | failure: { 862 | kind: 'literal', 863 | value: 'constant expression required' 864 | } 865 | }, 866 | { 867 | kind: 'assert_invalid', 868 | module: { 869 | kind: 'module', 870 | body: [{ 871 | kind: 'global', 872 | id: null, 873 | mut: false, 874 | expo: null, 875 | impo: null, 876 | type: 'i32', 877 | body: [ 878 | { 879 | kind: 'const', 880 | type: 'i32', 881 | init: '0' 882 | }, 883 | {kind: 'nop'} 884 | ] 885 | }] 886 | }, 887 | failure: { 888 | kind: 'literal', 889 | value: 'constant expression required' 890 | } 891 | }, 892 | { 893 | kind: 'assert_invalid', 894 | module: { 895 | kind: 'module', 896 | body: [{ 897 | kind: 'global', 898 | id: null, 899 | mut: false, 900 | expo: null, 901 | impo: null, 902 | type: 'i32', 903 | body: [{kind: 'nop'}] 904 | }] 905 | }, 906 | failure: { 907 | kind: 'literal', 908 | value: 'constant expression required' 909 | } 910 | }, 911 | { 912 | kind: 'assert_invalid', 913 | module: { 914 | kind: 'module', 915 | body: [{ 916 | kind: 'global', 917 | id: null, 918 | mut: false, 919 | expo: null, 920 | impo: null, 921 | type: 'i32', 922 | body: [{ 923 | kind: 'const', 924 | type: 'f32', 925 | init: '0' 926 | }] 927 | }] 928 | }, 929 | failure: { 930 | kind: 'literal', 931 | value: 'type mismatch' 932 | } 933 | }, 934 | { 935 | kind: 'assert_invalid', 936 | module: { 937 | kind: 'module', 938 | body: [{ 939 | kind: 'global', 940 | id: null, 941 | mut: false, 942 | expo: null, 943 | impo: null, 944 | type: 'i32', 945 | body: [ 946 | { 947 | kind: 'const', 948 | type: 'i32', 949 | init: '0' 950 | }, 951 | { 952 | kind: 'const', 953 | type: 'i32', 954 | init: '0' 955 | } 956 | ] 957 | }] 958 | }, 959 | failure: { 960 | kind: 'literal', 961 | value: 'type mismatch' 962 | } 963 | }, 964 | { 965 | kind: 'assert_invalid', 966 | module: { 967 | kind: 'module', 968 | body: [{ 969 | kind: 'global', 970 | id: null, 971 | mut: false, 972 | expo: null, 973 | impo: null, 974 | type: 'i32', 975 | body: [] 976 | }] 977 | }, 978 | failure: { 979 | kind: 'literal', 980 | value: 'type mismatch' 981 | } 982 | }, 983 | { 984 | kind: 'assert_invalid', 985 | module: { 986 | kind: 'module', 987 | body: [{ 988 | kind: 'global', 989 | id: null, 990 | mut: false, 991 | expo: null, 992 | impo: null, 993 | type: 'i32', 994 | body: [{ 995 | kind: 'get_global', 996 | id: { 997 | kind: 'literal', 998 | value: 0, 999 | raw: '0' 1000 | } 1001 | }] 1002 | }] 1003 | }, 1004 | failure: { 1005 | kind: 'literal', 1006 | value: 'unknown global' 1007 | } 1008 | }, 1009 | { 1010 | kind: 'assert_invalid', 1011 | module: { 1012 | kind: 'module', 1013 | body: [ 1014 | { 1015 | kind: 'global', 1016 | id: null, 1017 | mut: false, 1018 | expo: null, 1019 | impo: null, 1020 | type: 'i32', 1021 | body: [{ 1022 | kind: 'get_global', 1023 | id: { 1024 | kind: 'literal', 1025 | value: 1, 1026 | raw: '1' 1027 | } 1028 | }] 1029 | }, 1030 | { 1031 | kind: 'global', 1032 | id: null, 1033 | mut: false, 1034 | expo: null, 1035 | impo: null, 1036 | type: 'i32', 1037 | body: [{ 1038 | kind: 'const', 1039 | type: 'i32', 1040 | init: '0' 1041 | }] 1042 | } 1043 | ] 1044 | }, 1045 | failure: { 1046 | kind: 'literal', 1047 | value: 'unknown global' 1048 | } 1049 | }, 1050 | { 1051 | kind: 'module', 1052 | body: [{ 1053 | kind: 'import', 1054 | id: null, 1055 | modName: { 1056 | kind: 'literal', 1057 | value: 'spectest' 1058 | }, 1059 | funcName: { 1060 | kind: 'literal', 1061 | value: 'global_i32' 1062 | }, 1063 | type: { 1064 | kind: 'global', 1065 | id: null, 1066 | mut: false, 1067 | expo: null, 1068 | impo: null, 1069 | type: 'i32', 1070 | body: [] 1071 | }, 1072 | params: [], 1073 | result: null 1074 | }] 1075 | }, 1076 | { 1077 | kind: 'assert_malformed', 1078 | module: { 1079 | kind: 'module', 1080 | body: [ 1081 | 'binary', 1082 | { 1083 | kind: 'literal', 1084 | value: '\\00asm' 1085 | }, 1086 | { 1087 | kind: 'literal', 1088 | value: '\\01\\00\\00\\00' 1089 | }, 1090 | { 1091 | kind: 'literal', 1092 | value: '\\02\\94\\80\\80\\80\\00' 1093 | }, 1094 | { 1095 | kind: 'literal', 1096 | value: '\\01' 1097 | }, 1098 | { 1099 | kind: 'literal', 1100 | value: '\\08\\73\\70\\65\\63\\74\\65\\73\\74' 1101 | }, 1102 | { 1103 | kind: 'literal', 1104 | value: '\\0a\\67\\6c\\6f\\62\\61\\6c\\5f\\69\\33\\32' 1105 | }, 1106 | { 1107 | kind: 'literal', 1108 | value: '\\03' 1109 | }, 1110 | { 1111 | kind: 'literal', 1112 | value: '\\7f' 1113 | }, 1114 | { 1115 | kind: 'literal', 1116 | value: '\\02' 1117 | } 1118 | ] 1119 | }, 1120 | failure: { 1121 | kind: 'literal', 1122 | value: 'invalid mutability' 1123 | } 1124 | }, 1125 | { 1126 | kind: 'assert_malformed', 1127 | module: { 1128 | kind: 'module', 1129 | body: [ 1130 | 'binary', 1131 | { 1132 | kind: 'literal', 1133 | value: '\\00asm' 1134 | }, 1135 | { 1136 | kind: 'literal', 1137 | value: '\\01\\00\\00\\00' 1138 | }, 1139 | { 1140 | kind: 'literal', 1141 | value: '\\02\\94\\80\\80\\80\\00' 1142 | }, 1143 | { 1144 | kind: 'literal', 1145 | value: '\\01' 1146 | }, 1147 | { 1148 | kind: 'literal', 1149 | value: '\\08\\73\\70\\65\\63\\74\\65\\73\\74' 1150 | }, 1151 | { 1152 | kind: 'literal', 1153 | value: '\\0a\\67\\6c\\6f\\62\\61\\6c\\5f\\69\\33\\32' 1154 | }, 1155 | { 1156 | kind: 'literal', 1157 | value: '\\03' 1158 | }, 1159 | { 1160 | kind: 'literal', 1161 | value: '\\7f' 1162 | }, 1163 | { 1164 | kind: 'literal', 1165 | value: '\\ff' 1166 | } 1167 | ] 1168 | }, 1169 | failure: { 1170 | kind: 'literal', 1171 | value: 'invalid mutability' 1172 | } 1173 | }, 1174 | { 1175 | kind: 'module', 1176 | body: [{ 1177 | kind: 'global', 1178 | id: null, 1179 | mut: false, 1180 | expo: null, 1181 | impo: null, 1182 | type: 'i32', 1183 | body: [{ 1184 | kind: 'const', 1185 | type: 'i32', 1186 | init: '0' 1187 | }] 1188 | }] 1189 | }, 1190 | { 1191 | kind: 'assert_malformed', 1192 | module: { 1193 | kind: 'module', 1194 | body: [ 1195 | 'binary', 1196 | { 1197 | kind: 'literal', 1198 | value: '\\00asm' 1199 | }, 1200 | { 1201 | kind: 'literal', 1202 | value: '\\01\\00\\00\\00' 1203 | }, 1204 | { 1205 | kind: 'literal', 1206 | value: '\\06\\86\\80\\80\\80\\00' 1207 | }, 1208 | { 1209 | kind: 'literal', 1210 | value: '\\01' 1211 | }, 1212 | { 1213 | kind: 'literal', 1214 | value: '\\7f' 1215 | }, 1216 | { 1217 | kind: 'literal', 1218 | value: '\\02' 1219 | }, 1220 | { 1221 | kind: 'literal', 1222 | value: '\\41\\00' 1223 | }, 1224 | { 1225 | kind: 'literal', 1226 | value: '\\0b' 1227 | } 1228 | ] 1229 | }, 1230 | failure: { 1231 | kind: 'literal', 1232 | value: 'invalid mutability' 1233 | } 1234 | }, 1235 | { 1236 | kind: 'assert_malformed', 1237 | module: { 1238 | kind: 'module', 1239 | body: [ 1240 | 'binary', 1241 | { 1242 | kind: 'literal', 1243 | value: '\\00asm' 1244 | }, 1245 | { 1246 | kind: 'literal', 1247 | value: '\\01\\00\\00\\00' 1248 | }, 1249 | { 1250 | kind: 'literal', 1251 | value: '\\06\\86\\80\\80\\80\\00' 1252 | }, 1253 | { 1254 | kind: 'literal', 1255 | value: '\\01' 1256 | }, 1257 | { 1258 | kind: 'literal', 1259 | value: '\\7f' 1260 | }, 1261 | { 1262 | kind: 'literal', 1263 | value: '\\ff' 1264 | }, 1265 | { 1266 | kind: 'literal', 1267 | value: '\\41\\00' 1268 | }, 1269 | { 1270 | kind: 'literal', 1271 | value: '\\0b' 1272 | } 1273 | ] 1274 | }, 1275 | failure: { 1276 | kind: 'literal', 1277 | value: 'invalid mutability' 1278 | } 1279 | } 1280 | ] 1281 | } 1282 | -------------------------------------------------------------------------------- /results/inline-module.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'func', 6 | id: null, 7 | expos: [], 8 | imp: null, 9 | type: null, 10 | params: [], 11 | result: null, 12 | local: [], 13 | body: [] 14 | }, 15 | { 16 | kind: 'memory', 17 | impo: null, 18 | expo: null, 19 | int: { 20 | kind: 'literal', 21 | value: 0, 22 | raw: [ 23 | [' '], 24 | '0' 25 | ] 26 | }, 27 | int1: null, 28 | segment: [] 29 | }, 30 | { 31 | kind: 'func', 32 | id: null, 33 | expos: [{ 34 | kind: 'literal', 35 | value: 'f' 36 | }], 37 | imp: null, 38 | type: null, 39 | params: [], 40 | result: null, 41 | local: [], 42 | body: [] 43 | } 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /results/memory_redundancy.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'module', 6 | body: [ 7 | { 8 | kind: 'memory', 9 | impo: null, 10 | expo: null, 11 | int: { 12 | kind: 'literal', 13 | value: 1, 14 | raw: [ 15 | [' '], 16 | '1' 17 | ] 18 | }, 19 | int1: { 20 | kind: 'literal', 21 | value: 1, 22 | raw: '1' 23 | }, 24 | segment: [] 25 | }, 26 | { 27 | kind: 'func', 28 | id: null, 29 | expos: [{ 30 | kind: 'literal', 31 | value: 'zero_everything' 32 | }], 33 | imp: null, 34 | type: null, 35 | params: [], 36 | result: null, 37 | local: [], 38 | body: [ 39 | { 40 | kind: 'store', 41 | type: 'i32', 42 | size: null, 43 | offset: 0, 44 | align: 0, 45 | addr: { 46 | kind: 'const', 47 | type: 'i32', 48 | init: '0' 49 | }, 50 | data: { 51 | kind: 'const', 52 | type: 'i32', 53 | init: '0' 54 | } 55 | }, 56 | { 57 | kind: 'store', 58 | type: 'i32', 59 | size: null, 60 | offset: 0, 61 | align: 0, 62 | addr: { 63 | kind: 'const', 64 | type: 'i32', 65 | init: '4' 66 | }, 67 | data: { 68 | kind: 'const', 69 | type: 'i32', 70 | init: '0' 71 | } 72 | }, 73 | { 74 | kind: 'store', 75 | type: 'i32', 76 | size: null, 77 | offset: 0, 78 | align: 0, 79 | addr: { 80 | kind: 'const', 81 | type: 'i32', 82 | init: '8' 83 | }, 84 | data: { 85 | kind: 'const', 86 | type: 'i32', 87 | init: '0' 88 | } 89 | }, 90 | { 91 | kind: 'store', 92 | type: 'i32', 93 | size: null, 94 | offset: 0, 95 | align: 0, 96 | addr: { 97 | kind: 'const', 98 | type: 'i32', 99 | init: '12' 100 | }, 101 | data: { 102 | kind: 'const', 103 | type: 'i32', 104 | init: '0' 105 | } 106 | } 107 | ] 108 | }, 109 | { 110 | kind: 'func', 111 | id: null, 112 | expos: [{ 113 | kind: 'literal', 114 | value: 'test_store_to_load' 115 | }], 116 | imp: null, 117 | type: null, 118 | params: [], 119 | result: { 120 | kind: 'result', 121 | type: 'i32' 122 | }, 123 | local: [], 124 | body: [ 125 | { 126 | kind: 'store', 127 | type: 'i32', 128 | size: null, 129 | offset: 0, 130 | align: 0, 131 | addr: { 132 | kind: 'const', 133 | type: 'i32', 134 | init: '8' 135 | }, 136 | data: { 137 | kind: 'const', 138 | type: 'i32', 139 | init: '0' 140 | } 141 | }, 142 | { 143 | kind: 'store', 144 | type: 'f32', 145 | size: null, 146 | offset: 0, 147 | align: 0, 148 | addr: { 149 | kind: 'const', 150 | type: 'i32', 151 | init: '5' 152 | }, 153 | data: { 154 | kind: 'const', 155 | type: 'f32', 156 | init: '-0.0' 157 | } 158 | }, 159 | { 160 | kind: 'load', 161 | type: 'i32', 162 | size: null, 163 | sign: null, 164 | offset: 0, 165 | align: 0, 166 | expr: { 167 | kind: 'const', 168 | type: 'i32', 169 | init: '8' 170 | } 171 | } 172 | ] 173 | }, 174 | { 175 | kind: 'func', 176 | id: null, 177 | expos: [{ 178 | kind: 'literal', 179 | value: 'test_redundant_load' 180 | }], 181 | imp: null, 182 | type: null, 183 | params: [], 184 | result: { 185 | kind: 'result', 186 | type: 'i32' 187 | }, 188 | local: [ 189 | { 190 | kind: 'local', 191 | items: [{ 192 | kind: 'item', 193 | name: 't', 194 | type: 'i32' 195 | }] 196 | }, 197 | { 198 | kind: 'local', 199 | items: [{ 200 | kind: 'item', 201 | name: 's', 202 | type: 'i32' 203 | }] 204 | } 205 | ], 206 | body: [ 207 | { 208 | kind: 'set_local', 209 | id: { 210 | kind: 'identifier', 211 | name: 't' 212 | }, 213 | init: { 214 | kind: 'load', 215 | type: 'i32', 216 | size: null, 217 | sign: null, 218 | offset: 0, 219 | align: 0, 220 | expr: { 221 | kind: 'const', 222 | type: 'i32', 223 | init: '8' 224 | } 225 | } 226 | }, 227 | { 228 | kind: 'store', 229 | type: 'i32', 230 | size: null, 231 | offset: 0, 232 | align: 0, 233 | addr: { 234 | kind: 'const', 235 | type: 'i32', 236 | init: '5' 237 | }, 238 | data: { 239 | kind: 'const', 240 | type: 'i32', 241 | init: '0x80000000' 242 | } 243 | }, 244 | { 245 | kind: 'set_local', 246 | id: { 247 | kind: 'identifier', 248 | name: 's' 249 | }, 250 | init: { 251 | kind: 'load', 252 | type: 'i32', 253 | size: null, 254 | sign: null, 255 | offset: 0, 256 | align: 0, 257 | expr: { 258 | kind: 'const', 259 | type: 'i32', 260 | init: '8' 261 | } 262 | } 263 | }, 264 | { 265 | kind: 'binop', 266 | type: 'i32', 267 | operator: 'add', 268 | left: { 269 | kind: 'get_local', 270 | id: { 271 | kind: 'identifier', 272 | name: 't' 273 | } 274 | }, 275 | right: { 276 | kind: 'get_local', 277 | id: { 278 | kind: 'identifier', 279 | name: 's' 280 | } 281 | } 282 | } 283 | ] 284 | }, 285 | { 286 | kind: 'func', 287 | id: null, 288 | expos: [{ 289 | kind: 'literal', 290 | value: 'test_dead_store' 291 | }], 292 | imp: null, 293 | type: null, 294 | params: [], 295 | result: { 296 | kind: 'result', 297 | type: 'f32' 298 | }, 299 | local: [{ 300 | kind: 'local', 301 | items: [{ 302 | kind: 'item', 303 | name: 't', 304 | type: 'f32' 305 | }] 306 | }], 307 | body: [ 308 | { 309 | kind: 'store', 310 | type: 'i32', 311 | size: null, 312 | offset: 0, 313 | align: 0, 314 | addr: { 315 | kind: 'const', 316 | type: 'i32', 317 | init: '8' 318 | }, 319 | data: { 320 | kind: 'const', 321 | type: 'i32', 322 | init: '0x23232323' 323 | } 324 | }, 325 | { 326 | kind: 'set_local', 327 | id: { 328 | kind: 'identifier', 329 | name: 't' 330 | }, 331 | init: { 332 | kind: 'load', 333 | type: 'f32', 334 | size: null, 335 | sign: null, 336 | offset: 0, 337 | align: 0, 338 | expr: { 339 | kind: 'const', 340 | type: 'i32', 341 | init: '11' 342 | } 343 | } 344 | }, 345 | { 346 | kind: 'store', 347 | type: 'i32', 348 | size: null, 349 | offset: 0, 350 | align: 0, 351 | addr: { 352 | kind: 'const', 353 | type: 'i32', 354 | init: '8' 355 | }, 356 | data: { 357 | kind: 'const', 358 | type: 'i32', 359 | init: '0' 360 | } 361 | }, 362 | { 363 | kind: 'get_local', 364 | id: { 365 | kind: 'identifier', 366 | name: 't' 367 | } 368 | } 369 | ] 370 | }, 371 | { 372 | kind: 'func', 373 | id: { 374 | kind: 'identifier', 375 | name: 'malloc' 376 | }, 377 | expos: [{ 378 | kind: 'literal', 379 | value: 'malloc' 380 | }], 381 | imp: null, 382 | type: null, 383 | params: [{ 384 | kind: 'param', 385 | id: { 386 | kind: 'identifier', 387 | name: 'size' 388 | }, 389 | items: [{ 390 | kind: 'item', 391 | type: 'i32' 392 | }] 393 | }], 394 | result: { 395 | kind: 'result', 396 | type: 'i32' 397 | }, 398 | local: [], 399 | body: [{ 400 | kind: 'const', 401 | type: 'i32', 402 | init: '16' 403 | }] 404 | }, 405 | { 406 | kind: 'func', 407 | id: null, 408 | expos: [{ 409 | kind: 'literal', 410 | value: 'malloc_aliasing' 411 | }], 412 | imp: null, 413 | type: null, 414 | params: [], 415 | result: { 416 | kind: 'result', 417 | type: 'i32' 418 | }, 419 | local: [ 420 | { 421 | kind: 'local', 422 | items: [{ 423 | kind: 'item', 424 | name: 'x', 425 | type: 'i32' 426 | }] 427 | }, 428 | { 429 | kind: 'local', 430 | items: [{ 431 | kind: 'item', 432 | name: 'y', 433 | type: 'i32' 434 | }] 435 | } 436 | ], 437 | body: [ 438 | { 439 | kind: 'set_local', 440 | id: { 441 | kind: 'identifier', 442 | name: 'x' 443 | }, 444 | init: { 445 | kind: 'call', 446 | id: { 447 | kind: 'identifier', 448 | name: 'malloc' 449 | }, 450 | exprs: [{ 451 | kind: 'const', 452 | type: 'i32', 453 | init: '4' 454 | }] 455 | } 456 | }, 457 | { 458 | kind: 'set_local', 459 | id: { 460 | kind: 'identifier', 461 | name: 'y' 462 | }, 463 | init: { 464 | kind: 'call', 465 | id: { 466 | kind: 'identifier', 467 | name: 'malloc' 468 | }, 469 | exprs: [{ 470 | kind: 'const', 471 | type: 'i32', 472 | init: '4' 473 | }] 474 | } 475 | }, 476 | { 477 | kind: 'store', 478 | type: 'i32', 479 | size: null, 480 | offset: 0, 481 | align: 0, 482 | addr: { 483 | kind: 'get_local', 484 | id: { 485 | kind: 'identifier', 486 | name: 'x' 487 | } 488 | }, 489 | data: { 490 | kind: 'const', 491 | type: 'i32', 492 | init: '42' 493 | } 494 | }, 495 | { 496 | kind: 'store', 497 | type: 'i32', 498 | size: null, 499 | offset: 0, 500 | align: 0, 501 | addr: { 502 | kind: 'get_local', 503 | id: { 504 | kind: 'identifier', 505 | name: 'y' 506 | } 507 | }, 508 | data: { 509 | kind: 'const', 510 | type: 'i32', 511 | init: '43' 512 | } 513 | }, 514 | { 515 | kind: 'load', 516 | type: 'i32', 517 | size: null, 518 | sign: null, 519 | offset: 0, 520 | align: 0, 521 | expr: { 522 | kind: 'get_local', 523 | id: { 524 | kind: 'identifier', 525 | name: 'x' 526 | } 527 | } 528 | } 529 | ] 530 | } 531 | ] 532 | }, 533 | { 534 | kind: 'assert_return', 535 | invoke: { 536 | kind: 'invoke', 537 | id: null, 538 | name: 'test_store_to_load', 539 | body: [] 540 | }, 541 | expr: { 542 | kind: 'const', 543 | type: 'i32', 544 | init: '0x00000080' 545 | } 546 | }, 547 | { 548 | kind: 'invoke', 549 | id: null, 550 | name: 'zero_everything', 551 | body: [] 552 | }, 553 | { 554 | kind: 'assert_return', 555 | invoke: { 556 | kind: 'invoke', 557 | id: null, 558 | name: 'test_redundant_load', 559 | body: [] 560 | }, 561 | expr: { 562 | kind: 'const', 563 | type: 'i32', 564 | init: '0x00000080' 565 | } 566 | }, 567 | { 568 | kind: 'invoke', 569 | id: null, 570 | name: 'zero_everything', 571 | body: [] 572 | }, 573 | { 574 | kind: 'assert_return', 575 | invoke: { 576 | kind: 'invoke', 577 | id: null, 578 | name: 'test_dead_store', 579 | body: [] 580 | }, 581 | expr: { 582 | kind: 'const', 583 | type: 'f32', 584 | init: '0x1.18p-144' 585 | } 586 | }, 587 | { 588 | kind: 'invoke', 589 | id: null, 590 | name: 'zero_everything', 591 | body: [] 592 | }, 593 | { 594 | kind: 'assert_return', 595 | invoke: { 596 | kind: 'invoke', 597 | id: null, 598 | name: 'malloc_aliasing', 599 | body: [] 600 | }, 601 | expr: { 602 | kind: 'const', 603 | type: 'i32', 604 | init: '43' 605 | } 606 | } 607 | ] 608 | } 609 | -------------------------------------------------------------------------------- /results/resizing.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'module', 6 | body: [ 7 | { 8 | kind: 'memory', 9 | impo: null, 10 | expo: null, 11 | int: { 12 | kind: 'literal', 13 | value: 0, 14 | raw: [ 15 | [' '], 16 | '0' 17 | ] 18 | }, 19 | int1: null, 20 | segment: [] 21 | }, 22 | { 23 | kind: 'func', 24 | id: null, 25 | expos: [{ 26 | kind: 'literal', 27 | value: 'load_at_zero' 28 | }], 29 | imp: null, 30 | type: null, 31 | params: [], 32 | result: { 33 | kind: 'result', 34 | type: 'i32' 35 | }, 36 | local: [], 37 | body: [{ 38 | kind: 'load', 39 | type: 'i32', 40 | size: null, 41 | sign: null, 42 | offset: 0, 43 | align: 0, 44 | expr: { 45 | kind: 'const', 46 | type: 'i32', 47 | init: '0' 48 | } 49 | }] 50 | }, 51 | { 52 | kind: 'func', 53 | id: null, 54 | expos: [{ 55 | kind: 'literal', 56 | value: 'store_at_zero' 57 | }], 58 | imp: null, 59 | type: null, 60 | params: [], 61 | result: null, 62 | local: [], 63 | body: [{ 64 | kind: 'store', 65 | type: 'i32', 66 | size: null, 67 | offset: 0, 68 | align: 0, 69 | addr: { 70 | kind: 'const', 71 | type: 'i32', 72 | init: '0' 73 | }, 74 | data: { 75 | kind: 'const', 76 | type: 'i32', 77 | init: '2' 78 | } 79 | }] 80 | }, 81 | { 82 | kind: 'func', 83 | id: null, 84 | expos: [{ 85 | kind: 'literal', 86 | value: 'load_at_page_size' 87 | }], 88 | imp: null, 89 | type: null, 90 | params: [], 91 | result: { 92 | kind: 'result', 93 | type: 'i32' 94 | }, 95 | local: [], 96 | body: [{ 97 | kind: 'load', 98 | type: 'i32', 99 | size: null, 100 | sign: null, 101 | offset: 0, 102 | align: 0, 103 | expr: { 104 | kind: 'const', 105 | type: 'i32', 106 | init: '0x10000' 107 | } 108 | }] 109 | }, 110 | { 111 | kind: 'func', 112 | id: null, 113 | expos: [{ 114 | kind: 'literal', 115 | value: 'store_at_page_size' 116 | }], 117 | imp: null, 118 | type: null, 119 | params: [], 120 | result: null, 121 | local: [], 122 | body: [{ 123 | kind: 'store', 124 | type: 'i32', 125 | size: null, 126 | offset: 0, 127 | align: 0, 128 | addr: { 129 | kind: 'const', 130 | type: 'i32', 131 | init: '0x10000' 132 | }, 133 | data: { 134 | kind: 'const', 135 | type: 'i32', 136 | init: '3' 137 | } 138 | }] 139 | }, 140 | { 141 | kind: 'func', 142 | id: null, 143 | expos: [{ 144 | kind: 'literal', 145 | value: 'grow' 146 | }], 147 | imp: null, 148 | type: null, 149 | params: [{ 150 | kind: 'param', 151 | id: { 152 | kind: 'identifier', 153 | name: 'sz' 154 | }, 155 | items: [{ 156 | kind: 'item', 157 | type: 'i32' 158 | }] 159 | }], 160 | result: { 161 | kind: 'result', 162 | type: 'i32' 163 | }, 164 | local: [], 165 | body: [{ 166 | kind: 'memory.grow', 167 | expr: { 168 | kind: 'get_local', 169 | id: { 170 | kind: 'identifier', 171 | name: 'sz' 172 | } 173 | } 174 | }] 175 | }, 176 | { 177 | kind: 'func', 178 | id: null, 179 | expos: [{ 180 | kind: 'literal', 181 | value: 'size' 182 | }], 183 | imp: null, 184 | type: null, 185 | params: [], 186 | result: { 187 | kind: 'result', 188 | type: 'i32' 189 | }, 190 | local: [], 191 | body: [{kind: 'memory.size'}] 192 | } 193 | ] 194 | }, 195 | { 196 | kind: 'assert_return', 197 | invoke: { 198 | kind: 'invoke', 199 | id: null, 200 | name: 'size', 201 | body: [] 202 | }, 203 | expr: { 204 | kind: 'const', 205 | type: 'i32', 206 | init: '0' 207 | } 208 | }, 209 | { 210 | kind: 'assert_trap', 211 | invoke: { 212 | kind: 'invoke', 213 | id: null, 214 | name: 'store_at_zero', 215 | body: [] 216 | }, 217 | failure: { 218 | kind: 'literal', 219 | value: 'out of bounds memory access' 220 | } 221 | }, 222 | { 223 | kind: 'assert_trap', 224 | invoke: { 225 | kind: 'invoke', 226 | id: null, 227 | name: 'load_at_zero', 228 | body: [] 229 | }, 230 | failure: { 231 | kind: 'literal', 232 | value: 'out of bounds memory access' 233 | } 234 | }, 235 | { 236 | kind: 'assert_trap', 237 | invoke: { 238 | kind: 'invoke', 239 | id: null, 240 | name: 'store_at_page_size', 241 | body: [] 242 | }, 243 | failure: { 244 | kind: 'literal', 245 | value: 'out of bounds memory access' 246 | } 247 | }, 248 | { 249 | kind: 'assert_trap', 250 | invoke: { 251 | kind: 'invoke', 252 | id: null, 253 | name: 'load_at_page_size', 254 | body: [] 255 | }, 256 | failure: { 257 | kind: 'literal', 258 | value: 'out of bounds memory access' 259 | } 260 | }, 261 | { 262 | kind: 'assert_return', 263 | invoke: { 264 | kind: 'invoke', 265 | id: null, 266 | name: 'grow', 267 | body: [{ 268 | kind: 'const', 269 | type: 'i32', 270 | init: '1' 271 | }] 272 | }, 273 | expr: { 274 | kind: 'const', 275 | type: 'i32', 276 | init: '0' 277 | } 278 | }, 279 | { 280 | kind: 'assert_return', 281 | invoke: { 282 | kind: 'invoke', 283 | id: null, 284 | name: 'size', 285 | body: [] 286 | }, 287 | expr: { 288 | kind: 'const', 289 | type: 'i32', 290 | init: '1' 291 | } 292 | }, 293 | { 294 | kind: 'assert_return', 295 | invoke: { 296 | kind: 'invoke', 297 | id: null, 298 | name: 'load_at_zero', 299 | body: [] 300 | }, 301 | expr: { 302 | kind: 'const', 303 | type: 'i32', 304 | init: '0' 305 | } 306 | }, 307 | { 308 | kind: 'assert_return', 309 | invoke: { 310 | kind: 'invoke', 311 | id: null, 312 | name: 'store_at_zero', 313 | body: [] 314 | }, 315 | expr: null 316 | }, 317 | { 318 | kind: 'assert_return', 319 | invoke: { 320 | kind: 'invoke', 321 | id: null, 322 | name: 'load_at_zero', 323 | body: [] 324 | }, 325 | expr: { 326 | kind: 'const', 327 | type: 'i32', 328 | init: '2' 329 | } 330 | }, 331 | { 332 | kind: 'assert_trap', 333 | invoke: { 334 | kind: 'invoke', 335 | id: null, 336 | name: 'store_at_page_size', 337 | body: [] 338 | }, 339 | failure: { 340 | kind: 'literal', 341 | value: 'out of bounds memory access' 342 | } 343 | }, 344 | { 345 | kind: 'assert_trap', 346 | invoke: { 347 | kind: 'invoke', 348 | id: null, 349 | name: 'load_at_page_size', 350 | body: [] 351 | }, 352 | failure: { 353 | kind: 'literal', 354 | value: 'out of bounds memory access' 355 | } 356 | }, 357 | { 358 | kind: 'assert_return', 359 | invoke: { 360 | kind: 'invoke', 361 | id: null, 362 | name: 'grow', 363 | body: [{ 364 | kind: 'const', 365 | type: 'i32', 366 | init: '4' 367 | }] 368 | }, 369 | expr: { 370 | kind: 'const', 371 | type: 'i32', 372 | init: '1' 373 | } 374 | }, 375 | { 376 | kind: 'assert_return', 377 | invoke: { 378 | kind: 'invoke', 379 | id: null, 380 | name: 'size', 381 | body: [] 382 | }, 383 | expr: { 384 | kind: 'const', 385 | type: 'i32', 386 | init: '5' 387 | } 388 | }, 389 | { 390 | kind: 'assert_return', 391 | invoke: { 392 | kind: 'invoke', 393 | id: null, 394 | name: 'load_at_zero', 395 | body: [] 396 | }, 397 | expr: { 398 | kind: 'const', 399 | type: 'i32', 400 | init: '2' 401 | } 402 | }, 403 | { 404 | kind: 'assert_return', 405 | invoke: { 406 | kind: 'invoke', 407 | id: null, 408 | name: 'store_at_zero', 409 | body: [] 410 | }, 411 | expr: null 412 | }, 413 | { 414 | kind: 'assert_return', 415 | invoke: { 416 | kind: 'invoke', 417 | id: null, 418 | name: 'load_at_zero', 419 | body: [] 420 | }, 421 | expr: { 422 | kind: 'const', 423 | type: 'i32', 424 | init: '2' 425 | } 426 | }, 427 | { 428 | kind: 'assert_return', 429 | invoke: { 430 | kind: 'invoke', 431 | id: null, 432 | name: 'load_at_page_size', 433 | body: [] 434 | }, 435 | expr: { 436 | kind: 'const', 437 | type: 'i32', 438 | init: '0' 439 | } 440 | }, 441 | { 442 | kind: 'assert_return', 443 | invoke: { 444 | kind: 'invoke', 445 | id: null, 446 | name: 'store_at_page_size', 447 | body: [] 448 | }, 449 | expr: null 450 | }, 451 | { 452 | kind: 'assert_return', 453 | invoke: { 454 | kind: 'invoke', 455 | id: null, 456 | name: 'load_at_page_size', 457 | body: [] 458 | }, 459 | expr: { 460 | kind: 'const', 461 | type: 'i32', 462 | init: '3' 463 | } 464 | }, 465 | { 466 | kind: 'module', 467 | body: [ 468 | { 469 | kind: 'memory', 470 | impo: null, 471 | expo: null, 472 | int: { 473 | kind: 'literal', 474 | value: 0, 475 | raw: [ 476 | [' '], 477 | '0' 478 | ] 479 | }, 480 | int1: null, 481 | segment: [] 482 | }, 483 | { 484 | kind: 'func', 485 | id: null, 486 | expos: [{ 487 | kind: 'literal', 488 | value: 'grow' 489 | }], 490 | imp: null, 491 | type: null, 492 | params: [{ 493 | kind: 'param', 494 | id: null, 495 | items: [{ 496 | kind: 'item', 497 | type: 'i32' 498 | }] 499 | }], 500 | result: { 501 | kind: 'result', 502 | type: 'i32' 503 | }, 504 | local: [], 505 | body: [{ 506 | kind: 'memory.grow', 507 | expr: { 508 | kind: 'get_local', 509 | id: { 510 | kind: 'literal', 511 | value: 0, 512 | raw: '0' 513 | } 514 | } 515 | }] 516 | } 517 | ] 518 | }, 519 | { 520 | kind: 'assert_return', 521 | invoke: { 522 | kind: 'invoke', 523 | id: null, 524 | name: 'grow', 525 | body: [{ 526 | kind: 'const', 527 | type: 'i32', 528 | init: '0' 529 | }] 530 | }, 531 | expr: { 532 | kind: 'const', 533 | type: 'i32', 534 | init: '0' 535 | } 536 | }, 537 | { 538 | kind: 'assert_return', 539 | invoke: { 540 | kind: 'invoke', 541 | id: null, 542 | name: 'grow', 543 | body: [{ 544 | kind: 'const', 545 | type: 'i32', 546 | init: '1' 547 | }] 548 | }, 549 | expr: { 550 | kind: 'const', 551 | type: 'i32', 552 | init: '0' 553 | } 554 | }, 555 | { 556 | kind: 'assert_return', 557 | invoke: { 558 | kind: 'invoke', 559 | id: null, 560 | name: 'grow', 561 | body: [{ 562 | kind: 'const', 563 | type: 'i32', 564 | init: '0' 565 | }] 566 | }, 567 | expr: { 568 | kind: 'const', 569 | type: 'i32', 570 | init: '1' 571 | } 572 | }, 573 | { 574 | kind: 'assert_return', 575 | invoke: { 576 | kind: 'invoke', 577 | id: null, 578 | name: 'grow', 579 | body: [{ 580 | kind: 'const', 581 | type: 'i32', 582 | init: '2' 583 | }] 584 | }, 585 | expr: { 586 | kind: 'const', 587 | type: 'i32', 588 | init: '1' 589 | } 590 | }, 591 | { 592 | kind: 'assert_return', 593 | invoke: { 594 | kind: 'invoke', 595 | id: null, 596 | name: 'grow', 597 | body: [{ 598 | kind: 'const', 599 | type: 'i32', 600 | init: '800' 601 | }] 602 | }, 603 | expr: { 604 | kind: 'const', 605 | type: 'i32', 606 | init: '3' 607 | } 608 | }, 609 | { 610 | kind: 'assert_return', 611 | invoke: { 612 | kind: 'invoke', 613 | id: null, 614 | name: 'grow', 615 | body: [{ 616 | kind: 'const', 617 | type: 'i32', 618 | init: '0x10000' 619 | }] 620 | }, 621 | expr: { 622 | kind: 'const', 623 | type: 'i32', 624 | init: '-1' 625 | } 626 | }, 627 | { 628 | kind: 'module', 629 | body: [ 630 | { 631 | kind: 'memory', 632 | impo: null, 633 | expo: null, 634 | int: { 635 | kind: 'literal', 636 | value: 0, 637 | raw: [ 638 | [' '], 639 | '0' 640 | ] 641 | }, 642 | int1: { 643 | kind: 'literal', 644 | value: 10, 645 | raw: '10' 646 | }, 647 | segment: [] 648 | }, 649 | { 650 | kind: 'func', 651 | id: null, 652 | expos: [{ 653 | kind: 'literal', 654 | value: 'grow' 655 | }], 656 | imp: null, 657 | type: null, 658 | params: [{ 659 | kind: 'param', 660 | id: null, 661 | items: [{ 662 | kind: 'item', 663 | type: 'i32' 664 | }] 665 | }], 666 | result: { 667 | kind: 'result', 668 | type: 'i32' 669 | }, 670 | local: [], 671 | body: [{ 672 | kind: 'memory.grow', 673 | expr: { 674 | kind: 'get_local', 675 | id: { 676 | kind: 'literal', 677 | value: 0, 678 | raw: '0' 679 | } 680 | } 681 | }] 682 | } 683 | ] 684 | }, 685 | { 686 | kind: 'assert_return', 687 | invoke: { 688 | kind: 'invoke', 689 | id: null, 690 | name: 'grow', 691 | body: [{ 692 | kind: 'const', 693 | type: 'i32', 694 | init: '0' 695 | }] 696 | }, 697 | expr: { 698 | kind: 'const', 699 | type: 'i32', 700 | init: '0' 701 | } 702 | }, 703 | { 704 | kind: 'assert_return', 705 | invoke: { 706 | kind: 'invoke', 707 | id: null, 708 | name: 'grow', 709 | body: [{ 710 | kind: 'const', 711 | type: 'i32', 712 | init: '1' 713 | }] 714 | }, 715 | expr: { 716 | kind: 'const', 717 | type: 'i32', 718 | init: '0' 719 | } 720 | }, 721 | { 722 | kind: 'assert_return', 723 | invoke: { 724 | kind: 'invoke', 725 | id: null, 726 | name: 'grow', 727 | body: [{ 728 | kind: 'const', 729 | type: 'i32', 730 | init: '1' 731 | }] 732 | }, 733 | expr: { 734 | kind: 'const', 735 | type: 'i32', 736 | init: '1' 737 | } 738 | }, 739 | { 740 | kind: 'assert_return', 741 | invoke: { 742 | kind: 'invoke', 743 | id: null, 744 | name: 'grow', 745 | body: [{ 746 | kind: 'const', 747 | type: 'i32', 748 | init: '2' 749 | }] 750 | }, 751 | expr: { 752 | kind: 'const', 753 | type: 'i32', 754 | init: '2' 755 | } 756 | }, 757 | { 758 | kind: 'assert_return', 759 | invoke: { 760 | kind: 'invoke', 761 | id: null, 762 | name: 'grow', 763 | body: [{ 764 | kind: 'const', 765 | type: 'i32', 766 | init: '6' 767 | }] 768 | }, 769 | expr: { 770 | kind: 'const', 771 | type: 'i32', 772 | init: '4' 773 | } 774 | }, 775 | { 776 | kind: 'assert_return', 777 | invoke: { 778 | kind: 'invoke', 779 | id: null, 780 | name: 'grow', 781 | body: [{ 782 | kind: 'const', 783 | type: 'i32', 784 | init: '0' 785 | }] 786 | }, 787 | expr: { 788 | kind: 'const', 789 | type: 'i32', 790 | init: '10' 791 | } 792 | }, 793 | { 794 | kind: 'assert_return', 795 | invoke: { 796 | kind: 'invoke', 797 | id: null, 798 | name: 'grow', 799 | body: [{ 800 | kind: 'const', 801 | type: 'i32', 802 | init: '1' 803 | }] 804 | }, 805 | expr: { 806 | kind: 'const', 807 | type: 'i32', 808 | init: '-1' 809 | } 810 | }, 811 | { 812 | kind: 'assert_return', 813 | invoke: { 814 | kind: 'invoke', 815 | id: null, 816 | name: 'grow', 817 | body: [{ 818 | kind: 'const', 819 | type: 'i32', 820 | init: '0x10000' 821 | }] 822 | }, 823 | expr: { 824 | kind: 'const', 825 | type: 'i32', 826 | init: '-1' 827 | } 828 | } 829 | ] 830 | } 831 | -------------------------------------------------------------------------------- /results/start.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'assert_invalid', 6 | module: { 7 | kind: 'module', 8 | body: [ 9 | { 10 | kind: 'func', 11 | id: null, 12 | expos: [], 13 | imp: null, 14 | type: null, 15 | params: [], 16 | result: null, 17 | local: [], 18 | body: [] 19 | }, 20 | { 21 | kind: 'start', 22 | id: { 23 | kind: 'literal', 24 | value: 1, 25 | raw: '1' 26 | } 27 | } 28 | ] 29 | }, 30 | failure: { 31 | kind: 'literal', 32 | value: 'unknown function' 33 | } 34 | }, 35 | { 36 | kind: 'assert_invalid', 37 | module: { 38 | kind: 'module', 39 | body: [ 40 | { 41 | kind: 'func', 42 | id: { 43 | kind: 'identifier', 44 | name: 'main' 45 | }, 46 | expos: [], 47 | imp: null, 48 | type: null, 49 | params: [], 50 | result: { 51 | kind: 'result', 52 | type: 'i32' 53 | }, 54 | local: [], 55 | body: [{ 56 | kind: 'return', 57 | expr: { 58 | kind: 'const', 59 | type: 'i32', 60 | init: '0' 61 | } 62 | }] 63 | }, 64 | { 65 | kind: 'start', 66 | id: { 67 | kind: 'identifier', 68 | name: 'main' 69 | } 70 | } 71 | ] 72 | }, 73 | failure: { 74 | kind: 'literal', 75 | value: 'start function' 76 | } 77 | }, 78 | { 79 | kind: 'assert_invalid', 80 | module: { 81 | kind: 'module', 82 | body: [ 83 | { 84 | kind: 'func', 85 | id: { 86 | kind: 'identifier', 87 | name: 'main' 88 | }, 89 | expos: [], 90 | imp: null, 91 | type: null, 92 | params: [{ 93 | kind: 'param', 94 | id: { 95 | kind: 'identifier', 96 | name: 'a' 97 | }, 98 | items: [{ 99 | kind: 'item', 100 | type: 'i32' 101 | }] 102 | }], 103 | result: null, 104 | local: [], 105 | body: [] 106 | }, 107 | { 108 | kind: 'start', 109 | id: { 110 | kind: 'identifier', 111 | name: 'main' 112 | } 113 | } 114 | ] 115 | }, 116 | failure: { 117 | kind: 'literal', 118 | value: 'start function' 119 | } 120 | }, 121 | { 122 | kind: 'module', 123 | body: [ 124 | { 125 | kind: 'memory', 126 | impo: null, 127 | expo: null, 128 | int: null, 129 | int1: null, 130 | segment: [{ 131 | kind: 'data', 132 | expr: null, 133 | values: [{ 134 | kind: 'literal', 135 | value: 'A' 136 | }] 137 | }] 138 | }, 139 | { 140 | kind: 'func', 141 | id: { 142 | kind: 'identifier', 143 | name: 'inc' 144 | }, 145 | expos: [], 146 | imp: null, 147 | type: null, 148 | params: [], 149 | result: null, 150 | local: [], 151 | body: [{ 152 | kind: 'store', 153 | type: 'i32', 154 | size: 8, 155 | offset: 0, 156 | align: 0, 157 | addr: { 158 | kind: 'const', 159 | type: 'i32', 160 | init: '0' 161 | }, 162 | data: { 163 | kind: 'binop', 164 | type: 'i32', 165 | operator: 'add', 166 | left: { 167 | kind: 'load', 168 | type: 'i32', 169 | size: 8, 170 | sign: false, 171 | offset: 0, 172 | align: 0, 173 | expr: { 174 | kind: 'const', 175 | type: 'i32', 176 | init: '0' 177 | } 178 | }, 179 | right: { 180 | kind: 'const', 181 | type: 'i32', 182 | init: '1' 183 | } 184 | } 185 | }] 186 | }, 187 | { 188 | kind: 'func', 189 | id: { 190 | kind: 'identifier', 191 | name: 'get' 192 | }, 193 | expos: [], 194 | imp: null, 195 | type: null, 196 | params: [], 197 | result: { 198 | kind: 'result', 199 | type: 'i32' 200 | }, 201 | local: [], 202 | body: [{ 203 | kind: 'return', 204 | expr: { 205 | kind: 'load', 206 | type: 'i32', 207 | size: 8, 208 | sign: false, 209 | offset: 0, 210 | align: 0, 211 | expr: { 212 | kind: 'const', 213 | type: 'i32', 214 | init: '0' 215 | } 216 | } 217 | }] 218 | }, 219 | { 220 | kind: 'func', 221 | id: { 222 | kind: 'identifier', 223 | name: 'main' 224 | }, 225 | expos: [], 226 | imp: null, 227 | type: null, 228 | params: [], 229 | result: null, 230 | local: [], 231 | body: [ 232 | { 233 | kind: 'call', 234 | id: { 235 | kind: 'identifier', 236 | name: 'inc' 237 | }, 238 | exprs: [] 239 | }, 240 | { 241 | kind: 'call', 242 | id: { 243 | kind: 'identifier', 244 | name: 'inc' 245 | }, 246 | exprs: [] 247 | }, 248 | { 249 | kind: 'call', 250 | id: { 251 | kind: 'identifier', 252 | name: 'inc' 253 | }, 254 | exprs: [] 255 | } 256 | ] 257 | }, 258 | { 259 | kind: 'start', 260 | id: { 261 | kind: 'identifier', 262 | name: 'main' 263 | } 264 | }, 265 | { 266 | kind: 'export', 267 | name: { 268 | kind: 'literal', 269 | value: 'inc' 270 | }, 271 | id: { 272 | kind: 'func', 273 | id: { 274 | kind: 'identifier', 275 | name: 'inc' 276 | }, 277 | expos: [], 278 | imp: null, 279 | type: null, 280 | params: [], 281 | result: null, 282 | local: [], 283 | body: [] 284 | } 285 | }, 286 | { 287 | kind: 'export', 288 | name: { 289 | kind: 'literal', 290 | value: 'get' 291 | }, 292 | id: { 293 | kind: 'func', 294 | id: { 295 | kind: 'identifier', 296 | name: 'get' 297 | }, 298 | expos: [], 299 | imp: null, 300 | type: null, 301 | params: [], 302 | result: null, 303 | local: [], 304 | body: [] 305 | } 306 | } 307 | ] 308 | }, 309 | { 310 | kind: 'assert_return', 311 | invoke: { 312 | kind: 'invoke', 313 | id: null, 314 | name: 'get', 315 | body: [] 316 | }, 317 | expr: { 318 | kind: 'const', 319 | type: 'i32', 320 | init: '68' 321 | } 322 | }, 323 | { 324 | kind: 'invoke', 325 | id: null, 326 | name: 'inc', 327 | body: [] 328 | }, 329 | { 330 | kind: 'assert_return', 331 | invoke: { 332 | kind: 'invoke', 333 | id: null, 334 | name: 'get', 335 | body: [] 336 | }, 337 | expr: { 338 | kind: 'const', 339 | type: 'i32', 340 | init: '69' 341 | } 342 | }, 343 | { 344 | kind: 'invoke', 345 | id: null, 346 | name: 'inc', 347 | body: [] 348 | }, 349 | { 350 | kind: 'assert_return', 351 | invoke: { 352 | kind: 'invoke', 353 | id: null, 354 | name: 'get', 355 | body: [] 356 | }, 357 | expr: { 358 | kind: 'const', 359 | type: 'i32', 360 | init: '70' 361 | } 362 | }, 363 | { 364 | kind: 'module', 365 | body: [ 366 | { 367 | kind: 'memory', 368 | impo: null, 369 | expo: null, 370 | int: null, 371 | int1: null, 372 | segment: [{ 373 | kind: 'data', 374 | expr: null, 375 | values: [{ 376 | kind: 'literal', 377 | value: 'A' 378 | }] 379 | }] 380 | }, 381 | { 382 | kind: 'func', 383 | id: { 384 | kind: 'identifier', 385 | name: 'inc' 386 | }, 387 | expos: [], 388 | imp: null, 389 | type: null, 390 | params: [], 391 | result: null, 392 | local: [], 393 | body: [{ 394 | kind: 'store', 395 | type: 'i32', 396 | size: 8, 397 | offset: 0, 398 | align: 0, 399 | addr: { 400 | kind: 'const', 401 | type: 'i32', 402 | init: '0' 403 | }, 404 | data: { 405 | kind: 'binop', 406 | type: 'i32', 407 | operator: 'add', 408 | left: { 409 | kind: 'load', 410 | type: 'i32', 411 | size: 8, 412 | sign: false, 413 | offset: 0, 414 | align: 0, 415 | expr: { 416 | kind: 'const', 417 | type: 'i32', 418 | init: '0' 419 | } 420 | }, 421 | right: { 422 | kind: 'const', 423 | type: 'i32', 424 | init: '1' 425 | } 426 | } 427 | }] 428 | }, 429 | { 430 | kind: 'func', 431 | id: { 432 | kind: 'identifier', 433 | name: 'get' 434 | }, 435 | expos: [], 436 | imp: null, 437 | type: null, 438 | params: [], 439 | result: { 440 | kind: 'result', 441 | type: 'i32' 442 | }, 443 | local: [], 444 | body: [{ 445 | kind: 'return', 446 | expr: { 447 | kind: 'load', 448 | type: 'i32', 449 | size: 8, 450 | sign: false, 451 | offset: 0, 452 | align: 0, 453 | expr: { 454 | kind: 'const', 455 | type: 'i32', 456 | init: '0' 457 | } 458 | } 459 | }] 460 | }, 461 | { 462 | kind: 'func', 463 | id: { 464 | kind: 'identifier', 465 | name: 'main' 466 | }, 467 | expos: [], 468 | imp: null, 469 | type: null, 470 | params: [], 471 | result: null, 472 | local: [], 473 | body: [ 474 | { 475 | kind: 'call', 476 | id: { 477 | kind: 'identifier', 478 | name: 'inc' 479 | }, 480 | exprs: [] 481 | }, 482 | { 483 | kind: 'call', 484 | id: { 485 | kind: 'identifier', 486 | name: 'inc' 487 | }, 488 | exprs: [] 489 | }, 490 | { 491 | kind: 'call', 492 | id: { 493 | kind: 'identifier', 494 | name: 'inc' 495 | }, 496 | exprs: [] 497 | } 498 | ] 499 | }, 500 | { 501 | kind: 'start', 502 | id: { 503 | kind: 'literal', 504 | value: 2, 505 | raw: '2' 506 | } 507 | }, 508 | { 509 | kind: 'export', 510 | name: { 511 | kind: 'literal', 512 | value: 'inc' 513 | }, 514 | id: { 515 | kind: 'func', 516 | id: { 517 | kind: 'identifier', 518 | name: 'inc' 519 | }, 520 | expos: [], 521 | imp: null, 522 | type: null, 523 | params: [], 524 | result: null, 525 | local: [], 526 | body: [] 527 | } 528 | }, 529 | { 530 | kind: 'export', 531 | name: { 532 | kind: 'literal', 533 | value: 'get' 534 | }, 535 | id: { 536 | kind: 'func', 537 | id: { 538 | kind: 'identifier', 539 | name: 'get' 540 | }, 541 | expos: [], 542 | imp: null, 543 | type: null, 544 | params: [], 545 | result: null, 546 | local: [], 547 | body: [] 548 | } 549 | } 550 | ] 551 | }, 552 | { 553 | kind: 'assert_return', 554 | invoke: { 555 | kind: 'invoke', 556 | id: null, 557 | name: 'get', 558 | body: [] 559 | }, 560 | expr: { 561 | kind: 'const', 562 | type: 'i32', 563 | init: '68' 564 | } 565 | }, 566 | { 567 | kind: 'invoke', 568 | id: null, 569 | name: 'inc', 570 | body: [] 571 | }, 572 | { 573 | kind: 'assert_return', 574 | invoke: { 575 | kind: 'invoke', 576 | id: null, 577 | name: 'get', 578 | body: [] 579 | }, 580 | expr: { 581 | kind: 'const', 582 | type: 'i32', 583 | init: '69' 584 | } 585 | }, 586 | { 587 | kind: 'invoke', 588 | id: null, 589 | name: 'inc', 590 | body: [] 591 | }, 592 | { 593 | kind: 'assert_return', 594 | invoke: { 595 | kind: 'invoke', 596 | id: null, 597 | name: 'get', 598 | body: [] 599 | }, 600 | expr: { 601 | kind: 'const', 602 | type: 'i32', 603 | init: '70' 604 | } 605 | }, 606 | { 607 | kind: 'module', 608 | body: [ 609 | { 610 | kind: 'func', 611 | id: { 612 | kind: 'identifier', 613 | name: 'print_i32' 614 | }, 615 | expos: [], 616 | imp: {}, 617 | type: null, 618 | params: [{ 619 | kind: 'param', 620 | id: null, 621 | items: [{ 622 | kind: 'item', 623 | type: 'i32' 624 | }] 625 | }], 626 | result: null, 627 | local: [], 628 | body: [] 629 | }, 630 | { 631 | kind: 'func', 632 | id: { 633 | kind: 'identifier', 634 | name: 'main' 635 | }, 636 | expos: [], 637 | imp: null, 638 | type: null, 639 | params: [], 640 | result: null, 641 | local: [], 642 | body: [{ 643 | kind: 'call', 644 | id: { 645 | kind: 'identifier', 646 | name: 'print_i32' 647 | }, 648 | exprs: [{ 649 | kind: 'const', 650 | type: 'i32', 651 | init: '1' 652 | }] 653 | }] 654 | }, 655 | { 656 | kind: 'start', 657 | id: { 658 | kind: 'literal', 659 | value: 1, 660 | raw: '1' 661 | } 662 | } 663 | ] 664 | }, 665 | { 666 | kind: 'module', 667 | body: [ 668 | { 669 | kind: 'func', 670 | id: { 671 | kind: 'identifier', 672 | name: 'print_i32' 673 | }, 674 | expos: [], 675 | imp: {}, 676 | type: null, 677 | params: [{ 678 | kind: 'param', 679 | id: null, 680 | items: [{ 681 | kind: 'item', 682 | type: 'i32' 683 | }] 684 | }], 685 | result: null, 686 | local: [], 687 | body: [] 688 | }, 689 | { 690 | kind: 'func', 691 | id: { 692 | kind: 'identifier', 693 | name: 'main' 694 | }, 695 | expos: [], 696 | imp: null, 697 | type: null, 698 | params: [], 699 | result: null, 700 | local: [], 701 | body: [{ 702 | kind: 'call', 703 | id: { 704 | kind: 'identifier', 705 | name: 'print_i32' 706 | }, 707 | exprs: [{ 708 | kind: 'const', 709 | type: 'i32', 710 | init: '2' 711 | }] 712 | }] 713 | }, 714 | { 715 | kind: 'start', 716 | id: { 717 | kind: 'identifier', 718 | name: 'main' 719 | } 720 | } 721 | ] 722 | }, 723 | { 724 | kind: 'module', 725 | body: [ 726 | { 727 | kind: 'func', 728 | id: { 729 | kind: 'identifier', 730 | name: 'print' 731 | }, 732 | expos: [], 733 | imp: {}, 734 | type: null, 735 | params: [], 736 | result: null, 737 | local: [], 738 | body: [] 739 | }, 740 | { 741 | kind: 'start', 742 | id: { 743 | kind: 'identifier', 744 | name: 'print' 745 | } 746 | } 747 | ] 748 | }, 749 | { 750 | kind: 'assert_trap', 751 | invoke: { 752 | kind: 'module', 753 | body: [ 754 | { 755 | kind: 'func', 756 | id: { 757 | kind: 'identifier', 758 | name: 'main' 759 | }, 760 | expos: [], 761 | imp: null, 762 | type: null, 763 | params: [], 764 | result: null, 765 | local: [], 766 | body: [{kind: 'unreachable'}] 767 | }, 768 | { 769 | kind: 'start', 770 | id: { 771 | kind: 'identifier', 772 | name: 'main' 773 | } 774 | } 775 | ] 776 | }, 777 | failure: { 778 | kind: 'literal', 779 | value: 'unreachable' 780 | } 781 | } 782 | ] 783 | } 784 | -------------------------------------------------------------------------------- /results/store_retval.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'assert_invalid', 6 | module: { 7 | kind: 'module', 8 | body: [{ 9 | kind: 'func', 10 | id: null, 11 | expos: [], 12 | imp: null, 13 | type: null, 14 | params: [{ 15 | kind: 'param', 16 | id: null, 17 | items: [{ 18 | kind: 'item', 19 | type: 'i32' 20 | }] 21 | }], 22 | result: { 23 | kind: 'result', 24 | type: 'i32' 25 | }, 26 | local: [], 27 | body: [{ 28 | kind: 'set_local', 29 | id: { 30 | kind: 'literal', 31 | value: 0, 32 | raw: '0' 33 | }, 34 | init: { 35 | kind: 'const', 36 | type: 'i32', 37 | init: '1' 38 | } 39 | }] 40 | }] 41 | }, 42 | failure: { 43 | kind: 'literal', 44 | value: 'type mismatch' 45 | } 46 | }, 47 | { 48 | kind: 'assert_invalid', 49 | module: { 50 | kind: 'module', 51 | body: [{ 52 | kind: 'func', 53 | id: null, 54 | expos: [], 55 | imp: null, 56 | type: null, 57 | params: [{ 58 | kind: 'param', 59 | id: null, 60 | items: [{ 61 | kind: 'item', 62 | type: 'i64' 63 | }] 64 | }], 65 | result: { 66 | kind: 'result', 67 | type: 'i64' 68 | }, 69 | local: [], 70 | body: [{ 71 | kind: 'set_local', 72 | id: { 73 | kind: 'literal', 74 | value: 0, 75 | raw: '0' 76 | }, 77 | init: { 78 | kind: 'const', 79 | type: 'i64', 80 | init: '1' 81 | } 82 | }] 83 | }] 84 | }, 85 | failure: { 86 | kind: 'literal', 87 | value: 'type mismatch' 88 | } 89 | }, 90 | { 91 | kind: 'assert_invalid', 92 | module: { 93 | kind: 'module', 94 | body: [{ 95 | kind: 'func', 96 | id: null, 97 | expos: [], 98 | imp: null, 99 | type: null, 100 | params: [{ 101 | kind: 'param', 102 | id: null, 103 | items: [{ 104 | kind: 'item', 105 | type: 'f32' 106 | }] 107 | }], 108 | result: { 109 | kind: 'result', 110 | type: 'f32' 111 | }, 112 | local: [], 113 | body: [{ 114 | kind: 'set_local', 115 | id: { 116 | kind: 'literal', 117 | value: 0, 118 | raw: '0' 119 | }, 120 | init: { 121 | kind: 'const', 122 | type: 'f32', 123 | init: '1' 124 | } 125 | }] 126 | }] 127 | }, 128 | failure: { 129 | kind: 'literal', 130 | value: 'type mismatch' 131 | } 132 | }, 133 | { 134 | kind: 'assert_invalid', 135 | module: { 136 | kind: 'module', 137 | body: [{ 138 | kind: 'func', 139 | id: null, 140 | expos: [], 141 | imp: null, 142 | type: null, 143 | params: [{ 144 | kind: 'param', 145 | id: null, 146 | items: [{ 147 | kind: 'item', 148 | type: 'f64' 149 | }] 150 | }], 151 | result: { 152 | kind: 'result', 153 | type: 'f64' 154 | }, 155 | local: [], 156 | body: [{ 157 | kind: 'set_local', 158 | id: { 159 | kind: 'literal', 160 | value: 0, 161 | raw: '0' 162 | }, 163 | init: { 164 | kind: 'const', 165 | type: 'f64', 166 | init: '1' 167 | } 168 | }] 169 | }] 170 | }, 171 | failure: { 172 | kind: 'literal', 173 | value: 'type mismatch' 174 | } 175 | }, 176 | { 177 | kind: 'assert_invalid', 178 | module: { 179 | kind: 'module', 180 | body: [ 181 | { 182 | kind: 'memory', 183 | impo: null, 184 | expo: null, 185 | int: { 186 | kind: 'literal', 187 | value: 1, 188 | raw: [ 189 | [' '], 190 | '1' 191 | ] 192 | }, 193 | int1: null, 194 | segment: [] 195 | }, 196 | { 197 | kind: 'func', 198 | id: null, 199 | expos: [], 200 | imp: null, 201 | type: null, 202 | params: [{ 203 | kind: 'param', 204 | id: null, 205 | items: [{ 206 | kind: 'item', 207 | type: 'i32' 208 | }] 209 | }], 210 | result: { 211 | kind: 'result', 212 | type: 'i32' 213 | }, 214 | local: [], 215 | body: [{ 216 | kind: 'store', 217 | type: 'i32', 218 | size: null, 219 | offset: 0, 220 | align: 0, 221 | addr: { 222 | kind: 'const', 223 | type: 'i32', 224 | init: '0' 225 | }, 226 | data: { 227 | kind: 'const', 228 | type: 'i32', 229 | init: '1' 230 | } 231 | }] 232 | } 233 | ] 234 | }, 235 | failure: { 236 | kind: 'literal', 237 | value: 'type mismatch' 238 | } 239 | }, 240 | { 241 | kind: 'assert_invalid', 242 | module: { 243 | kind: 'module', 244 | body: [ 245 | { 246 | kind: 'memory', 247 | impo: null, 248 | expo: null, 249 | int: { 250 | kind: 'literal', 251 | value: 1, 252 | raw: [ 253 | [' '], 254 | '1' 255 | ] 256 | }, 257 | int1: null, 258 | segment: [] 259 | }, 260 | { 261 | kind: 'func', 262 | id: null, 263 | expos: [], 264 | imp: null, 265 | type: null, 266 | params: [{ 267 | kind: 'param', 268 | id: null, 269 | items: [{ 270 | kind: 'item', 271 | type: 'i64' 272 | }] 273 | }], 274 | result: { 275 | kind: 'result', 276 | type: 'i64' 277 | }, 278 | local: [], 279 | body: [{ 280 | kind: 'store', 281 | type: 'i64', 282 | size: null, 283 | offset: 0, 284 | align: 0, 285 | addr: { 286 | kind: 'const', 287 | type: 'i32', 288 | init: '0' 289 | }, 290 | data: { 291 | kind: 'const', 292 | type: 'i64', 293 | init: '1' 294 | } 295 | }] 296 | } 297 | ] 298 | }, 299 | failure: { 300 | kind: 'literal', 301 | value: 'type mismatch' 302 | } 303 | }, 304 | { 305 | kind: 'assert_invalid', 306 | module: { 307 | kind: 'module', 308 | body: [ 309 | { 310 | kind: 'memory', 311 | impo: null, 312 | expo: null, 313 | int: { 314 | kind: 'literal', 315 | value: 1, 316 | raw: [ 317 | [' '], 318 | '1' 319 | ] 320 | }, 321 | int1: null, 322 | segment: [] 323 | }, 324 | { 325 | kind: 'func', 326 | id: null, 327 | expos: [], 328 | imp: null, 329 | type: null, 330 | params: [{ 331 | kind: 'param', 332 | id: null, 333 | items: [{ 334 | kind: 'item', 335 | type: 'f32' 336 | }] 337 | }], 338 | result: { 339 | kind: 'result', 340 | type: 'f32' 341 | }, 342 | local: [], 343 | body: [{ 344 | kind: 'store', 345 | type: 'f32', 346 | size: null, 347 | offset: 0, 348 | align: 0, 349 | addr: { 350 | kind: 'const', 351 | type: 'i32', 352 | init: '0' 353 | }, 354 | data: { 355 | kind: 'const', 356 | type: 'f32', 357 | init: '1' 358 | } 359 | }] 360 | } 361 | ] 362 | }, 363 | failure: { 364 | kind: 'literal', 365 | value: 'type mismatch' 366 | } 367 | }, 368 | { 369 | kind: 'assert_invalid', 370 | module: { 371 | kind: 'module', 372 | body: [ 373 | { 374 | kind: 'memory', 375 | impo: null, 376 | expo: null, 377 | int: { 378 | kind: 'literal', 379 | value: 1, 380 | raw: [ 381 | [' '], 382 | '1' 383 | ] 384 | }, 385 | int1: null, 386 | segment: [] 387 | }, 388 | { 389 | kind: 'func', 390 | id: null, 391 | expos: [], 392 | imp: null, 393 | type: null, 394 | params: [{ 395 | kind: 'param', 396 | id: null, 397 | items: [{ 398 | kind: 'item', 399 | type: 'f64' 400 | }] 401 | }], 402 | result: { 403 | kind: 'result', 404 | type: 'f64' 405 | }, 406 | local: [], 407 | body: [{ 408 | kind: 'store', 409 | type: 'f64', 410 | size: null, 411 | offset: 0, 412 | align: 0, 413 | addr: { 414 | kind: 'const', 415 | type: 'i32', 416 | init: '0' 417 | }, 418 | data: { 419 | kind: 'const', 420 | type: 'f64', 421 | init: '1' 422 | } 423 | }] 424 | } 425 | ] 426 | }, 427 | failure: { 428 | kind: 'literal', 429 | value: 'type mismatch' 430 | } 431 | }, 432 | { 433 | kind: 'assert_invalid', 434 | module: { 435 | kind: 'module', 436 | body: [ 437 | { 438 | kind: 'memory', 439 | impo: null, 440 | expo: null, 441 | int: { 442 | kind: 'literal', 443 | value: 1, 444 | raw: [ 445 | [' '], 446 | '1' 447 | ] 448 | }, 449 | int1: null, 450 | segment: [] 451 | }, 452 | { 453 | kind: 'func', 454 | id: null, 455 | expos: [], 456 | imp: null, 457 | type: null, 458 | params: [{ 459 | kind: 'param', 460 | id: null, 461 | items: [{ 462 | kind: 'item', 463 | type: 'i32' 464 | }] 465 | }], 466 | result: { 467 | kind: 'result', 468 | type: 'i32' 469 | }, 470 | local: [], 471 | body: [{ 472 | kind: 'store', 473 | type: 'i32', 474 | size: 8, 475 | offset: 0, 476 | align: 0, 477 | addr: { 478 | kind: 'const', 479 | type: 'i32', 480 | init: '0' 481 | }, 482 | data: { 483 | kind: 'const', 484 | type: 'i32', 485 | init: '1' 486 | } 487 | }] 488 | } 489 | ] 490 | }, 491 | failure: { 492 | kind: 'literal', 493 | value: 'type mismatch' 494 | } 495 | }, 496 | { 497 | kind: 'assert_invalid', 498 | module: { 499 | kind: 'module', 500 | body: [ 501 | { 502 | kind: 'memory', 503 | impo: null, 504 | expo: null, 505 | int: { 506 | kind: 'literal', 507 | value: 1, 508 | raw: [ 509 | [' '], 510 | '1' 511 | ] 512 | }, 513 | int1: null, 514 | segment: [] 515 | }, 516 | { 517 | kind: 'func', 518 | id: null, 519 | expos: [], 520 | imp: null, 521 | type: null, 522 | params: [{ 523 | kind: 'param', 524 | id: null, 525 | items: [{ 526 | kind: 'item', 527 | type: 'i32' 528 | }] 529 | }], 530 | result: { 531 | kind: 'result', 532 | type: 'i32' 533 | }, 534 | local: [], 535 | body: [{ 536 | kind: 'store', 537 | type: 'i32', 538 | size: 16, 539 | offset: 0, 540 | align: 0, 541 | addr: { 542 | kind: 'const', 543 | type: 'i32', 544 | init: '0' 545 | }, 546 | data: { 547 | kind: 'const', 548 | type: 'i32', 549 | init: '1' 550 | } 551 | }] 552 | } 553 | ] 554 | }, 555 | failure: { 556 | kind: 'literal', 557 | value: 'type mismatch' 558 | } 559 | }, 560 | { 561 | kind: 'assert_invalid', 562 | module: { 563 | kind: 'module', 564 | body: [ 565 | { 566 | kind: 'memory', 567 | impo: null, 568 | expo: null, 569 | int: { 570 | kind: 'literal', 571 | value: 1, 572 | raw: [ 573 | [' '], 574 | '1' 575 | ] 576 | }, 577 | int1: null, 578 | segment: [] 579 | }, 580 | { 581 | kind: 'func', 582 | id: null, 583 | expos: [], 584 | imp: null, 585 | type: null, 586 | params: [{ 587 | kind: 'param', 588 | id: null, 589 | items: [{ 590 | kind: 'item', 591 | type: 'i64' 592 | }] 593 | }], 594 | result: { 595 | kind: 'result', 596 | type: 'i64' 597 | }, 598 | local: [], 599 | body: [{ 600 | kind: 'store', 601 | type: 'i64', 602 | size: 8, 603 | offset: 0, 604 | align: 0, 605 | addr: { 606 | kind: 'const', 607 | type: 'i32', 608 | init: '0' 609 | }, 610 | data: { 611 | kind: 'const', 612 | type: 'i64', 613 | init: '1' 614 | } 615 | }] 616 | } 617 | ] 618 | }, 619 | failure: { 620 | kind: 'literal', 621 | value: 'type mismatch' 622 | } 623 | }, 624 | { 625 | kind: 'assert_invalid', 626 | module: { 627 | kind: 'module', 628 | body: [ 629 | { 630 | kind: 'memory', 631 | impo: null, 632 | expo: null, 633 | int: { 634 | kind: 'literal', 635 | value: 1, 636 | raw: [ 637 | [' '], 638 | '1' 639 | ] 640 | }, 641 | int1: null, 642 | segment: [] 643 | }, 644 | { 645 | kind: 'func', 646 | id: null, 647 | expos: [], 648 | imp: null, 649 | type: null, 650 | params: [{ 651 | kind: 'param', 652 | id: null, 653 | items: [{ 654 | kind: 'item', 655 | type: 'i64' 656 | }] 657 | }], 658 | result: { 659 | kind: 'result', 660 | type: 'i64' 661 | }, 662 | local: [], 663 | body: [{ 664 | kind: 'store', 665 | type: 'i64', 666 | size: 16, 667 | offset: 0, 668 | align: 0, 669 | addr: { 670 | kind: 'const', 671 | type: 'i32', 672 | init: '0' 673 | }, 674 | data: { 675 | kind: 'const', 676 | type: 'i64', 677 | init: '1' 678 | } 679 | }] 680 | } 681 | ] 682 | }, 683 | failure: { 684 | kind: 'literal', 685 | value: 'type mismatch' 686 | } 687 | }, 688 | { 689 | kind: 'assert_invalid', 690 | module: { 691 | kind: 'module', 692 | body: [ 693 | { 694 | kind: 'memory', 695 | impo: null, 696 | expo: null, 697 | int: { 698 | kind: 'literal', 699 | value: 1, 700 | raw: [ 701 | [' '], 702 | '1' 703 | ] 704 | }, 705 | int1: null, 706 | segment: [] 707 | }, 708 | { 709 | kind: 'func', 710 | id: null, 711 | expos: [], 712 | imp: null, 713 | type: null, 714 | params: [{ 715 | kind: 'param', 716 | id: null, 717 | items: [{ 718 | kind: 'item', 719 | type: 'i64' 720 | }] 721 | }], 722 | result: { 723 | kind: 'result', 724 | type: 'i64' 725 | }, 726 | local: [], 727 | body: [{ 728 | kind: 'store', 729 | type: 'i64', 730 | size: 32, 731 | offset: 0, 732 | align: 0, 733 | addr: { 734 | kind: 'const', 735 | type: 'i32', 736 | init: '0' 737 | }, 738 | data: { 739 | kind: 'const', 740 | type: 'i64', 741 | init: '1' 742 | } 743 | }] 744 | } 745 | ] 746 | }, 747 | failure: { 748 | kind: 'literal', 749 | value: 'type mismatch' 750 | } 751 | } 752 | ] 753 | } 754 | -------------------------------------------------------------------------------- /results/token.js: -------------------------------------------------------------------------------- 1 | { 2 | kind: 'script', 3 | body: [ 4 | { 5 | kind: 'assert_malformed', 6 | module: { 7 | kind: 'module', 8 | body: [ 9 | 'quote', 10 | { 11 | kind: 'literal', 12 | value: '(func (drop (i32.const0)))' 13 | } 14 | ] 15 | }, 16 | failure: { 17 | kind: 'literal', 18 | value: 'unknown operator' 19 | } 20 | }, 21 | { 22 | kind: 'assert_malformed', 23 | module: { 24 | kind: 'module', 25 | body: [ 26 | 'quote', 27 | { 28 | kind: 'literal', 29 | value: '(func br 0drop)' 30 | } 31 | ] 32 | }, 33 | failure: { 34 | kind: 'literal', 35 | value: 'unknown operator' 36 | } 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var fs = require('fs'), 4 | path = require('path'), 5 | expect = require('chai').expect, 6 | jsof = require('jsof'), 7 | parser = require('../'); 8 | 9 | [ 10 | { src: '../testsuite/', dst: '../results/' }, 11 | { src: '../testsuite-extra/', dst: '../results-extra/' } 12 | ] 13 | .map(function (job) { 14 | return { 15 | src: path.resolve(__dirname, job.src), 16 | dst: path.resolve(__dirname, job.dst) 17 | }; 18 | }) 19 | .map(function (job) { 20 | return { 21 | src: job.src, 22 | dst: job.dst, 23 | files: ( 24 | fs.readdirSync(job.dst) 25 | .filter(function (fileName) { 26 | return fileName.match('^(.*).js$'); 27 | }) 28 | ) 29 | }; 30 | }) 31 | .forEach(function (job) { 32 | describe(job.src, function () { 33 | job.files.forEach(function (astFileName) { 34 | var matchArr = astFileName.match('^(.*).js$'); 35 | var name = matchArr[1]; 36 | it(name, function (done) { 37 | fs.readFile( 38 | path.resolve(job.src, name + '.wast'), 39 | 'utf8', 40 | function (err, wastData) { 41 | if (err) { throw err; } 42 | 43 | var result; 44 | try { 45 | result = parser.parse(wastData); 46 | } catch (err1) { 47 | console.log(err1); 48 | throw err1; 49 | } 50 | 51 | fs.readFile( 52 | path.resolve(job.dst, name + '.js'), 53 | 'utf8', 54 | function (err2, astData) { 55 | if (err2) { throw err2; } 56 | expect(jsof.s(result) + '\n').to.equal(astData); 57 | done(); 58 | } 59 | ); 60 | } 61 | ); 62 | }); 63 | }); 64 | }); 65 | }); 66 | -------------------------------------------------------------------------------- /testsuite-extra/wast-parser-22.wast: -------------------------------------------------------------------------------- 1 | (module 2 | (export "add" $add) 3 | (func $add (param $x f64) (param $y f64) (result f64) 4 | (f64.add 5 | (get_local $x) 6 | (get_local $y) 7 | ) 8 | ) 9 | ) 10 | -------------------------------------------------------------------------------- /wast.pegjs: -------------------------------------------------------------------------------- 1 | /* WAST Grammar */ 2 | 3 | start 4 | = body:( __ cmd )* __ { 5 | return { 6 | kind: 'script', 7 | body: body.map(function (e) { return e[1]; }) 8 | }; 9 | } 10 | 11 | white_space "whitespace" 12 | = [\t\v\f \u00A0\uFEFF] 13 | 14 | LineTerminatorSequence "end of line" 15 | = "\n" 16 | / "\r\n" 17 | / "\r" 18 | / "\u2028" // line separator 19 | / "\u2029" // paragraph separator 20 | 21 | LineTerminator = [\n\r\u2028\u2029] 22 | 23 | multiLineComment = "(;" ( multiLineComment / !";)" . )* ";)" { return null; } 24 | 25 | comment "comment" 26 | = ";;" ( !LineTerminator . )* { return null; } 27 | / multiLineComment 28 | 29 | __ = ( white_space / LineTerminatorSequence / comment )* 30 | 31 | name = name:[a-zA-Z0-9\-\>\_\$\.]+ { return name.join(''); } 32 | 33 | local_type = "i32" / "i64" / "f32" / "f64" 34 | 35 | int = node:( "0x" [0-9A-Fa-f]+ / "-"? [0-9]+ ) { return (node[0] || '') + node[1].join(''); } 36 | 37 | float = "-"? [0-9.]+ 38 | 39 | binop 40 | = "add" / "sub" / "mul" / "div_s" / "div_u" / "rem_s" / "rem_u" 41 | / "and" / "or" / "xor" / "shl" / "shr_u" / "shr_s" / "rotl" / "rotr" // int 42 | / "add" / "sub" / "mul" / "div" / "copysign" / "min" / "max" // float 43 | 44 | unop 45 | = "clz" / "ctz" / "popcnt" / "eqz" // int 46 | / "neg" / "abs" / "ceil" / "floor" / "trunc" / "nearest" / "sqrt" // float 47 | 48 | cvtop 49 | = "wrap" / "trunc_s" / "trunc_u" / "reinterpret" / "extend_s" / "extend_u" 50 | / "convert_s" / "convert_u" / "demote" / "promote" 51 | 52 | relop 53 | = "eq" / "ne" / "lt_s" / "lt_u" / "le_s" / "le_u" / "gt_s" / "gt_u" / "ge_s" / "ge_u" // int 54 | / "eq" / "ne" / "lt" / "le" / "gt" / "ge" // float 55 | 56 | value 57 | = node:(pre:( "nan:" / "+nan:" / "-nan:" ) sign:"-"? hex:"0x" digits:[0-9A-Fa-f_\.\-\+EPep]+ { 58 | return pre[0] + (sign || '') + hex + digits.join('') 59 | } 60 | / "nan" / "+nan" / "-nan" 61 | / "inf" / "+inf" / "-inf" 62 | / sign:("-" / "+")? hex:"0x" digits:[0-9A-Fa-f_\.\-\+Pp]+ { 63 | return (sign || '') + hex + digits.join(''); 64 | } 65 | / sign:"-"? digits:[0-9_\.\-\+Ee]+ { 66 | return (sign || '') + digits.join(''); 67 | } 68 | ) 69 | 70 | sign = "s" / "u" 71 | 72 | align = ( 73 | hex:"0x" digit:[0-9A-Fa-f]* { return hex + digit.join(''); } 74 | / digit:[0-9]* { return digit.join(''); } 75 | ); 76 | 77 | var 78 | = int:int { 79 | return { 80 | kind: 'literal', 81 | value: Number(int), 82 | raw: int 83 | }; 84 | } 85 | / "$" id:name { 86 | return { 87 | kind: 'identifier', 88 | name: id 89 | }; 90 | } 91 | 92 | case 93 | = "(" __ kind:"case" __ test:( "$" name / value ) body:( __ expr )* fallthrough:( __ "fallthrough")? __ ")" { 94 | return { 95 | kind: kind, 96 | test: test, 97 | body: body.map(function (e) { return e[1]; }), 98 | fallthrough: fallthrough ? true : false 99 | }; 100 | } 101 | / "(" __ kind:"case" test:( __ value )? __ ")" { 102 | return { 103 | kind: kind, 104 | test: test ? value[1] : null 105 | }; 106 | } 107 | / expr 108 | 109 | /* 110 | tableswitchtable = "(" kind:"table" items:( __ case )* __ ")" { 111 | return { 112 | kind: kind, 113 | items: items.map(function (e) { return e[1]; }) 114 | }; 115 | } 116 | */ 117 | expr 118 | = "(" __ 119 | body:( type:local_type "." kind:"const" __ init:value { 120 | return { 121 | kind: kind, 122 | type: type, 123 | init: init 124 | }; 125 | } 126 | 127 | / kind:"drop" body:( __ expr )* { 128 | return { 129 | kind: kind, 130 | body: body.map(function (e) { return e[1]; }) 131 | }; 132 | } 133 | 134 | / kind:"block" id:( __ var )? result:( __ result )? body:( __ expr )* { 135 | return { 136 | kind: kind, 137 | result: result ? result[1] : result, 138 | id: id ? id[1] : id, 139 | body: body.map(function (e) { return e[1]; }) 140 | }; 141 | } 142 | 143 | / kind:"if" id:( __ var )? result:( __ result )? body:( __ expr )* { 144 | return { 145 | kind: kind, 146 | id: id ? id[1] : id, 147 | result: result ? result[1] : result, 148 | body: body.map(function (e) { return e[1]; }) 149 | }; 150 | } 151 | 152 | / kind:( "then" / "else" ) id:( __ var )? body:( __ expr )* { 153 | return { 154 | kind: kind, 155 | id: id ? id[1] : id, 156 | body: body.map(function (e) { return e[1]; }) 157 | }; 158 | } 159 | 160 | // = (label (loop (block ? *))) 161 | / kind:"loop" id:( __ var )? result:( __ result )? extra:( __ var )? body:( __ expr )* { 162 | return { 163 | kind: kind, 164 | id: id ? id[1] : id, 165 | result: result ? result[1] : result, 166 | extra: extra ? extra[1] : extra, 167 | body: body.map(function (e) { return e[1]; }) 168 | }; 169 | } 170 | 171 | // = (loop (block *)) 172 | / kind:"loop" body:( __ expr )* { 173 | return { 174 | kind: kind, 175 | body: body.map(function (e) { return e[1]; }) 176 | }; 177 | } 178 | 179 | / kind:"label" id:( __ var )? __ body:expr { 180 | return { 181 | kind: kind, 182 | id: id ? id[1] : id, 183 | body: body 184 | }; 185 | } 186 | 187 | / kind:"br" __ id:var expr:( __ expr )? { 188 | return { 189 | kind: kind, 190 | id: id, 191 | expr: expr ? expr[1] : expr 192 | }; 193 | } 194 | 195 | / kind:"br_if" __ id:var __ test:expr __ expr:( __ expr )? { 196 | return { 197 | kind: kind, 198 | id: id, 199 | test: test, 200 | expr: expr ? expr[1] : expr 201 | }; 202 | } 203 | 204 | / kind:"br_table" body:( __ var )* expr:( __ expr )* { 205 | return { 206 | kind: kind, 207 | exprs: expr.map(function (e) { return e[1]; }), 208 | body: body.map(function (e) { return e[1]; }) 209 | }; 210 | } 211 | 212 | / kind:"call" __ id:var expr:( __ expr )* { 213 | return { 214 | kind: kind, 215 | id: id, 216 | exprs: expr.map(function (e) { return e[1]; }) 217 | }; 218 | } 219 | 220 | / kind:"call_indirect" __ type:( __ func_type )? __ expr:( __ expr )+ { 221 | return { 222 | kind: kind, 223 | type: type, 224 | exprs: expr.map(function (e) { return e[1]; }) 225 | } 226 | } 227 | 228 | / kind:"return" expr:( __ expr )? { 229 | return { 230 | kind: kind, 231 | expr: expr ? expr[1] : expr 232 | } 233 | } 234 | 235 | / kind:("get_local" / "get_global") __ id:var { 236 | return { 237 | kind: kind, 238 | id: id 239 | }; 240 | } 241 | 242 | / kind:("set_local" / "tee_local" / "set_global") __ id:var expr:( __ expr )? { 243 | return { 244 | kind: kind, 245 | id: id, 246 | init: expr ? expr[1] : null 247 | }; 248 | } 249 | 250 | / type:local_type "." kind:"load" sufix:( ( "8" / "16" / "32" / "64") ( "_" sign )? )? offset:( __ "offset=" align )? align:( __ "align=" align )? __ expr:expr { 251 | return { 252 | kind: kind, 253 | type: type, 254 | size: sufix ? parseInt(sufix[0], 10) : null, 255 | sign: (sufix && sufix[1]) ? (sufix[1][1] === 's') : null, 256 | offset: offset ? parseInt(offset[2], 10) : 0, 257 | align: align ? parseInt(align[2], 10) : 0, 258 | expr: expr 259 | }; 260 | } 261 | 262 | / type:local_type "." kind:"store" sufix:( "8" / "16" / "32" / "64")? offset:( __ "offset=" align )? align:( __ "align=" align )? __ addr:expr __ data:expr { 263 | return { 264 | kind: kind, 265 | type: type, 266 | size: sufix ? parseInt(sufix, 10) : null, 267 | offset: offset ? parseInt(offset[2], 10) : 0, 268 | align: align ? parseInt(align[2], 10) : 0, 269 | addr: addr, 270 | data: data 271 | }; 272 | } 273 | 274 | / kind:"select" args:( __ expr __ expr __ expr )? { 275 | return { 276 | kind: kind, 277 | then: args ? args[1] : null, 278 | else: args ? args[3] : null, 279 | test: args ? args[5] : null 280 | }; 281 | } 282 | 283 | / type:local_type "." operator:cvtop "/" type1:local_type __ expr:expr { 284 | return { 285 | kind: 'cvtop', 286 | type: type, 287 | type1: type1, 288 | operator: operator, 289 | expr: expr 290 | }; 291 | } 292 | 293 | / type:local_type "." operator:unop expr:( __ expr )? { 294 | return { 295 | kind: 'unop', 296 | type: type, 297 | operator: operator, 298 | expr: expr ? expr[1] : expr 299 | }; 300 | } 301 | 302 | / type:local_type "." operator:binop left:( __ expr)? right:( __ expr)? { 303 | return { 304 | kind: 'binop', 305 | type: type, 306 | operator: operator, 307 | left: left ? left[1] : left, 308 | right: right ? right[1] : right 309 | }; 310 | } 311 | 312 | / type:local_type "." operator:relop left:( __ expr)? right:( __ expr)? { 313 | return { 314 | kind: 'relop', 315 | type: type, 316 | operator: operator, 317 | left: left ? left[1] : left, 318 | right: right ? right[1] : right 319 | }; 320 | } 321 | 322 | / kind:("nop" / "unreachable" / "current_memory" / "memory.size") { 323 | return { 324 | kind: kind 325 | }; 326 | } 327 | 328 | / kind:("grow_memory" / "memory.grow") __ expr:expr { 329 | return { 330 | kind: kind, 331 | expr: expr 332 | }; 333 | } 334 | ) 335 | __ ")" { 336 | return body; 337 | } 338 | 339 | literal = ["] value:( "\\\"" / !["] . )* ["] { 340 | return { 341 | kind: 'literal', 342 | value: value.map(function (e) { return e[1]; }).join('').replace(/\\/g, '\\\\') 343 | }; 344 | } 345 | 346 | param 347 | = "(" __ kind:"param" id:( __ var )? __ items:( __ local_type )* __ ")" { 348 | return { 349 | kind: kind, 350 | id: id ? id[1] : id, 351 | items: items.map(function (e) { return { kind: 'item', type: e[1] }; }) 352 | }; 353 | } 354 | / "(" __ kind:"param" __ "$" name:name __ type:local_type __ ")" { 355 | return { 356 | kind: kind, 357 | items: [{ kind: 'item', name: name, type: type }] 358 | }; 359 | } 360 | 361 | local 362 | = "(" __ kind:"local" items:( __ local_type )* __ ")" { 363 | return { 364 | kind: kind, 365 | items: items.map(function (e) { return { kind: 'item', type: e[1] }; }) 366 | }; 367 | } 368 | / "(" __ kind:"local" __ "$" name:name __ type:local_type __ ")" { 369 | return { 370 | kind: kind, 371 | items: [{ kind: 'item', name: name, type: type }] 372 | }; 373 | } 374 | 375 | result = "(" __ kind:"result" type:( __ local_type )? __ ")" { 376 | return { 377 | kind: kind, 378 | type: type ? type[1] : null 379 | }; 380 | } 381 | 382 | segment = kind:"segment" __ int:int __ init:literal { 383 | return { 384 | kind: kind, 385 | offset: { 386 | kind: 'literal', 387 | value: Number(int), 388 | raw: int 389 | }, 390 | init: init 391 | } 392 | } 393 | 394 | func_type = "(" __ kind:"type" __ id:var __ ")" { 395 | return { 396 | kind: kind, 397 | id: id 398 | }; 399 | } 400 | 401 | func = kind:"func" 402 | id:( __ var )? 403 | expos:( __ "(" __ "export" __ literal __ ")" )* 404 | imp:( __ "(" __ "import" __ literal __ literal __ ")" )? 405 | type:( __ func_type )? 406 | param:( __ param )* 407 | result:( __ result )? 408 | local:( __ local )* 409 | body:( __ expr )* 410 | { 411 | return { 412 | kind: kind, 413 | id: id ? id[1] : id, 414 | expos: expos.map(function (e) { 415 | return e[5]; 416 | }), 417 | imp: imp ? { 418 | 419 | } : imp, 420 | type: type ? type[1] : type, 421 | params: param.map(function (e) { return e[1]; }), 422 | result: result ? result[1] : result, 423 | local: local.map(function (e) { return e[1]; }), 424 | body: body.map(function (e) { return e[1]; }) 425 | }; 426 | } 427 | 428 | global = kind:"global" 429 | id:( __ var )? 430 | expo:( __ "(" __ "export" __ literal __ ")" )? 431 | impo:( __ import_def )? 432 | mut:( __ "(" __ "mut" __ local_type __ ")" )? 433 | type:( __ local_type )? 434 | body:( __ expr )* 435 | { 436 | return { 437 | kind:kind, 438 | id: id ? id[1] : id, 439 | mut: mut ? true : false, 440 | expo: expo ? expo[5] : expo, 441 | impo: impo ? impo[1] : null, 442 | type: (type ? type[1] : (mut ? mut[5] : null)), 443 | body: body.map(function (e) { return e[1]; }) 444 | }; 445 | } 446 | 447 | _start = kind:"start" __ id:var { 448 | return { 449 | kind: kind, 450 | id: id 451 | }; 452 | } 453 | 454 | param_def = "(" __ kind:"param" id:( __ var )? items:( __ local_type )* __ ")" { 455 | return { 456 | kind: kind, 457 | id: id ? id[1] : id, 458 | items: items.map(function (e) { return { kind: 'item', type: e[1] }; }) 459 | } 460 | } 461 | 462 | result_def = "(" __ kind:"result" __ type:local_type __ ")" { 463 | return { 464 | kind: kind, 465 | type: type 466 | } 467 | } 468 | 469 | func_def = 470 | "(" 471 | __ kind:"func" 472 | id:( __ var )? 473 | param:( __ param_def )* 474 | result:( __ result_def )? 475 | __ ")" 476 | { 477 | return { 478 | kind: kind, 479 | id: id ? id[1] : id, 480 | params: param.map(function (e) { return e[1]; }), 481 | result: result ? result[1] : result, 482 | local: [], 483 | body: [] 484 | }; 485 | } 486 | 487 | type_def = kind:"type" id:( __ var )? expr:( __ func_def ) { 488 | return { 489 | kind: kind, 490 | id: id ? id[1] : id, 491 | expr: expr ? expr[1] : expr 492 | }; 493 | } 494 | 495 | global_def = "(" __ res:global __ ")" { 496 | return res; 497 | } 498 | 499 | import = kind:"import" 500 | id:( __ var )? 501 | __ modName:literal 502 | __ funcName:literal 503 | type:( __ (global_def / func_def / table_def) )? 504 | params:( __ param )* 505 | result:( __ result )? 506 | { 507 | return { 508 | kind: kind, 509 | id: id ? id[1] : id, 510 | modName: modName, 511 | funcName: funcName, 512 | type: type ? type[1] : type, 513 | params: params.map(function (e) { return e[1]; }), 514 | result: result ? result[1] : result 515 | }; 516 | } 517 | 518 | import_def = "(" __ res:import __ ")" { return res; } 519 | 520 | export = kind:"export" __ ["] name:( "\\" "\"" / !["] . )* ["] __ id:( var / cmd / "memory" ) { 521 | return { 522 | kind: kind, 523 | name: { 524 | kind: 'literal', 525 | value: name.map(function (e) { return e[1]; }).join('') 526 | }, 527 | id: (id === 'memory') ? { 528 | kind: 'literal', 529 | value: id, 530 | bare: true 531 | } : id 532 | }; 533 | } 534 | 535 | elem = "(" __ kind:"elem" items:( __ var )* __ ")" { 536 | return { 537 | kind: kind, 538 | items: items.map(function (e) { return e[1]; }) 539 | } 540 | } 541 | 542 | table = kind:"table" 543 | expo:( __ "(" __ "export" __ literal __ ")" )? 544 | index:( __ int )* 545 | anyfunc:( __ "anyfunc" )? 546 | items:( __ elem )? 547 | { 548 | return { 549 | kind: kind, 550 | expo: expo ? expo[5] : expo, 551 | index: index.map(function (e) { 552 | return e[1]; 553 | }), 554 | items: items ? items[1] : items 555 | }; 556 | } 557 | 558 | table_def = "(" __ res:table __ ")" { return res; } 559 | 560 | memory = kind:"memory" 561 | impo:( __ import_def )? 562 | expo:( __ "(" __ "export" __ literal __ ")" )? 563 | int:( __ int )? 564 | int1:( __ int )? 565 | segment:( __ cmd )* 566 | { 567 | return { 568 | kind: kind, 569 | impo: impo ? impo[1] : null, 570 | expo: expo ? expo[5] : expo, 571 | int: int ? { 572 | kind: 'literal', 573 | value: Number(int[1]), 574 | raw: int 575 | } : int, 576 | int1: int1 ? { 577 | kind: 'literal', 578 | value: Number(int1[1]), 579 | raw: int1[1] 580 | } : int1, 581 | segment: segment.map(function (e) { return e[1]; }) 582 | }; 583 | } 584 | 585 | invoke = kind:"invoke" id:( __ var )? __ ["] name:( "\\\"" / !["] . )* ["] body:( __ expr )* { 586 | return { 587 | kind: kind, 588 | id: id ? id[1] : id, 589 | name: name.map(function (e) { 590 | return e[1]; 591 | }).join(''), 592 | body: body.map(function (e) { return e[1]; }) 593 | }; 594 | } 595 | 596 | module = kind:"module" body:( __ ( cmd / literal / name ) )* { 597 | var result = []; 598 | return { 599 | kind: kind, 600 | body: body.map(function (e) { return e[1]; }) 601 | }; 602 | } 603 | 604 | assert_return = kind:"assert_return" __ invoke:cmd __ expr:( expr )? { 605 | return { 606 | kind: kind, 607 | invoke: invoke, 608 | expr: expr 609 | }; 610 | } 611 | 612 | assert_return_nan = kind:("assert_return_canonical_nan" / "assert_return_arithmetic_nan") __ invoke:cmd { 613 | return { 614 | kind: kind, 615 | invoke: invoke 616 | }; 617 | } 618 | 619 | assert_trap = kind:"assert_trap" __ invoke:cmd __ failure:literal { 620 | return { 621 | kind: kind, 622 | invoke: invoke, 623 | failure: failure 624 | }; 625 | } 626 | 627 | assert_invalid = kind:("assert_invalid" / "assert_unlinkable" / "assert_malformed" / "assert_exhaustion") __ module:cmd __ failure:literal { 628 | return { 629 | kind: kind, 630 | module: module, 631 | failure: failure 632 | }; 633 | } 634 | 635 | data = kind:"data" 636 | expr:( __ expr )? 637 | values:( __ literal )* 638 | { 639 | return { 640 | kind: kind, 641 | expr: expr ? expr[1] : null, 642 | values: values.map(function (e) { return e[1]; }) 643 | }; 644 | } 645 | 646 | register = kind:"register" 647 | __ ["] name:( "\\\"" / !["] . )* ["] 648 | name1:( __ var )? 649 | { 650 | return { 651 | kind: kind, 652 | name: name.map(function (e) { 653 | return e[1]; 654 | }).join(''), 655 | name1: name1 ? name1[1] : null 656 | }; 657 | } 658 | 659 | cmd 660 | = "(" __ 661 | node:( module 662 | / invoke 663 | / assert_return 664 | / assert_return_nan 665 | / assert_trap 666 | / assert_invalid 667 | / segment 668 | / func 669 | / global 670 | / import 671 | / export 672 | / table 673 | / memory 674 | / data 675 | / register 676 | / type_def 677 | / _start 678 | ) __ 679 | ")" { return node; } 680 | / node:expr { return node; } 681 | --------------------------------------------------------------------------------