mooigraph a2732f9b6a next c wasm test added | 3 lat temu | |
---|---|---|
.. | ||
0m.sh | 3 lat temu | |
README.md | 3 lat temu | |
add.c | 3 lat temu | |
add.html | 3 lat temu | |
add.wasm | 3 lat temu | |
add2.html | 3 lat temu | |
lenstr.c | 3 lat temu | |
lenstr.wasm | 3 lat temu | |
lenstr3.html | 3 lat temu |
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.