Live data from Hacker News

C as an intermediate language (2012)

yosefk.com

31–32 of 32 posts

Re: C as an intermediate language (2012)

#31
post #14
post #10

Earlier quoted context omitted.

Wouldn't that be even easier if you used LLVM IR, as you'd then be able to write your runtime in any language that LLVM supports?

In C you can write you run-time in any language that C can link to. Which is rather a lot of languages, and isn't tied to any particular compiler.

Yes and no. You can, but if you wrote your runtime in e.g. Haskell or Python you'd lose most of the advantages the article describes - debugging and tracing would be much more complicated for anything that called into the runtime, and profiling would become very difficult.

As a linkage format C is both too high-level (it provides a lot of facilities that are irrelevant to this use case - so while C may be ubiquitous now, I suspect it's much easier to implement an interpreter from scratch for something like LLVM bytecode) and too low-level (it exposes the host machine's memory model, making it inherently unportable). Use the right tool for the job - programming languages for writing programs in, intermediate representations for code for representing intermediate code.

Re: C as an intermediate language (2012)

#32
post #28

Earlier quoted context omitted.

C: AKA "portable assembler" :-)

TI has a DSP processor where the assembly looks quite much like the early days of C: mov reg1, reg2 ==> reg1 = reg2 mov reg1, [reg2] ==> reg1 = *reg2 add reg1, reg2 ==> reg1 += reg2 And so on.

looks sort of like PDP 11 assembler, particularly the [] brackets for indirect access through a register.
Post reply on HN