mooigraph a2732f9b6a next c wasm test added | 3 سال پیش | |
---|---|---|
.. | ||
0m.sh | 3 سال پیش | |
README.md | 3 سال پیش | |
add.c | 3 سال پیش | |
add.html | 3 سال پیش | |
add.wasm | 3 سال پیش | |
add2.html | 3 سال پیش | |
lenstr.c | 3 سال پیش | |
lenstr.wasm | 3 سال پیش | |
lenstr3.html | 3 سال پیش |
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.