caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Till Varoquaux <till@pps.jussieu.fr>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: oleg@okmij.org, caml-list@inria.fr, ontologiae@gmail.com
Subject: Re: [Caml-list] Why NOT to compile OCaml via C
Date: Fri, 9 Dec 2011 19:20:16 -0500	[thread overview]
Message-ID: <CAHJESt0oOkX=4eT=xeaNr2AHcz=NEsLSibOV2YqK7e9sYTwiFQ@mail.gmail.com> (raw)
In-Reply-To: <87aa712v26.fsf@frosties.localnet>

You can use the bytecode compiler and interpreter on those
architectures. If you feel adventurous you can compile ocaml to java
or javascript and run wherever those languages run.

The hypothetical ocaml->c compiler would have to interact with the
garbage collector or use a different garbage collector; to be useful
it would also need to present a compatible FFI to pre-existing stubs.
You might also want to respect the limitations imposed by the current
framework (exceptions for stack-overflows; 31/63 bits ints...).
Writing portable C that low level is hard; generating it would be a
lot of work. I very much doubt that anyone who understands what's at
stake enough to be able to take a stab at it would consider this a
productive use of their time.

Till

On Fri, Dec 9, 2011 at 6:18 PM, Goswin von Brederlow <goswin-v-b@web.de> wrote:
> oleg@okmij.org writes:
>
>> Pierre-Alexandre Voye wrote:
>>
>>> Note that if Ocaml compiler would have a C backend, all these problems or
>>> architecture port would disappear...
>>> Ocaml would have more than 30 target[1]
>>> In my Opinion, trying to generate assembler is a bad idea because modern CPU
>>> require a lot of work to generate good assembler.
>>
>> There are many good reasons to avoid C when compiling functional
>> languages, especially strict ones.
>>
>> One often hears that ``C is a portable assembler''. That has never
>> been true. One of the reasons is that every assembler I know has the
>> "jmp" instruction, which, without affecting SP, transfers control
>> anywhere, out of a procedure or in the middle of a procedure, out of a
>> module or into a module. C is built around the stack discipline --
>> after all, C is a descendant of Algol 60. (Although C has labels, they
>> are limited, even in GCC). Although Algol-60 researchers quickly
>> recognized the value of tail recursion, all that knowledge was lost in
>> the Dark Ages.
>
> Well, write the code as ONE function and do use lables. Sure, the C
> source will be huge for larger projects but then again you get the
> single source optimization bonus from gcc.
>
> Note: gcc does know something about tail recusion. So it is not
> completly lost there.
>
> Personly I would like to have a ocaml -> C compiler. Not to replace the
> one we have but for fun or as alternative on architectures that don't
> have a native compiler (yet). It doesn't have to be hype efficient. If
> it is somwhere between the bytecode and native speed that would be
> totally fine.
>
> MfG
>        Goswin
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>


  reply	other threads:[~2011-12-10  0:20 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-09  6:57 oleg
2011-12-09  7:52 ` Stéphane Glondu
2011-12-09  9:58   ` Gabriel Scherer
2011-12-09 10:06     ` [Caml-devel] " Jonathan Protzenko
2011-12-09 11:03     ` Mehdi Dogguy
2011-12-09 12:08     ` Benedikt Meurer
2011-12-09 12:37       ` Gabriel Scherer
2011-12-09 14:05         ` Benedikt Meurer
2011-12-09 14:30           ` Török Edwin
2011-12-09 14:51             ` Benedikt Meurer
2011-12-09 23:38             ` oliver
2011-12-09 21:22           ` Richard W.M. Jones
2011-12-10  9:36             ` Benedikt Meurer
2011-12-10 11:34   ` Jon Harrop
2011-12-09 23:01 ` oliver
2011-12-09 23:18 ` Goswin von Brederlow
2011-12-10  0:20   ` Till Varoquaux [this message]
2011-12-10  7:35   ` oleg
2011-12-10 15:40   ` Basile Starynkevitch
2011-12-10 23:56     ` Peter Hawkins
2011-12-11  8:24       ` Basile Starynkevitch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHJESt0oOkX=4eT=xeaNr2AHcz=NEsLSibOV2YqK7e9sYTwiFQ@mail.gmail.com' \
    --to=till@pps.jussieu.fr \
    --cc=caml-list@inria.fr \
    --cc=goswin-v-b@web.de \
    --cc=oleg@okmij.org \
    --cc=ontologiae@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).