From: Florian Angeletti <florian.angeletti@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] a simple example of compiler-libs.toplevel?
Date: Fri, 5 Jun 2026 14:18:41 +0200 [thread overview]
Message-ID: <e9fa4a97-7b7a-4281-9085-354c89bc55d1@inria.fr> (raw)
In-Reply-To: <ad-IewXpM5HagXjC@is.ocha.ac.jp>
To share the answer discussed during the compiler office hours,
I have a very minimal example of a shallow wrapper around
compiler-libs.toplevel (with at least its own toplevel loop) which
replaces the prompt with a "λ" at https://github.com/Octachron/minitop
Note also that the toplevel API is quite awkward and it tends to reflect
what is used by the vanilla toplevel rather than what would be useful in
general for a REPL. There are been remarks on this point from time to
time and I rather agree with them, but I have yet to found the time to
solve those paper cuts.
Le 15/04/2026 à 14:45, Kenichi Asai a écrit :
> Five years ago, I asked a question to this mailing list on how to
> create a copy of the OCaml toplevel using compiler-libs (so that I can
> customize it). I am trying it again. The thread is here:
>
> https://inbox.vuxu.org/caml-list/CANhEzE5tOqq7JXA47tmkQcnF6Bz70eU8jPBT+=+g2EwQ7cNf6Q@mail.gmail.com/T/
>
> What I did is to copy the necessary files from the OCaml source (I am
> working on OCaml 4.14.2.):
>
> topstart.ml, topmain.ml, toploop.ml, topeval.ml, topdirs.ml
> topcommon.ml, trace.ml, genprintval.ml
>
> rename them to my_topstart.ml, my_topmain.ml, etc, rename all the
> module references to the new ones (My_toploop instead of Toploop, etc.)
> and compiled them with compiler-libs. See the toplevel1 directory of:
>
> https://github.com/kenichi-asai/toplevel-experiment
>
> However, when I compile them (by "make"), and execute the binary, I get:
>
> $ ./toplevel
> OCaml version 4.14.2
> Enter #help;; for help.
>
> # let a = 3;;
> Error: Reference to undefined global `Toploop'
> #
>
> Why does this happen?
>
> When I search for "Toploop" in the OCaml source outside the toplevel
> directory, I found lambda/translmod.ml mentions it:
>
> let toploop_ident = Ident.create_persistent "Toploop"
>
> Does this mean the toplevel must be given by the Toploop module
> instead of My_toploop?
>
> As a second attempt, I created the toplevel2 directory of the above
> repository, where I did not rename files to "my_*" but used the
> original names. When I compiled them and execute the binary, I get
> segmentation fault (!):
>
> $ ./toplevel
> OCaml version 4.14.2
> Enter #help;; for help.
>
> # let a = 3;;
> Segmentation fault
> $
>
> What's wrong? How can I create a copy of the OCaml toplevel using
> compiler-libs? Any help appreciated.
>
> Another question. I also want to use dune to compile, instead of
> OCamlMakefile. I provided dune and dune_project files in the
> repository, but when I execute dune build, I obtain the following.
> What am I doing wrong?
>
> $ dune build
> File "dune", line 2, characters 7-18:
> 2 | (name my_topstart)
> ^^^^^^^^^^^
> Undefined symbols for architecture x86_64:
> "_caml_get_current_environment", referenced from:
> _camlDune__exe__My_topmain__fun_2483 in dune__exe__My_topmain.o
> _camlDune__exe__My_topmain__1 in dune__exe__My_topmain.o
> ld: symbol(s) not found for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
> File "caml_startup", line 1:
> Error: Error during linking (exit code 1)
>
> Thank you in advance!
>
prev parent reply other threads:[~2026-06-05 12:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-05 5:05 Kenichi Asai
2021-03-05 9:44 ` Jeremie Dimino
2021-03-05 14:03 ` Kenichi Asai
2021-03-05 17:11 ` Jeremie Dimino
2026-04-15 12:45 ` Kenichi Asai
2026-06-05 12:18 ` Florian Angeletti [this message]
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=e9fa4a97-7b7a-4281-9085-354c89bc55d1@inria.fr \
--to=florian.angeletti@inria.fr \
--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