Quantcast
Channel: OCaml - Topics tagged dune
Viewing all articles
Browse latest Browse all 521

How can I Toploop inside a script?

$
0
0

Hello Folks, I hope everyone is doing good =]

I’m very new Ocaml and I’m having trouble trying to use Toploop from the compiler-libs in a script, maybe someone here could help.

Even tho I’m providing the my dune config with (libraries compiler-libs) I still get this error when trying to call Toploop functions: Error: No implementations provided for the following modules: Toploop referenced from bin/.main.

Using the same switch env I’m able to use the Toploop functions inside utop by using #require compiler-libs so the library exists in my env, dune just doesn’t seem be able to find it or something like this.

In case this helps, this is the function I’m trying to achieve, jus simply evaluating code as a string:

let eval code =
  let as_buf = Lexing.from_string code in
  let parsed = !Toploop.parse_toplevel_phrase as_buf in
  ignore (Toploop.execute_phrase true Format.std_formatter parsed)

– Update

I was able to make some changes that made possible to run the dune build step successfully, by changing the libraries on dune config to use compiler-libs.toplevel (as was recommended on the thread) and by adding (modes byte) to the dune config. But then now I got the this error while running dune exec: Fatal error: exception Env.Error(_)

4 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 521

Trending Articles