Date Tags cduce

Nothing deep here …

file toto.ml

let toto = ref ( fun () -> 0 )

file foo.ml

let run ( r : int ) () = r
let register i = Toto.toto := i

file bar.cd. This is the cduce program that is then dynamically loaded.

let f : ( `nil -> Caml_int ) = Foo.run 1 ;;
Foo.register f ;;

file main.ml. Note that we have to dynamically load all the libraries.

let _ =
    Dynlink.init ();
    Dynlink.allow_unsafe_modules true

let () =
    try
        Dynlink.loadfile "/usr/lib/ocaml/3.09.2/stdlib.cma";
        Dynlink.loadfile "/usr/lib/ocaml/3.09.2/nums.cma";
        Dynlink.loadfile "/usr/lib/ocaml/3.09.2/netstring/netstring.cma";
        Dynlink.loadfile "/usr/lib/ocaml/3.09.2/ulex/ulexing.cma";
        Dynlink.loadfile "/usr/lib/ocaml/3.09.2/camlp4/gramlib.cma";
        Dynlink.loadfile "/usr/lib/ocaml/3.09.2/camlp4/odyl.cma";
        Dynlink.loadfile "/usr/lib/ocaml/3.09.2/camlp4/camlp4.cma";
        Dynlink.loadfile "/usr/lib/ocaml/3.09.2/curl/curl.cma";
        Dynlink.loadfile "/usr/lib/ocaml/3.09.2/pxp-engine/pxp_engine.cma";
        Dynlink.loadfile "/usr/lib/ocaml/3.09.2/expat/expat.cma";
        Dynlink.loadfile "/home/users/abate/software/lib/ocaml/cduce/cduce_lib.cma";
        Dynlink.loadfile "foo.cmo";
        Dynlink.loadfile "bar.cmo";
    with Dynlink.Error(e) -> failwith (Dynlink.error_message e)

;;

print_int ( !Toto.toto () )

And to compile everything :

ocamlfind ocamlc -c toto.ml foo.ml
cduce --compile bar.cd
cduce --mlstub bar.cdo > bar.ml
ocamlfind ocamlc -package cduce -linkpkg -c toto.cmo foo.cmo bar.ml
ocamlfind ocamlc -package cduce,dynlink -linkpkg toto.cmo main.ml