English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
JIT VM in OCaml: Impossible?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-08-16 (15:11)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] JIT VM in OCaml: Impossible?
Zitat von Joel Reymont <joelr1@gmail.com>:

> Folks,
> Is it possible to write a JIT VM in OCaml?
> It seems that this should not be possible as OCaml does not allow for
> code generation at runtime. Am I mistaken?

It is possible to create functions on the fly
via putting together available functions by partial function application.

If you parse a "sin" in your code, you can use the "sin" form ocaml,
applying nor arguments to it. (Like passing function pointers in C,
but it's more elegant in functional languages, and more convenient.)

So it is possible to create applicable code.
I use this in one of my tools. There I create
certain comparison functions, for example, dependend
on what I parsed from my input.

I do this by creating closures (which means that
the functions that are the closures can be applied to
the arguments later).

A not perfect example (quick but not so dirty hacked, but possible
to make it better, as I just saw, when I answered your mail and
looked again in my *.mly, but maybe it can give you an idea
about what can be done, or how it could be done) is my tool
"apalogretrieve", which makes SQL-like queries on Apache
common logfiles:


I know, it's not perfect (so, maybe the OCaml Gurus might
laugh about it) but it works for my needs and was done in
a short time, scattered about a long time.

Maybe it give's you an idea.

For a complete language to implement your stuff might
need more code, but if you have to implement a for-loop for example,
you could parse it from your language and create a
closure, which calls an OCaml for-loop directly (in the

You can make complex things by putting together partial applicated
functions. Look at how I create the conditions in the above mentioned code.


P.S.: Functional Programming should be written in this way:
      FUNctional programming, because it really makes FUN,
      at least to me. :)