caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gerd Stolpmann <info@gerd-stolpmann.de>
To: oliver <oliver@first.in-berlin.de>
Cc: Diego Olivier Fernandez Pons <dofp.ocaml@gmail.com>,
	Xavier Leroy <Xavier.Leroy@inria.fr>,
	caml-list@inria.fr
Subject: Re: [Caml-list] How to write an efficient interpreter
Date: Mon, 24 Oct 2011 14:58:30 +0200	[thread overview]
Message-ID: <1319461110.18639.96.camel@thinkpad> (raw)
In-Reply-To: <20111024124617.GA2287@siouxsie>

Am Montag, den 24.10.2011, 14:46 +0200 schrieb oliver:
> 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?!

Exactly. But what's the big difference? You want to run code of a
domain-specific language.

> I would assume, with "translating on-the-fly into Caml code"
> is something meant that could be done via partial application.

The interpretative overhead does not go away with this technique. E.g.
looking up variables in your interpretation environment. I'd consider
this as a micro-optimization that doesn't bring much improvement.

Gerd

> 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
> 

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
*** Searching for new projects! Need consulting for system
*** programming in Ocaml? Gerd Stolpmann can help you.
------------------------------------------------------------


  reply	other threads:[~2011-10-24 12:59 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 [this message]
2011-10-24 21:01           ` oliver
2011-10-26  9:27             ` Diego Olivier Fernandez Pons
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=1319461110.18639.96.camel@thinkpad \
    --to=info@gerd-stolpmann.de \
    --cc=Xavier.Leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=dofp.ocaml@gmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).