Skip to content

Instantly share code, notes, and snippets.

@yutopp
Created May 22, 2017 01:55
Show Gist options
  • Save yutopp/18f38b5eebba1ebf1422243a79dfe689 to your computer and use it in GitHub Desktop.
Save yutopp/18f38b5eebba1ebf1422243a79dfe689 to your computer and use it in GitHub Desktop.
def main() {
ref a = fib(10);
a.print();
}
import std.stdio;
def fib(v: int32): int32 {
return if ( v == 0 ) 0
else if ( v == 1 ) 1
else fib(v-1) + fib(v-2);
}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>zoi</title>
<script>
fetch('fib.wasm')
.then(response => response.arrayBuffer())
.then(buffer => WebAssembly.compile(buffer))
.then(module => {
let importObject = {
env: {rill_print_int32: (i32) => { alert(`print_int32: ${i32}`); }}
};
let instance = new WebAssembly.Instance(module, importObject);
instance.exports._Rill_main(); // main()呼び出し
});
</script>
</head>
<body>Hello</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment