SoftTimur
SoftTimur

Reputation: 5540

Unimplemented Javascript primitive caml_pure_js_expr

I want to write and compile cubes.ml such that 1) it wraps an OCaml function to make a JS function that can be called in web; 2) the OCaml function and the bytecode can still be tested in a command line under Linux.

cubes.ml is as follows:

let () =
  let oneArgument (a: int) = a + 100 in
  Js.Unsafe.global##.jsOneArgument := Js.wrap_callback oneArgument;
  print_string "hello\n";
  exit 0

The following 2 commands generate a bytecode T, and translates T to cubes.js:

ocamlfind ocamlc -package js_of_ocaml.ppx -linkpkg cubes.ml -o T

js_of_ocaml T -o cubes.js

I have tested that the function jsOneArgument of cubes.js can well be called by other JS or HTML files. So my 1) goal is satisfied.

However, my 2) goal cannot be satisfied: ./T returns an error:

:testweb $ ./T
Unimplemented Javascript primitive caml_pure_js_expr!

Although node cubes.js returns hello, I do need to be able to test ./T directly, because when there is an error, it would show well the error position, whereas the information shown by node cubes.js is not readable...

So does anyone know how to solve that?

PS: node --version gives v6.1.0; npm --version gives 3.8.6; ocaml -version gives The OCaml toplevel, version 4.02.3. js_of_ocaml --version gives 2.7.

Upvotes: 2

Views: 987

Answers (1)

Pierre Boutillier
Pierre Boutillier

Reputation: 276

I don't see anyway to avoid the use of node but you can improve the information returned by it by

  1. compiling the OCaml with the debug info (add -g option to ocamlc)

  2. add the options --debuginfo --sourcemap --pretty to the invocation of js_of_ocaml

In your example, you'd have to do

ocamlfind ocamlc -g -package js_of_ocaml.ppx -linkpkg cubes.ml -o T
js_of_ocaml --debuginfo --sourcemap --pretty T -o cubes.js

Upvotes: 4

Related Questions