Question

I want to make a compiled language. I am currently evaluating backends. So far I am looking at C because of its speed of execution, compiling, and a small, easy to use compiler called TCC.

Having read the discussions here about using it as an intermediate language, I am trying to think about how to make it compatible with garbage collection, and handling exceptions. So far, I think I can solve both, but with much overhead.

Here are some of my thoughts on the other possible backends:

  1. Assembly: unportable and a total pain to program in.
  2. .NET: Feels really slow. 5 seconds to start up and 5 seconds to evaluate 1+2 on Ironpython and Boo. Unable to run without large library.
  3. JVM: Feels a bit slow. No access to binary libraries. Unable to run without large library.
  4. LLVM: No windows support. I hear that compiled executable size is 16 mb+
  5. C--: looks underdeveloped.
  6. C++: possibly. Can't find a nice small free one I can bundle with.

Can any of you change my mind or have more to add to this list?

Edit

I've been experimenting with LLVM recently. I found out that they have precompiled binaries and that it is possible to compile to native assembly.

http://www.antlr.org/wiki/display/CS652/Generating+machine+executable+binaries+with+LLVM

Here are the steps:

  1. Run llvm-as on LLVM Assembly, which yields a LLVM bytecode file.
  2. Run llc on the LLVM bytecode file to yield an assembly file.
  3. Run an assembler on the assembly file to yield an object file. (or run llvm-ld which seems to depend on an externally installed c compiler)
  4. Compile to executable with gcc etc.
Was it helpful?

Solution

Have you considered writing a frontend for GCC? I mention this for completeness’ sake only – as far as I know the backend interface is quite complicated and the codebase is huge and hard to comprehend.

On the other hand, GCC is a mature product with many expert programmers working on it. At the very least, it probably provides the most solid basis of all the alternatives.

Personally, I would prefer LLVM (exciting architecture) or .NET’s IL: very, very easy to use, has great tool support (Reflector, Cecil, Reflexil and last but not least, the .NET reflection API) and two very efficient implementations (namely Microsoft’s canonical implementation and Mono).

But I can’t claim expertise in any of the architectures so take this answer with a grain of salt.

OTHER TIPS

In that case LLVM is probably a better choice.

LLVM has Windows support, it just takes some time to compile

C++ won't give you much, use C instead. But if you want you language to be used in the Web, use .NET or Java, sure they slow to load but when they are, they as fast as C.

For SmartEiffel we use C as a back-end.

Tcc is a very good option for development- though not for final release (the produced object is equivalent to gcc -O0)

Another to add to the list: Slava recently implemented Smalltalk on a Factor backend. I haven't tried this myself, but I have the feeling it would offer more of the features you want from the higher-level ones with more like the size/performance from the lower-level ones.

TCC is the best choice. It is portable and it has a library so it can easily be used as a backend which is called libtcc. The executables are smaller than gcc and it is ANSI C.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top