• comex 8 hours ago

    In the comparison with Emscripten using wasm-decompile [1], the author appears to have forgotten to turn on optimization. Yes, if you run emcc with no -O option then you will get extremely bad generated code quality, similar to most C compilers. Add -O and you get nice and tight code similar to what c4wa outputs.

    [1] https://github.com/kign/c4wa/blob/master/etc/doc/comparison....

    • soegaard 13 minutes ago

      I think, the author's goal was to produce wasm-code that had the same structure as the original C. Thus it makes sense to turn off the advanced optimizations.

    • lioeters 8 hours ago

      > c4wa needs Java 11 or above

      It sounded good until this part. Would have been nice if it were written in the subset of C that it supports, so it could compile the compiler to Wasm.

      • b0a04gl 17 minutes ago

        one wierd connection i realised later now, > volatile in c was for blocking reorders, forcing real mem reads, esp mmio or sync operations. wasm runs singlethreaded, no fences unless you go atomic. so compiler keeps volatile loads yeah, but wasm runtime ain't bound to order. it runs but doesn't mean anything. semantics gone. still compiles

        • s-macke 4 hours ago

          clang can compile into wasm pretty well via the

          --target=wasm32

          option. It creates small binaries. My 16-Bit x86 emulator with BIOS and DOS emulation is under 100kB [0].

          [0] https://github.com/s-macke/FSHistory

          • ncruces an hour ago

            And if you need parts of libc, you can use something like the below, for something more minimal than musl: https://github.com/Photosounder/MinQND-libc

            Personally, although I do use wasi-sdk (clang) and the wasm32-unknown-wasi triple, the result can be basically free-standing, depending on what flags you use.

            As a sibling post said, optimization matters, and using wasm-ctor-eval and wasm-opt also helps. But it's useful to keep full C semantics.

        • apitman 7 hours ago

          This is actually pretty compelling to me. I think the more support for freestanding wasm modules the better.

          I'm working on a custom wasm app runtime and I don't want to have to implement the entire API surface of Emscripten or WASI. The new component model is even more complex. I wish there was more tooling available for using C/Rust stdlib functions for things like reading files or opening a socket, but being able to define your own API to handle the actually operations in the host/module interface.

          • pyrolistical 7 hours ago

            Zig can also compile to free standing wasm

          • Anduia 5 hours ago

            Last commit on Jan 29, 2022

            • teo_zero 4 hours ago

              > here are some of the most commonly used features of C language NOT supported by c4wa. > [...] Almost all new features introduced in C99

              At least, it doesn't require K&R syntax for functions!