File: main.ml

package info (click to toggle)
ocaml 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 44,372 kB
  • sloc: ml: 370,196; ansic: 52,820; sh: 27,419; asm: 5,462; makefile: 3,684; python: 974; awk: 278; javascript: 273; perl: 59; fortran: 21; cs: 9
file content (88 lines) | stat: -rw-r--r-- 2,411 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(* TEST
 include dynlink;
 ld_library_path += "${test_build_directory}";
 readonly_files = "plug1.ml plug2.ml registry.ml stub1.c stub2.c";
 shared-libraries;
 setup-ocamlc.byte-build-env;
 compile_only = "true";
 all_modules = "registry.ml stub1.c stub2.c plug1.ml plug2.ml main.ml";
 ocamlc.byte;
 program = "plug1";
 modules = "stub1.${objext}";
 ocamlmklib;
 program = "plug2";
 modules = "stub2.${objext}";
 ocamlmklib;
 program = "plug1";
 modules = "plug1.cmo";
 ocamlmklib;
 program = "plug2";
 modules = "plug2.cmo";
 compile_only = "false";
 ocamlmklib;
 {
   program = "${test_build_directory}/main.exe";
   all_modules = "registry.cmo main.cmo";
   ocamlc.byte;
   arguments = "plug1.cma plug2.cma";
   output = "main.output";
   run;
   check-program-output;
 }{
   program = "${test_build_directory}/static.exe";
   flags = "-linkall";
   all_modules = "registry.cmo plug1.cma plug2.cma";
   ocamlc.byte;
   output = "static.output";
   run;
   reference = "${test_source_directory}/static.reference";
   check-program-output;
 }{
   program = "${test_build_directory}/custom.exe";
   flags = "-custom -linkall -I .";
   all_modules = "registry.cmo plug2.cma plug1.cma";
   use_runtime = "false";
   ocamlc.byte;
   output = "custom.output";
   run;
   reference = "${test_source_directory}/custom.reference";
   check-program-output;
 }
*)

let f x = print_string "This is Main.f\n"; x

let () = Registry.register f

let _ =
  Dynlink.allow_unsafe_modules true;
  for i = 1 to Array.length Sys.argv - 1 do
    let name = Sys.argv.(i) in
    Printf.printf "Loading %s\n" name; flush stdout;
    try
      if name.[0] = '-'
      then Dynlink.loadfile_private
        (String.sub name 1 (String.length name - 1))
      else Dynlink.loadfile name
    with
      | Dynlink.Error err ->
          Printf.printf "Dynlink error: %s\n"
            (Dynlink.error_message err)
      | exn ->
          Printf.printf "Error: %s\n" (Printexc.to_string exn)
  done;
  flush stdout;
  try
    let oc = open_out_bin "marshal.data" in
    Marshal.to_channel oc (Registry.get_functions()) [Marshal.Closures];
    close_out oc;
    let ic = open_in_bin "marshal.data" in
    let l = (Marshal.from_channel ic : (int -> int) list) in
    close_in ic;
    List.iter
      (fun f ->
        let res = f 0 in
        Printf.printf "Result is: %d\n" res)
      l
  with Failure s ->
    Printf.printf "Failure: %s\n" s