views:

513

answers:

6

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.
+3  A: 

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.

vava
I like C++ because it already has stack unwinding exceptions and I can encapsulate pointers to make them more garbage unfriendly, unfortunately the compilers available seem to be extremely large and take longer to compile.
Unknown
+2  A: 

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)

cadrian
I read about many languages that used C as the backend, and yours was one of them. Was it hard for you to output C code that could be easily garbage collected?
Unknown
We have our own GC implementation, with specialized buckets for each type (our language is close-world; every type is known at compile time). The only complex part is being sure of marking every live object: we use some markers in the stack + registers saving for those architectures that need it.
cadrian
+4  A: 

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.

Konrad Rudolph
+3  A: 

In that case LLVM is probably a better choice.

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

I've tried to read all the LLVM documents. From what I can understand from it so far, I don't want to force users to install the large runtime, which takes 3 GB to compile.
Unknown
LLVM is not a runtime, it is a compiler framework.Once your application is compiled, it will run as any other native binary on windows
I only read documentation that mentions bytecode compilation. Even if it does allow static compilation, I don't even have 3 GB of memory to compile it under windows and can't expect anyone else to either.
Unknown
+1  A: 

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.

Ken
A: 

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.

I've already started using C++ as a backend so I don't have to implement STL containers and OOP. I experimented with TCC and found it small and fast, but I heard the code it compiles is not optimized at all.
Unknown