What does HackerNews think of tinycc?

Unofficial mirror of mob development branch

Language: C

#34 in C
#26 in Compiler
#7 in JavaScript
Perhaps https://github.com/TinyCC/tinycc would be useful? I've had success using it to implement a repl for my language.
I have found the libtcc from https://github.com/TinyCC/tinycc to be absolutely fantastic. I'm using it to instantaneously compile the C output from my hobby language to create a repl. Once I had the compiler in good shape it allowed me to create a 100% compatible interpreter for (basically) free.

The libtcc API is minimal. For my needs that has been 100% sufficient and a pleasure to work with.

bun:ffi is available in the current version of bun.

Here's an example that uses raylib (GUI library), without any extra bindings/build step: https://github.com/theoparis/bunray/blob/main/src/example.ts

bun:ffi works by embedding TinyCC - https://github.com/TinyCC/tinycc and then just-in-time compiling C functions that perform type conversions from JavaScript <> C ABI and back. It's faster than node.js' napi (which bun also supports) because it avoids the dynamic library overhead via doing type conversions inline.

For bun, I really wanted something simpler than napi without the performance drawbacks of libffi.

If you want to see the generated C bindings, you can do this:

    import { viewSource } from "bun:ffi";

    console.log(
        viewSource(
            {
            hello_world: {
                returns: "float",
                args: ["float"],
            },
            },
            false
        )[0]
    );
You could transpile to C and feed that to LLVM/Clang or e.g. to TCC (https://github.com/TinyCC/tinycc).
Tiny C compiler (tcc) is really cool. I used it as a test case in my diverse double-compiling (DDC) work to counter the trusting trust attack: http://www.dwheeler.com/trusting-trust/

There has been some continued development of tcc; the GitHub repository here has changes through April 2016: https://github.com/TinyCC/tinycc