Live data from Hacker News

Show HN: Compiling C in the browser using WebAssembly

wasmer.io

41–50 of 74 posts

Re: Show HN: Compiling C in the browser using WebAssembly

#41

Couldn’t a tcc or similarly simple C compiler be used instead of a 100MB Clang? Where’s the C to wasm compiler hiding?

I recently wanted to use tcc for a homebaked programming sideproject and was surprised to find it's no longer supported anymore, at least not by Fabrice Bellard. Upstream git still has some light activity but no releases. I wasn't sure how good of an idea it is to rely on it as a code generator.

Re: Show HN: Compiling C in the browser using WebAssembly

#43

Couldn’t a tcc or similarly simple C compiler be used instead of a 100MB Clang? Where’s the C to wasm compiler hiding?

I recently wanted to use tcc for a homebaked programming sideproject and was surprised to find it's no longer supported anymore, at least not by Fabrice Bellard. Upstream git still has some light activity but no releases. I wasn't sure how good of an idea it is to rely on it as a code generator.

It's alive and kicking my friend https://repo.or.cz/tinycc.git/shortlog

We wait for grischka to decide when to announce a new release https://lists.nongnu.org/archive/html/tinycc-devel/2024-10/m...

Re: Show HN: Compiling C in the browser using WebAssembly

#44

Now all this needs is a simple OS running in a browser, that can edit and compile itself, post the resulting binary onto a WebDAV somewhere, and reload itself from there. Then it becomes a fully self-sustaining OS that can live forever in a browser.

Something like exaequOS? https://exaequos.com

Re: Show HN: Compiling C in the browser using WebAssembly

#45
A few weeks ago, I tried to compile Clang to WebAssembly, but got several different errors, and tried fixing a lot of them, but some of them seemed kind of impossible to fix, so I thought I would try again at a later date. However it seems I will not need to try again. I feel angry that someone made a convenient solution before I did, but also happy, because this probably implies that they made a consistent process to compile Clang for WASM.

Re: Show HN: Compiling C in the browser using WebAssembly

#46
post #29

Earlier quoted context omitted.

One issue with Wasm is you essentially can't target it with a single-pass compiler, unlike just about any real machine. Wasm can only represent reducible control flow, so you have to pass your control-flow graph through some variation of the Relooper[1,2]. I don't know if upstream tcc can do that (there are apparently some forks?..). [1] http://troubles.md/why-do-we-need-the-relooper-algorithm-aga... [2] https://medi…

> you essentially can't target it with a single-pass compiler, That might be true if your source language has goto, but for other languages that start with structured control flow, it's possible to just carry the structure through and emit Wasm directly from the AST.

Presumably C's `switch` is also a problem.

Re: Show HN: Compiling C in the browser using WebAssembly

#47

Earlier quoted context omitted.

MB, right? Mb is megabit I only have to bring this up because network providers still insist on measuring bits

They insist on it because it is the proper way to measure data rates on serial bit streams where out-of-band encoding doesn't divide up on octet boundaries.

They insist on it because big number sell better.

Re: Show HN: Compiling C in the browser using WebAssembly

#49
post #29

Earlier quoted context omitted.

> you essentially can't target it with a single-pass compiler, That might be true if your source language has goto, but for other languages that start with structured control flow, it's possible to just carry the structure through and emit Wasm directly from the AST.

Presumably C's `switch` is also a problem.

Yes, I don't recall all the confusing elements and technicalities of what's allowed in Switch statements in C offhand but here are a few brainfscks:

https://old.reddit.com/r/C_Programming/comments/16kg48y/mind...

https://old.reddit.com/r/programminghorror/comments/ylc7f3/w...

Re: Show HN: Compiling C in the browser using WebAssembly

#50
post #3

Is it possible/already existing to have interactive C++ lessons where the user's C++ code is compiled an run client-side in a web page?

See: emception https://github.com/jprendes/emception

Thanks, I'm seeing but the documentation is so scarce and I'm not a proefficient C expert.

What syntax can be used to run emception? Thank you.

Post reply on HN