caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
To: caml-list@inria.fr
Subject: Re: [Caml-list] A few questions regarding the compiler
Date: Sun, 11 Nov 2001 21:54:25 +0000 (UTC)	[thread overview]
Message-ID: <slrn9utssh.cck.qrczak@qrnik.zagroda> (raw)
In-Reply-To: <9smdf7$511$1@qrnik.zagroda>

Sun, 11 Nov 2001 18:38:30 +0100, Xavier Leroy <xavier.leroy@inria.fr> pisze:

> In 3.03 alpha and in the forthcoming 3.03, additional "hooks" were
> added to the toplevel so that it can call user-provided functions for
> displaying evaluation results, including uncaught exceptions.  The
> Camlp4 preprocessor makes good use of this new feature.

Only toplevel? I would like to have it in standalone executables.
It doesn't have high priority though - often exceptions are defined
in OCaml, wrapped in objects of my language only when catching,
reraised in their original form, so then they are printed reasonably.

I was thinking about backtraces. It would be very helpful because the
compiled language is dynamically typed so errors are often catched
at runtime. Unfortunately translating an OCaml backtrace to something
related to source positions would be very tricky. It would even have
to be pasted manually to an external tool because the program proper
doesn't have access to its backtrace when it fails - it's just printed
to stderr when it's too late.

>>    I think it should be possible to start ocaml (or a custom
>>    toplevel) in a subprocess and talk with it through a pipe,
>>    giving it declarations compiled on the fly.
> 
> It can be done this way indeed, although again Camlp4 provides
> another alternative where your preprocessor and the Caml toplevel
> live in the same process.

I don't see how Camlp4 could help. The compiler is not written in
OCaml, it only generates OCaml output.

> Not easily.  You could link with the toplevel and call
> "Toploop.use_silently" to execute code from a file, suppressing
> the output.

I looked closer and realized that it's quite impossible to plug into
toplevellib something other than the default Topmain, although it's
very close to being possible.

For example the Clflags module is not exported (i.e. clflags.cmi
is not installed) so I can't set any options. Initialization is
hardwired into Toploop.loop, but calling Toploop.loop is too much:
it reads from stdin (which must be available to the program so it
can't be /dev/null) and writes to stdout. Initializing by hand is
not possible because the relevant modules are not exported.

I don't want to have to compile a custom OCaml version - it should
work with whatever is installed with OCaml. Unfortunately now it's
impossible.

Another question. Low-level libraries for my language contain many
embedded OCaml snippets written by hand, so they often contain errors.
Is it possible to tell the OCaml compiler about original source
positions for parts of the program, so it reports them in error
messages? I mean like '# line_no "filename"' in cpp. Maybe Camlp4
could help?

Yet another question. OCaml doesn't accept an identifier as the
rhs of let rec (an identifier defined earlier). Why? I had to make
a little workaround to not generate such bindings. I guess it's the
only difference between "what is accepted in let rec" and "what allows
generalization of free type variables"?

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^
QRCZAK

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  parent reply	other threads:[~2001-11-11 21:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-29 15:43 Marcin 'Qrczak' Kowalczyk
2001-11-11 17:38 ` Xavier Leroy
     [not found] ` <9smdf7$511$1@qrnik.zagroda>
2001-11-11 21:54   ` Marcin 'Qrczak' Kowalczyk [this message]
2001-11-11 22:09     ` Patrick M Doane
2001-11-13 20:36     ` Xavier Leroy
     [not found]     ` <9ssfsl$fa4$1@qrnik.zagroda>
2001-11-14  3:03       ` Marcin 'Qrczak' Kowalczyk
2001-11-14  9:52         ` Markus Mottl
2001-11-14 13:20         ` David Mentre
     [not found]         ` <9sttmn$kei$1@qrnik.zagroda>
2001-11-14 14:47           ` Marcin 'Qrczak' Kowalczyk
2001-11-14 16:45             ` Marcin 'Qrczak' Kowalczyk

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=slrn9utssh.cck.qrczak@qrnik.zagroda \
    --to=qrczak@knm.org.pl \
    --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;
as well as URLs for NNTP newsgroup(s).