diff options
author | Ben Smith <binji@chromium.org> | 2016-04-18 01:30:24 -0700 |
---|---|---|
committer | Ben Smith <binji@chromium.org> | 2016-04-18 01:31:01 -0700 |
commit | cbd283ada1e6d9915bea1e02560e2ef8700123d1 (patch) | |
tree | 8194d1d4ff2c4b8fe971f1501803696e77c7a854 /demo/demo.js | |
parent | 36a1f6a90c854523b80fa3166facb08e65dcfdbd (diff) | |
download | wabt-cbd283ada1e6d9915bea1e02560e2ef8700123d1.tar.gz wabt-cbd283ada1e6d9915bea1e02560e2ef8700123d1.tar.bz2 wabt-cbd283ada1e6d9915bea1e02560e2ef8700123d1.zip |
more demo stuff
* Need to call wasm.markUsedBlocks for the binary writer to work
properly
* Make .wast and .wasm into links
* Add another example, with a bunch of sections
* Clamp the length of the error caret line
Diffstat (limited to 'demo/demo.js')
-rw-r--r-- | demo/demo.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/demo/demo.js b/demo/demo.js index 16bd66a6..40e937d0 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -97,7 +97,8 @@ function onError(loc, error, sourceLine, sourceLineColumnOffset) { ]; if (sourceLine.length > 0) { var numSpaces = loc.firstColumn - 1 - sourceLineColumnOffset; - var numCarets = loc.lastColumn - loc.firstColumn; + var numCarets = + Math.min(loc.lastColumn - loc.firstColumn, sourceLine.length); lines.push(sourceLine); lines.push(' '.repeat(numSpaces) + '^'.repeat(numCarets)); } @@ -118,6 +119,7 @@ function compile(text) { var jsWriter = new wasm.JSStringWriter(); var logStream = new wasm.Stream(jsWriter.writer); var options = new wasm.WriteBinaryOptions({logStream: logStream}); + wasm.markUsedBlocks(allocator, script); wasm.writeBinaryScript(allocator, memoryWriter.base, script, options); output.textContent = jsWriter.string; } catch (e) { @@ -181,6 +183,20 @@ var examples = [ ' (get_local 0)\n' + ' (i64.const 1)))))))\n' + ' (export "fac" $fac))\n' + }, + + { + name: 'stuff', + contents: + '(module\n' + + ' (memory 1 (segment 0 "hi"))\n' + + ' (type (func (param i32) (result i32)))\n' + + ' (import "foo" "bar" (param f32))\n' + + ' (start 0)\n' + + ' (table 0 1)\n' + + ' (func)\n' + + ' (func (type 0) (i32.const 42))\n' + + ' (export "e" 1))\n' } ]; |