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.