Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tommy-mitchell/c-learning
A collection of C demos compiled to WebAssembly and run with JS.
https://github.com/tommy-mitchell/c-learning
Last synced: 8 days ago
JSON representation
A collection of C demos compiled to WebAssembly and run with JS.
- Host: GitHub
- URL: https://github.com/tommy-mitchell/c-learning
- Owner: tommy-mitchell
- Created: 2021-05-07T00:08:08.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-27T07:50:58.000Z (over 2 years ago)
- Last Synced: 2023-03-10T11:26:16.920Z (over 1 year ago)
- Language: C
- Homepage:
- Size: 347 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# C Learning
A repository to document my learning of C during the summer of 2019, using [this book](https://www.goodreads.com/book/show/16248728-programming-in-c-4th-edition). Some examples were from the book (primarily the bitwise operators), others from the web, and one was a recreation of a game from my high school CS class.
## Online Demos
An online version of this repository can be found [here](https://tommy-mitchell.github.io/C-Learning/).
Using [WASI-SDK's](https://github.com/WebAssembly/wasi-sdk) included [wasi-libc](https://github.com/WebAssembly/wasi-libc), I compiled these demos into WebAssembly and implemented a barebones [WASI](https://wasi.dev/) interface in JavaScript following [this tutorial](https://rob-blackbourn.github.io/blog/webassembly/wasm/strings/javascript/c/libc/wasm-libc/clang/2020/06/20/wasm-stdout-stderr.html). I used the following command to compile each `.c` file:
`clang --target=wasm32-unknown-wasi --sysroot= -O3 -flto -Wl,--export=malloc -Wl,--export-all -Wl,--lto-O3 src.c -o src.wasm`
From there, I made a script ([instance.js](Web/WASI/instance.js)) that would instatiate each WASM source and handle inputs for it, so that all each page had to do was call `instatiate` with some optional program-specific runners.