Making a language, need a good backend

梦想的初衷 提交于 2019-12-09 12:33:45

问题


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.

回答1:


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.




回答2:


In that case LLVM is probably a better choice.

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




回答3:


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.




回答4:


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)




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/720714/making-a-language-need-a-good-backend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!