If I understand your question correctly, you want to make something like this. Going off of that assumption, you have two ways to go about this problem:
1. Client-side compilation:
In order to do this, you'll have to get your hands on a WASM binary of a C compiler, that supports WASM output. AFAIK no one is distributing WASM binaries (yet), so you'll have to compile a WASM compiler with itself, and if you have to, you'll have to compile the compiler itself with another compiler. This might involve changing up the source code in the following ways:
- Change up the
main
function take input from stdin
and output the binary to stdout
, so that JavaScript (Angluar) can access it.
- Create an interface function, for example
char* js_compile(char* source)
, which, as you can probably see, will take the source code, execute main
with the appropriate arguments, and return the binary.
This method will be the best architecturally, since you won't need to host a server, and the client will be responsible for compiling his own code. However, as you can probably see, this is quite a difficult method, and doing it will probably take several years off of your life.
2. Server-side compilation:
With this method, you'll create a backend (it can be in any language/framework, but I prefer NodeJS/ExpressJS). Then, the backend will expose a HTTP post route (for example, /compile
), that will read the body as source. Then, the server will run the code trough a compiler, installed on the server. Finally, the compiler will either respond with the WASM bytecode, the result of the compilation, or with the errors, that the compilers has raised during the compilation.
This of course is the easiest method, but you'll need to host (and probably pay) for a server. If you're OK with that, this is the method you should use.
3. Client-side C interpreter
Here, you'll need to get your hands on a C interpreter, written in JavaScript. Unfortunately, AFAIK, there aren't any COMPLETE C interpreters, but if you're ok with that, you can take a look at this thread. Another solution would be to write an interpreter yourself, but good luck with that.
TL; DR: Pretty complicated, either use a modified WASM compiler on the client, compiler on the server, or interpret the code.
P.S.: If you want me to elaborate on anything, make sure to comment on this post