caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: oleg@okmij.org
To: christoph.hoeger@tu-berlin.de
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] is it possible to embed an OCaml interpreter into an OCaml Module?
Date: Sat,  1 Nov 2014 08:54:25 -0400 (EDT)	[thread overview]
Message-ID: <20141101125425.90219C38B8@www1.g3.pair.com> (raw)



Christoph Hoeger wrote:

> But ist it also possible in some way to embed that interpreter safely
> in an OCaml Module (so I can reuse it e.g. from within utop)?
> Currently, it seems that there is exactly one dedicated toplevel for
> every running bytecode interpreter and when running utop, it is
> already in use.
>
> So what I would need would be the ability to execute a phrase from
> within a call of execute_phrase. I already clonded the toploop module
> and for tehe time being I am fine with that. What I need is a way to
>
> a) safe the already set ('outer') toplevel value bindings
> b) restore the nested value bindings
> c) execute the compiled bytecode
> d) restore the 'outer' value bindings

The MetaOCaml top-level does exactly what you have described. It is
the standard OCaml toplevel with the ability to execute the generated
code. Please look at the file metalib/runcode.ml in the MetaOCaml
distribution. If you get it from the metaocaml.bundle, you get the
current version. Otherwise, please to make sure the beginning of
run_bytecode starts as follows:

let run_bytecode' exp =
  if !initial_env = Env.empty then begin
    let old_time = Ident.current_time() in
    (* does Ident.reinit() and may corrupt the timestamp if we
       run in top-level. See Ident.reinit code
     *)
    initial_env := Compmisc.initial_env(); 
    Ident.set_current_time old_time
   end;
  (* Ctype.init_def(Ident.current_time());  *)
  ....


             reply	other threads:[~2014-11-01 12:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-01 12:54 oleg [this message]
2014-11-03 14:13 ` Christoph Höger
  -- strict thread matches above, loose matches on Subject: below --
2014-10-31 14:42 Christoph Höger
2014-10-31 15:03 ` Peter Zotov
2014-11-01 13:10   ` Stephen Dolan

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=20141101125425.90219C38B8@www1.g3.pair.com \
    --to=oleg@okmij.org \
    --cc=caml-list@inria.fr \
    --cc=christoph.hoeger@tu-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).