Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Diego Olivier Fernandez Pons <dofp.ocaml@gmail.com>
To: caml-list@inria.fr
Cc: Gerd Stolpmann <info@gerd-stolpmann.de>,
	Xavier Leroy <Xavier.Leroy@inria.fr>,
	oliver <oliver@first.in-berlin.de>
Subject: Re: [Caml-list] How to write an efficient interpreter
Date: Wed, 26 Oct 2011 11:27:53 +0200	[thread overview]
Message-ID: <CAHqiZ-+6oS6KtuNKoZ=Pt-7qrKFUVBSfk-v=RKeG+nPB8HZ+aw@mail.gmail.com> (raw)
In-Reply-To: <20111024210108.GE1838@siouxsie>

[-- Attachment #1: Type: text/plain, Size: 2206 bytes --]

    List,

Thanks for your suggestions, here is a small summary of them with some
comments.

Options for interpreting a DSL
-------------------------------------------

1 - Classical optimised interpreter
2 - Combinator / partial application based interpreter
3 - Emitting bytecode for any VM
4 - Emitting Caml source and compile / run on the fly
5 - Retargeting Caml compiler (CamlP4 syntax extension + custom toplevel)

Comments
----------------

1. Is the most natural and first thing to try (working on optimising my
naive interpreter right now)

5. Is the second most obvious idea : in the same way C is a portable
assembler, core-ML is a portable functional language. If we could easily
write a Lex/Yacc parser and generate Caml AST or some kind of quote and
connect it to Caml, we could interpret many DST with little work. Moreover,
generating Caml source is useful for debugging or profiling and can be
compiled offline.

One comment is that Lex/Yacc is a tool that any engineer can manage while
CamlP4 is much more complex which increases maintainability risks.

4. Is the poor man's variant of 5.

2. Globally the idea is that evaluating Plus (Plus (Var "x", 3), 4) is
slower than calling sum [| get env "x"; 3 ; 4 |] with a pre-compiled 'sum'
function.

There is already an interpreter for that same language that is targets C++
combinators : operator overloading and class hierarchy build an "AST" (2 + 3
* x -> expr<int>) which instantiates a set of predefined operators (sum,
forall, etc). The experience was however not good IMHO : despite a (naive)
gc there are still permanent memory leaks and speed issues, part of the
semantics is lost which requires some guessing, there are weird limitations
like polymorphism that only works with 2 levels of nesting, finally the code
basis grows uncontrollably. Maybe C++ is to blame there. In any case that's
a second level of optimisation after 1.

3. Unless there is a 3rd part tool to emit the code, I won't get into this.
It would allow native interaction with the customer chosen platform (Java,
.NET, etc) but that's way too much trouble and risk as long as it is not a
standard technique that any engineer can handle.

        Diego Olivier

[-- Attachment #2: Type: text/html, Size: 2668 bytes --]

  reply	other threads:[~2011-10-26  9:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-24  9:10 Diego Olivier Fernandez Pons
2011-10-24  9:58 ` Gabriel Scherer
2011-10-24 10:57   ` Gerd Stolpmann
2011-10-24 11:28 ` Xavier Leroy
2011-10-24 11:50   ` Diego Olivier Fernandez Pons
2011-10-24 12:33     ` Jérémie Dimino
2011-10-24 12:40     ` Gerd Stolpmann
2011-10-24 12:46       ` oliver
2011-10-24 12:58         ` Gerd Stolpmann
2011-10-24 21:01           ` oliver
2011-10-26  9:27             ` Diego Olivier Fernandez Pons [this message]
2011-11-07  6:45               ` Jon Harrop

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHqiZ-+6oS6KtuNKoZ=Pt-7qrKFUVBSfk-v=RKeG+nPB8HZ+aw@mail.gmail.com' \
    --to=dofp.ocaml@gmail.com \
    --cc=Xavier.Leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=info@gerd-stolpmann.de \
    --cc=oliver@first.in-berlin.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox