package archimedes

  1. Overview
  2. Docs

Source file archimedes_toploop.ml

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
(* File: archimedes_toplevel.ml

   Copyright (C) 2009

   Christophe Troestler <Christophe.Troestler@umons.ac.be>
   WWW: http://math.umons.ac.be/an/software/

   This library is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License version 3 or
   later as published by the Free Software Foundation, with the special
   exception on linking described in the file LICENSE.

   This library is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the file
   LICENSE for more details. *)

(** When working in the toplevel, it is convenient to have a
    simplified interface so one can plot without having to declare any
    handle.  The usual Archimedes functions will remain available in
    case several concurrent plots are needed. *)

(* One must pass the usual Backend registration mechanism of Backend
   in the toplevel because, for example, loading graphics in this way
   raises: Assert_failure ("bytecomp/dll.ml", 109, 4).

   We use the toplevel mechanism to load the modules. *)

open Printf

let modules = [ "graphics.cma";
                (* "dynlink.cma";*) (* already loaded by META *)
                "archimedes.cma";
                "archimedes_graphics.cma";
              ]

let eval_string
    ?(print_outcome = false) ?(err_formatter = Format.err_formatter) str =
  let lexbuf = Lexing.from_string str in
  let phrase = !Toploop.parse_toplevel_phrase lexbuf in
  Toploop.execute_phrase print_outcome err_formatter phrase

let rec load_modules = function
  | [] -> true
  | cma :: tl ->
      eval_string(sprintf "#load %S;;" cma) && load_modules tl

let () =
  if load_modules modules then (
    if eval_string "module A = Archimedes;;" then
      Format.eprintf "Module Archimedes loaded and aliased as A.@."
    else
      Format.eprintf "Problem aliasing the Archimedes module!@."
  )
  else
    Format.eprintf "Problem loading Archimedes module.@."
OCaml

Innovation. Community. Security.