mirror of
https://github.com/pezkuwichain/wasm-instrument.git
synced 2026-04-22 04:27:57 +00:00
initial
This commit is contained in:
@@ -0,0 +1 @@
|
||||
out
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
# "Compile rust source and put it as a tested contract"
|
||||
|
||||
mkdir -p out
|
||||
rustc $1 -o out/contract.js -O --target wasm32-unknown-emscripten
|
||||
@@ -0,0 +1,74 @@
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
// Check for wasm support.
|
||||
if (!('WebAssembly' in window)) {
|
||||
alert('you need a browser with wasm support enabled :(');
|
||||
}
|
||||
|
||||
function loadWebAssembly(filename, imports) {
|
||||
return fetch(filename)
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(buffer => WebAssembly.compile(buffer))
|
||||
.then(module => {
|
||||
imports = imports || {};
|
||||
imports.env = imports.env || {};
|
||||
var env = imports.env;
|
||||
imports.env.memoryBase = imports.env.memoryBase || 0;
|
||||
imports.env.tableBase = imports.env.tableBase || 0;
|
||||
|
||||
/* rust/emscripten imports
|
||||
(import "env" "DYNAMICTOP_PTR" (global (;0;) i32))
|
||||
(import "env" "STACKTOP" (global (;1;) i32))
|
||||
(import "env" "STACK_MAX" (global (;2;) i32))
|
||||
(import "env" "enlargeMemory" (func (;0;) (type 0)))
|
||||
(import "env" "getTotalMemory" (func (;1;) (type 0)))
|
||||
(import "env" "abortOnCannotGrowMemory" (func (;2;) (type 0)))
|
||||
(import "env" "_abort" (func (;3;) (type 1)))
|
||||
(import "env" "___setErrNo" (func (;4;) (type 2)))
|
||||
|
||||
(import "env" "memory" (memory (;0;) 256 256))
|
||||
(import "env" "table" (table (;0;) 0 0 anyfunc))
|
||||
(import "env" "memoryBase" (global (;3;) i32))
|
||||
(import "env" "tableBase" (global (;4;) i32))
|
||||
*/
|
||||
|
||||
env.DYNAMICTOP_PTR = env.DYNAMICTOP_PTR || 0;
|
||||
env.STACKTOP = env.STACKTOP || 0;
|
||||
env.STACK_MAX = env.STACK_MAX || 0;
|
||||
env.enlargeMemory = env.enlargeMemory || function() { throw "error enlarging memory"; };
|
||||
env.getTotalMemory = env.getTotalMemory || function() { return 65536 * 256; };
|
||||
env.abortOnCannotGrowMemory = env.abortOnCannotGrowMemory || function() { throw "abort growing memory"; };
|
||||
env._abort = env.abortOnCannotGrowMemory || function() { throw "abort"; };
|
||||
env.___setErrNo = env.abortOnCannotGrowMemory || function() { throw "setting error no"; };
|
||||
env.memoryBase = env.memoryBase || 0;
|
||||
env.tableBase = env.tableBase || 0;
|
||||
|
||||
if (!imports.env.memory) {
|
||||
imports.env.memory = new WebAssembly.Memory({ initial: 256 });
|
||||
}
|
||||
if (!imports.env.table) {
|
||||
imports.env.table = new WebAssembly.Table({ initial: 0, element: 'anyfunc' });
|
||||
}
|
||||
return new WebAssembly.Instance(module, imports);
|
||||
});
|
||||
}
|
||||
|
||||
loadWebAssembly('out/contract.wasm')
|
||||
.then(instance => {
|
||||
var exports = instance.exports;
|
||||
var call = exports._call;
|
||||
var button = document.getElementById('do-call');
|
||||
button.value = 'Execute call';
|
||||
button.addEventListener('click', function() {
|
||||
call();
|
||||
}, false);
|
||||
}
|
||||
);
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<input type="button" id="do-call" value="(waiting for WebAssembly)"/>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+2
@@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
python -m SimpleHTTPServer 8000
|
||||
Reference in New Issue
Block a user