Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] - Convert Caml to C/C++, C#, PHP, etc -
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-10-09 (21:48)
From: Kuba Ober <kuba@m...>
Subject: Re: [Caml-list] - Convert Caml to C/C++, C#, PHP, etc -
On Friday 03 October 2008, Erik de Castro Lopo wrote:
> axllaruse wrote:
> > I would like to convert all the MTASC open source project to
> > C/C++ or PHP.
> Sorry, but you're crazy.
> MTASC is a compiler and compilers are one of the tasks that
> Ocaml does better that all of the languages you mention.
> Converting the MTASC compiler to a less capable language (yes, C++
> is less capable) would be an exercise in extreme Greenspunning:

Um, since Ocaml can be compiled to bytecode and said bytecode executed
by an interpreter written in C, that's sorta-kinda el-cheapo conversion
right there. One can work backwards.

1. Get the bytecode compiler to output C that resembles what would be
called in the interpreter loop. That still uses all of the interpreter's
innards, just removes the interpreter loop.

2. Tweak the bytecode compiler to output higher-level C stuff where
applicable. That way you can get C that looks more like C and less like

(2) is probably the hard part as it involves sweeping modifications to the
compiler. (1) is easy, you can do it on raw bytecode without touching
the compiler, although it'd be a good exercise to get to know the compiler.

Side note: is there an Ocaml bytecode-compiler written in Ocaml somewhere?
It'd be easier to work on than said compiler written in C/C++.

Cheers, Kuba