From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 7B6BDBC69 for ; Thu, 16 Aug 2007 17:11:54 +0200 (CEST) Received: from einhorn.in-berlin.de (einhorn.in-berlin.de [192.109.42.8]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7GFBruY025747 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Thu, 16 Aug 2007 17:11:54 +0200 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: Received: from einhorn.in-berlin.de (localhost [127.0.0.1]) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id l7GFBrTW011944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Aug 2007 17:11:53 +0200 Received: (from www-data@localhost) by einhorn.in-berlin.de (8.13.6/8.13.6/Submit) id l7GFBrBv011942 for caml-list@inria.fr; Thu, 16 Aug 2007 17:11:53 +0200 X-Authentication-Warning: einhorn.in-berlin.de: www-data set sender to oliver@first.in-berlin.de using -f Received: from dslb-088-074-008-170.pools.arcor-ip.net (dslb-088-074-008-170.pools.arcor-ip.net [88.74.8.170]) by webmail.in-berlin.de (IMP) with HTTP for ; Thu, 16 Aug 2007 17:11:53 +0200 Message-ID: <1187277113.46c469394ff4e@webmail.in-berlin.de> Date: Thu, 16 Aug 2007 17:11:53 +0200 From: Oliver Bandel To: Caml List Subject: Re: [Caml-list] JIT VM in OCaml: Impossible? References: <5C180944-2CD9-48FB-8802-8AF57972AD2C@gmail.com> In-Reply-To: <5C180944-2CD9-48FB-8802-8AF57972AD2C@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.6 X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 X-Miltered: at discorde with ID 46C46939.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bandel:01 in-berlin:01 ocaml:01 ocaml:01 runtime:01 pointers:01 hacked:01 in-berlin:01 for-loop:01 for-loop:01 closures:01 closures:01 parsed:01 partial:01 partial:01 Zitat von Joel Reymont : > 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: http://www.first.in-berlin.de/software/tools/apalogretrieve/ 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 closures). You can make complex things by putting together partial applicated functions. Look at how I create the conditions in the above mentioned code. Ciao, Oliver P.S.: Functional Programming should be written in this way: FUNctional programming, because it really makes FUN, at least to me. :)