mooigraph a2732f9b6a next c wasm test added | %!s(int64=3) %!d(string=hai) anos | |
---|---|---|
.. | ||
0m.sh | %!s(int64=3) %!d(string=hai) anos | |
README.md | %!s(int64=3) %!d(string=hai) anos | |
add.c | %!s(int64=3) %!d(string=hai) anos | |
add.html | %!s(int64=3) %!d(string=hai) anos | |
add.wasm | %!s(int64=3) %!d(string=hai) anos | |
add2.html | %!s(int64=3) %!d(string=hai) anos | |
lenstr.c | %!s(int64=3) %!d(string=hai) anos | |
lenstr.wasm | %!s(int64=3) %!d(string=hai) anos | |
lenstr3.html | %!s(int64=3) %!d(string=hai) anos |
test compiling c to wasm without c-lib or emscripten using clang-7 and ./0m shell script
add.wasm adds two int numbers and prints result on console log
lenstr.wasm print length of string on console log
because lenstr.wasm uses wasm memory add linker flag -Wl,--import-memory to clang
It needs lld package installed and python webserver but not thttpd
python -m SimpleHTTPDServer
Then browse to localhost:8000
Using firefox developers console to see output from console.log()
From wasi-libc on github git clone https://github.com/CraneStation/wasi-libc.git
This is how wasm in c allocates memory in PAGESIZE sizes at once
uintptr_t old = __builtin_wasm_memory_grow(0, (uintptr_t)increment / PAGESIZE);
and this is wasm pagesize definition:
The page size in WebAssembly is fixed at 64 KiB. If this ever changes, it's expected that applications will need to opt in, so we can change this.
#define PAGESIZE (0x10000)
end.