Live data from Hacker News

Show HN: Compiling C in the browser using WebAssembly

wasmer.io

61–70 of 74 posts

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

#61

Earlier quoted context omitted.

And then use webrtc (or ideally someone can revive a webtransport-p2p please !) to serve itself from a page to other people. Ideally http3 over webtransport-p2p! Then add some network discovery so we can advertise & find what's available on our networks!

Do you have a proper link to the webtransport-p2p idea? I've done a few searches but I think there's some mix of current implementation and deprecated implementation somehow. What is it that needs reviving?

The spec is inactive, afaik, no implementations. Got it backwards, pardon, p2p-webtransport. https://github.com/w3c/p2p-webtransport

I don't know why it's fallen off, to be honest, or what was raised against it. Highly desireable to a lot of p2p folk, a very promising webrtc datatransport replacement.

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

#62

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

The whole LLVM toolchain is a bit big. I think we can reduce much more the size. We actually researched on using tcc but unfortunately tcc doesn’t have a wasm backend (for generating wasm output). It would be awesome if they added it!

This project is also very much worth checking out.

https://cranelift.dev/

From the page:

Cranelift is a fast, secure, relatively simple and innovative compiler backend. It takes an intermediate representation of a program generated by some frontend and compiles it to executable machine code. Cranelift is meant to be used as a library within an "embedder".

It is in successful use by the Wasmtime WebAssembly virtual machine, for just-in-time (JIT) and ahead-of-time (AOT) compilation, and also as an experimental backend for the Rust compiler.

Cranelift is an optimizing compiler, but it aims to take a fresh look at which optimizations are necessary. We have explicitly avoided features -- such as advanced alias analysis or use of undefined behavior -- that have historically led to subtle miscompilations in other compilers. Cranelift consists of about 200 thousand lines of code; in contrast, e.g. LLVM consists of over 20 million lines of code, a hundred times larger. This difference also allows Cranelift to be relatively approachable to developers, researchers, auditors and others who wish to understand how it works.

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

#64

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.

Very interesting idea but I have to say that those goals are not possible with a simple OS, at least by OS definitions of simple :P

It is possible. I already embedded chibicc in exaequOS. I will continue with xcc and clang

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

#67

Earlier quoted context omitted.

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.

It’s sadly a bit more of a proof of concept than a hackable project. The docker build in the readme did work last time I tried, and there is a demo site at https://jprendes.github.io/emception/, but I’ve failed to modify it in the past to do other things

There is a fork at https://github.com/emception/emception that is trying to make it more production ready, but it looks like that may have stalled

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

#68
post #30

Earlier quoted context omitted.

Importing a wasm module from a wasm module is (non)surprisingly impossible to do -- you have to have a linker, abi and all that.

It is possible provided some care. I was looking into this with WAForth which compiles the wasm and loads it via a host function (ie. it is the hosts responsibility to make it available). I wanted to enable dynamic loading of words from disk which requires some book keeping and shuffling a bunch of bytes around during compilation to write out the bits necessary to have the host do that linking. It isn't impossible to…

Yep, you need to do the nasty bits by hand, that's what I mean.

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

#69

Earlier quoted context omitted.

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...

I see thanks, that's great.

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

#70
post #49

Earlier quoted context omitted.

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...

I don’t want to become the switch-statement guy, but neither can I resist, apparently. There are no technicalities in what is allowed in a switch statement: the same things are as with bare gotos. That is, a switch statement is a fancy goto, and case labels are just labels that look a bit funny. Except for the case labels being restricted to inside of the switch body, nesting doesn’t really come into it.

So then the question becomes, which things are you allowed to jump over? In C++, I don’t really know, the restrictions seem fairly stringent. In C, you can jump over anything except a declaration using a variably modified type (i.e. a variable-length array, a pointer to one, etc.), but keep in mind that the variables whose declarations you’ve jumped over will be uninitialized even if the declaration does have an initializer.

Post reply on HN