From: rixed@happyleptic.org
To: caml-list@inria.fr
Subject: Re: [Caml-list] Calling the toplevel from the toplevel
Date: Mon, 28 Feb 2011 19:28:13 +0100 [thread overview]
Message-ID: <20110228182813.GA5462@ccellier.rd.happyleptic.org> (raw)
In-Reply-To: <20110227120027.GA3544@aurora>
> Actually you can, you just have to make sure that .cmi files are
> available in the search paths of the toplevel when you run your
> application.
Yes, it works now. AFAICT the cmi have always been available,
but anyway...
> > - I cannot let the user uses the toplevel directives "use" and "load"
> > because both writes into stdout whatever the formatter passed to
> > Toploop.execute_phrase (for "use" this is easily solvable by shadowing
> > the toplevel implementation by another one that call Toploop.use_file
> > with my own formatter, but for "load" I would have to copy a lot of
> > code from topdirs.ml
>
> Why not use Topdirs.dir_load with a custom formatter ?
Because I had not noticed that these functions were available.
This is handy. So I end up with something similar to you, except
I don't shadow that much directives (only those I know and use
regularly, and I'm not very experienced with the toplevel to say
the least).
> If you are interested, i started some time ago an emacs-like editor
> which can run in both curses and gtk mode and which integrates a
> toplevel.
Haha!, this is the very same reason why I was asking these questions.
Except that my project is just a small pet project consisting only
of less than 1k LOC, and I hope it will stay that way. I'm just used
to mix C and scheme to use the scheme repl to manipulate the running
C app and wanted to know how easy/hard it would be to have the same
"hackability" with Ocaml.
> I add to face the same problems. I solved them by using
> Toploop.execute_phrase directly and redefining all directives.
I've seen. We use very similar approach.
The funny thing is that when I started I was convinced that it was
not possible to call the Toploop evaluator from within itself, and
tried many other solutions, until I noticed that topfind.ml actually
does this to enrich the toplevel directives.
> Also another problem i had is that Toploop.execute_phrase does not
> prints errors on the given formatter but raises an exception instead,
> and the printer used in Toploop.loop (Errors.report_error) is in the
> module Errors for which the cmi is not available.
I give the exception to Toploop.print_exception_outcome :
let top_eval cmd =
let cmd = Rope.to_string cmd in
Log.p "Executing '%s'" cmd ;
try
let l = Lexing.from_string cmd in
let ph = !Toploop.parse_toplevel_phrase l in
Toploop.execute_phrase true self#formatter ph
with exn ->
Toploop.print_exception_outcome self#formatter exn ;
false in
but the exceptions are only pretty printed to a depth of 1, further
values being replaced by "_", so it's far from perfect.
> I used a hack which
> consists on parsing the output of Toploop.use_silently (file
> peps_top.ml, function eval_command).
Ooooh, I see! I'd never come up with this idea.
BTW, do you have any future plan for peps?
next prev parent reply other threads:[~2011-02-28 18:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-26 21:44 rixed
2011-02-27 2:45 ` Guillaume Yziquel
2011-02-27 10:52 ` rixed
2011-02-27 12:00 ` Jérémie Dimino
2011-02-28 18:28 ` rixed [this message]
2011-02-28 20:30 ` Jérémie Dimino
2011-02-28 21:14 ` Yoann Padioleau
2011-03-03 18:34 ` rixed
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=20110228182813.GA5462@ccellier.rd.happyleptic.org \
--to=rixed@happyleptic.org \
--cc=caml-list@inria.fr \
/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