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 p9OBSLxC006269 for ; Mon, 24 Oct 2011 13:28:21 +0200 X-IronPort-AV: E=Sophos;i="4.69,397,1315173600"; d="scan'208";a="125567655" Received: from estephe.inria.fr (HELO [128.93.11.95]) ([128.93.11.95]) by mail1-relais-roc.national.inria.fr with ESMTP; 24 Oct 2011 13:28:16 +0200 Message-ID: <4EA54BD0.8090009@inria.fr> Date: Mon, 24 Oct 2011 13:28:16 +0200 From: Xavier Leroy User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Thunderbird/3.1.13 MIME-Version: 1.0 To: caml-list@inria.fr References: In-Reply-To: X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] How to write an efficient interpreter On 10/24/2011 11:10 AM, Diego Olivier Fernandez Pons wrote: > I have to write an interpreter for a datatype rich purely applicative > language. I have already written a naive interpreter (like in programming > languages class) and was wondering what where the options for writing > something that would perform better while keeping it maintainable by a single > person < 5% dedicated and preferably only in core-ML (no C code or fancy ML > extensions). Gabriel and Gerd gave very good advice already, but here are my two cents: - Beware of premature optimizations. It could very well be that your naive interpreter is already fast enough for your applications. Test and profile to find hot spots. - Pay special attention to your data structures, e.g. environments should be maps, not A-lists. A good trick is to hash-cons identifiers into unique integers: not only comparisons are much faster, but you can use Patricia trees for your environments. - Compiling to bytecode is probably overkill. Hope this helps. - Xavier Leroy