-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
176 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
rm -f *.cmi *.cmx *.o a.out* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
let () = | ||
for i = 1 to 5 do | ||
print_int i; | ||
print_string " plop\n" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Test</title> | ||
<style> | ||
html { | ||
--ntp-focus-shadow-color: rgba(var(--google-blue-600-rgb), .4); | ||
--ntp-theme-text-color: var(--google-grey-800); | ||
background-attachment: fixed; | ||
background-color: rgba(255,255,255,1); | ||
background-position: -64px; | ||
background-repeat: no-repeat; | ||
height: 100%; | ||
overflow: auto; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
html { | ||
--ntp-focus-shadow-color: rgba(var(--google-blue-300-rgb), .5); | ||
--ntp-theme-text-color: white; | ||
} | ||
} | ||
|
||
body { | ||
align-items: center; | ||
display: flex; | ||
height: 100vh; | ||
justify-content: center; | ||
margin: 0; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<script type="module" src="./test.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
const memory = new WebAssembly.Memory({ | ||
initial: 1, | ||
maximum: 1, | ||
}); | ||
|
||
function print_string(str) { | ||
console.log('print_string'); | ||
var res = ""; | ||
for (i = 0; i < get_length(str); i++) { | ||
res = res + String.fromCharCode(get_char(str, i)); | ||
} | ||
console.log(res); | ||
}; | ||
var str_buff = ""; | ||
function print_string_mem(off, len) { | ||
// console.log('print_string_mem'); | ||
const buff = new Uint8Array(memory.buffer); | ||
// console.log(buff); | ||
var i = 0; | ||
for (i = 0; i < len; i++) { | ||
var char = String.fromCharCode(buff[i+off]); | ||
str_buff = str_buff + char; | ||
} | ||
}; | ||
|
||
function print_i32(arg) { | ||
str_buff = str_buff + arg.toString(); | ||
}; | ||
function print_f64(arg) { | ||
console.log(arg); | ||
}; | ||
|
||
function print_endline() { | ||
console.log(str_buff); | ||
str_buff = ""; | ||
} | ||
|
||
function putchar(i_char) { | ||
var char = String.fromCharCode(i_char); | ||
str_buff = str_buff + char; | ||
}; | ||
|
||
function flush() { | ||
console.log(str_buff); | ||
str_buff = ""; | ||
} | ||
|
||
const bindings = { | ||
"print_i32": print_i32, | ||
"print_f64": print_f64, | ||
"print_string": print_string, | ||
"print_string_mem": print_string_mem, | ||
"print_endline": print_endline, | ||
"putchar": putchar, | ||
"flush": flush, | ||
"memory": memory | ||
} | ||
|
||
const src = "./a.out.wasm" | ||
const code = fetch(src) | ||
const imports = {"js_runtime":bindings} | ||
const wasmModule = await WebAssembly.instantiateStreaming(code,imports) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters