From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p9OCkPkh009599 for ; Mon, 24 Oct 2011 14:46:25 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AucCANZcpU7AbSoIe2dsb2JhbABDhHWiFIIJIgEBFiYEIYFuAQEFI1EFEAsJBQoCAiYCAhQYMYgVoXORMxKBHoV8M2EEjHeYbw X-IronPort-AV: E=Sophos;i="4.69,398,1315173600"; d="scan'208";a="125593861" Received: from einhorn.in-berlin.de ([192.109.42.8]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 Oct 2011 14:46:20 +0200 X-Envelope-From: oliver@first.in-berlin.de Received: from first (e178015013.adsl.alicedsl.de [85.178.15.13]) (authenticated bits=0) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id p9OCkHOL003130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Mon, 24 Oct 2011 14:46:18 +0200 Received: by first (Postfix, from userid 1000) id BB4A7154012A; Mon, 24 Oct 2011 14:46:17 +0200 (CEST) Date: Mon, 24 Oct 2011 14:46:17 +0200 From: oliver To: Gerd Stolpmann Cc: Diego Olivier Fernandez Pons , Xavier Leroy , caml-list@inria.fr Message-ID: <20111024124617.GA2287@siouxsie> References: <4EA54BD0.8090009@inria.fr> <1319460013.18639.90.camel@thinkpad> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1319460013.18639.90.camel@thinkpad> User-Agent: Mutt/1.5.20 (2009-06-14) X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 Subject: Re: [Caml-list] How to write an efficient interpreter On Mon, Oct 24, 2011 at 02:40:13PM +0200, Gerd Stolpmann wrote: > Am Montag, den 24.10.2011, 13:50 +0200 schrieb Diego Olivier Fernandez > Pons: > > Caml-list, > > > > > > Xavier Leroy wrote > > > Compiling to bytecode is probably overkill. > > > > > > > > I think that writing my own bytecode interpreter is looking for > > trouble. Same for compiling to an existing bytecode. > > > > > > The language being a kind of SQL, most of the work is to properly > > execute the comprehensions (= queries). > > > > > > For instance > > > > > > range numbers = 0 .. 100; > > {int} sqrtLessThan [k in numbers] = { x | x in numbers : x * x > > <= k }; > > > > > > There are smarter ways to implement this than a double loop > > > > > > I was rather thinking of translating on-the-fly into Caml code and > > letting Caml do the job. Is that technically possible (rewriting a > > toplevel ? a CamlP4 grammar ?). If so guess I would have to license > > the Caml compiler from the INRIA. > > I don't think you need that, because you can load compiled OCaml code > dynamically (look into the Dynlink library). [...] Maybe you both talk about different things... What you seem to talk about is not interpreter but compiler stuff, and later bind it together?! I would assume, with "translating on-the-fly into Caml code" is something meant that could be done via partial application. Parsing the language that you implement, and create partial applicated functions of OCaml-code that do the work. This can be done straight forward and nearly "ad hoc". It's an easy way to go. Yo can create such partial applicated functions while prsing or from an AST that you construct in parsing stage. Ciao, Oliver