开发者

Compiling to idiomatic C

开发者 https://www.devze.com 2022-12-13 09:06 出处:网络
Are there any compilers out there for function or lisp-ish languages that compile to idiomatic C?Most compilers out there seem to provide something resembling a machine language composed of C macros.I

Are there any compilers out there for function or lisp-ish languages that compile to idiomatic C? Most compilers out there seem to provide something resembling a machine language composed of C macros. I'm wonde开发者_运维百科ring if there is anything out there that can produce readable C code based on a higher-level language.


Given that you tagged this question with Haskell I'll give a Haskell answer. JHC is a Haskell compiler which produces fairly idiomatic ansi-C. It's an optimizing whole-program compiler that can produce incredibly fast binaries. I'm not sure how stable it is at the moment though, and there seems to be limits to how big programs it can handle. But don't take my word for it, check it out yourself.


For Common Lisp there is currently only one widely used compiler that compiles to C: ECL. You would need to look if the output it is readable enough.

Years ago a company sold a Common Lisp compiler for exactly this purpose: compiling Lisp to 'maintainable' C. The compiler was very expensive. It is no longer available, but it still seems to be used in one or two companies: Lisp to C .


I only found a C->C++ converter. I'm not sure that you can convert most functional languages to LISP. The structure and syntax doesn't match up very well. I'm sure that you could find many converters for C++ though.


The haskell compiler built-in compiles to C. Although IIRC it isn't that pretty looking.
(Checked, 162 lines for main = putStrLn "Hello, World!"

Edit: GHC of course.


There is a Scheme compiler called Stalin that generates highly optimized C source code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号