caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] is it possible to embed an OCaml interpreter into an OCaml Module?
@ 2014-10-31 14:42 Christoph Höger
  2014-10-31 15:03 ` Peter Zotov
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Höger @ 2014-10-31 14:42 UTC (permalink / raw)
  To: caml users

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dear all,

I already asked this on stackoverflow and was pointed to
compiler-libs.toplevel - indeed this API seems to be sufficient to run
an OCaml interpreter from inside an OCaml program (as that seems to be
what utop does).

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

is there someone who can point me to a solution?
- -- 
Christoph Höger

Technische Universität Berlin
Fakultät IV - Elektrotechnik und Informatik
Übersetzerbau und Programmiersprachen

Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin

Tel.: +49 (30) 314-24890
E-Mail: christoph.hoeger@tu-berlin.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iEYEARECAAYFAlRTn9kACgkQhMBO4cVSGS97QwCfX59enOE89WWwvBu555V9LNM/
mCwAoLJ4PLkDlrLwA6A8OKzj8Elnpu0B
=uWdx
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [Caml-list] is it possible to embed an OCaml interpreter into an OCaml Module?
@ 2014-11-01 12:54 oleg
  2014-11-03 14:13 ` Christoph Höger
  0 siblings, 1 reply; 5+ messages in thread
From: oleg @ 2014-11-01 12:54 UTC (permalink / raw)
  To: christoph.hoeger; +Cc: caml-list



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());  *)
  ....


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-11-03 14:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-31 14:42 [Caml-list] is it possible to embed an OCaml interpreter into an OCaml Module? Christoph Höger
2014-10-31 15:03 ` Peter Zotov
2014-11-01 13:10   ` Stephen Dolan
2014-11-01 12:54 oleg
2014-11-03 14:13 ` Christoph Höger

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