|
toplevel-input | ::= | { toplevel-phrase } ;; |
toplevel-phrase | ::= | toplevel-definition |
| | expr | |
| | # ident directive-argument | |
toplevel-definition | ::= | let [rec] let-binding { and let-binding } |
| | external value-name : typexpr = external-declaration | |
| | type-definition | |
| | exception-definition | |
| | module module-name [ : module-type ] = module-expr | |
| | module type modtype-name = module-type | |
| | open module-path | |
directive-argument | ::= | nothing |
| | string-literal | |
| | integer-literal | |
| | value-path |
The toplevel system is started by the command ocaml, as follows:Windows:ocaml options objects # interactive mode ocaml options objects scriptfile # script modeoptions are described below. objects are filenames ending in .cmo or .cma; they are loaded into the interpreter immediately after options are set. scriptfile is any file name not ending in .cmo or .cma.
If no scriptfile is given on the command line, the toplevel system enters interactive mode: phrases are read on standard input, results are printed on standard output, errors on standard error. End-of-file on standard input terminates ocaml (see also the #quit directive in section 9.2).
On start-up (before the first phrase is read), if the file .ocamlinit exists in the current directory, its contents are read as a sequence of Objective Caml phrases and executed as per the #use directive described in section 9.2. The evaluation outcode for each phrase are not displayed.
The toplevel system does not perform line editing, but it can easily be used in conjunction with an external line editor such as fep; just run fep -emacs ocaml or fep -vi ocaml. Another option is to use ocaml under Gnu Emacs, which gives the full editing power of Emacs (see the subdirectory emacs of the Objective Caml distribution).
At any point, the parsing, compilation or evaluation of the current phrase can be interrupted by pressing ctrl-C (or, more precisely, by sending the sigintr signal to the ocaml process). The toplevel then immediately returns to the # prompt.
If scriptfile is given on the command-line to ocaml, the toplevel system enters script mode: the contents of the file are read as a sequence of Objective Caml phrases and executed, as per the #use directive (section 9.2). The outcome of the evaluation is not printed. On reaching the end of file, the ocaml command exits immediately. No commands are read from standard input. Sys.argv is transformed, ignoring all Objective Caml parameters, and starting with the script file name in Sys.argv.(0).
In script mode, the first line of the script is ignored if it starts with #!. Thus, it is theoretically possible to make the script itself executable and put as first line #!/usr/local/bin/ocaml, thus calling the toplevel system automatically when the script is run. However, ocaml itself is a #! script on most installations of Objective Caml, and Unix kernels usually do not handle nested #! scripts.
In addition to the text-only command ocaml.exe, which works exactly as under Unix (see above), a graphical user interface for the toplevel is available under the name ocamlwin.exe. It should be launched from the Windows file manager or program manager.
The ``Terminal'' windows is split in two panes. Phrases are entered and edited in the bottom pane. The top pane displays a copy of the input phrases as they are processed by the Objective Caml toplevel, interspersed with the toplevel responses. The ``Return'' key sends the contents of the bottom pane to the Objective Caml toplevel. The ``Enter'' key inserts a newline without sending the contents of the Input window. (This can be configured with the ``Preferences'' menu item.)
The contents of the input window can be edited at all times, with the standard Windows interface. An history of previously entered phrases is maintained and displayed in a separate window.
To quit the Camlwin application, either select ``Quit'' from the ``File'' menu, or use the quit function described below.
At any point, the parsing, compilation or evaluation of the current phrase can be interrupted by selecting the ``Interrupt Objective Caml'' menu item. This goes back to the # prompt.
|
The following environment variables are also consulted:
- LC_CTYPE
- If set to iso_8859_1, accented characters (from the ISO Latin-1 character set) in string and character literals are printed as is; otherwise, they are printed as decimal escape sequences (\ddd).
- TERM
- When printing error messages, the toplevel system attempts to underline visually the location of the error. It consults the TERM variable to determines the type of output terminal and look up its capabilities in the terminal database.
|
|
|
|
ocamlmktop -o mytoplevel foo.cmo bar.cmo gee.cmoThis creates the bytecode file mytoplevel, containing the Objective Caml toplevel system, plus the code from the three .cmo files. This toplevel is directly executable and is started by:
./mytoplevelThis enters a regular toplevel loop, except that the code from foo.cmo, bar.cmo and gee.cmo is already loaded in memory, just as if you had typed:
#load "foo.cmo";; #load "bar.cmo";; #load "gee.cmo";;on entrance to the toplevel. The modules Foo, Bar and Gee are not opened, though; you still have to do
open Foo;;yourself, if this is what you wish.
|