4 Running Mozart from the OPI

The OPI allows to run Mozart directly from the OPI. A sub-process is started that executes ozengine with a single root functor argument, by default called OPI.ozf. In particular, {Property.get argv} will always return nil.

Emulator and Compiler

The output of the process is redirected into an Emacs buffer called *Oz Emulator*. For instance, all output done via System.show etc. will appear in this buffer. Additionally, the OPI.ozf program instantiates an Oz compiler and attaches its input and output to an Emacs buffer called *Oz Compiler*; communication, in this case, is done via a socket. The compiler might also create a new buffer for output of source code, called *Oz Temp*.

When we speak of the ``Oz Emulator'' and ``Oz Compiler'' buffers in this manual, we mean the buffers called *Oz Emulator* and *Oz Compiler* respectively.

In order to run the Mozart system, the OPI has to know its installation path. This is normally found through the environment variable OZHOME; it will have been set by the oz shell script if you started the OPI with it. If it is not set, the value of the following variable will be used instead.

OZ-HOME (default: /usr/local/oz1)

Directory where Oz is installed. Only used as fallback when the environment variable OZHOME is not set.

4.1 Running and Halting

The following commands are used to start and halt the Mozart sub-process.

run-oz (C-. r)

Start Mozart as a sub-process if it is not already running. Handle input and output via the Oz Emulator buffer. If the current buffer is not running in an Oz mode, create a new buffer in Oz mode.

oz-change-title (default: nil)

If non-nil, change the Emacs frame's title while a Mozart sub-process is running.

oz-frame-title (default: "Oz Programming Interface (...)")

String to use as Emacs frame title while a Mozart sub-process is running. In the default shown above, the old frame title will be inserted in place of the ellipsis.

oz-halt FORCE (C-. h)

Halt the Mozart sub-process. With no prefix argument, feed an /{Application.exit 0} statement and wait for the process to terminate. Waiting time is limited by the user option oz-halt-timeout; after this delay, the process is sent a SIGHUP if still living.

With C-u as prefix argument, send the process a SIGHUP without delay. With C-u C-u as prefix argument, send it a SIGKILL instead.

oz-halt-timeout (default: 30)

Number of seconds to wait for shutdown in command oz-halt.

4.2 Mozart's Output Buffers

Several commands make inspecting the Oz Emulator and Oz Compiler buffers easier.

oz-toggle-emulator (C-. e)
oz-toggle-compiler (C-. c)
oz-toggle-temp (C-. t)

Toggle visibility of the Oz Emulator, Compiler or Temporary window respectively. If the buffer is not visible in any window, then display it. If it is, then delete the corresponding window.

oz-other-buffer-size (default: 35)

Percentage of screen to use for Oz Compiler, Emulator or Temp window.

4.3 Feeding Code to the Compiler

Feedable Regions

The commands that send regions of the current buffer to the Oz Compiler for compilation come in four flavors:

  • Feeding the whole buffer. More specifically, the region the buffer has been narrowed to is fed.

  • Feeding the currently marked region, i. e., the text contained between point and mark.

  • Feeding the line point is in. If a numeric prefix argument is given, that many lines are fed; if the prefix argument is negative, that many preceding lines as well as the current line are fed.

  • Feeding the paragraph point is in (or after, if it is not inside any paragraph). A paragraph is a region of text delimited by empty lines, i. e., lines not even containing whitespace. If a numeric prefix argument is given, that many paragraphs are fed; if the prefix argument is negative, that many preceding paragraphs as well as the current paragraph are fed.

oz-feed-buffer (C-. C-b)
oz-feed-region START END (C-. C-r)
oz-feed-line COUNT (C-. C-l)
oz-feed-paragraph COUNT (C-. C-p, M-C-x)

The corresponding text region is fed to the compiler and processed with its currently active switches.

oz-show-buffer (C-. s C-b)
oz-show-region START END (C-. s C-r)
oz-show-line COUNT (C-. s C-l)
oz-show-paragraph COUNT (C-. s C-p)

Feed the corresponding text region to the Oz Compiler. Assuming it to contain an expression, enclose it by an application of the procedure Show.

oz-to-coresyntax-region START END
oz-to-coresyntax-line COUNT
oz-to-coresyntax-paragraph COUNT

The corresponding text region is prefixed by

\switch +core -codegen 

and fed to the Oz Compiler. If compilation succeeds, the resulting source file will be displayed in the Oz Temporary buffer.

oz-send-string STRING &optional SYSTEM

Feed STRING to the Oz Compiler, restarting it if it died. If SYSTEM is non-nil, it is a command for the system and is prefixed by

\switch +threadedqueries -verbose -expression -runwithdebugger 

oz-prepend-line (default: t)

If non-nil, prepend a \line directive to all Oz queries, specifying the file name (or buffer name, if there's no associated file) and the line number. This information is used by the compiler to output meaningful error messages and to include debugging information in the generated machine code.

4.4 Running the Command-Line Tools


Compile an Oz program non-interactively.

oz-compile-command (default: "ozc -c %s")

Default shell command to do a compilation. This may contain at most one occurrence of %s, which is replaced by the current buffer's file name. Used by oz-compile-file.


Invoke ozd.

oz-application-command (default: "%s")

Default shell command to do execute an Oz application. This may contain at most one occurrence of %s, which is replaced by the current buffer's file name, minus the .oz or .ozg extension. Used by oz-debug-application.

4.5 Dealing With Errors

Error Messages

An error message is either an error or warning message issued by the Oz Compiler or an exception displayed by the Emulator.

Error Coordinates

Where available, error coordinates are associated with error messages, consisting of the file name (or buffer name) and line number of the corresponding Oz source code.

oz-popup-on-error (default: t)

If non-nil, pop up Compiler resp. Emulator buffer upon an error message.

next-error &optional ARG (C-x `)

Visit next compilation error message and corresponding source code.

A prefix arg specifies how many error messages to move; negative means move back to previous error messages. Just C-u as a prefix means reparse the error message buffer and start at the first error.

This normally uses the most recently started compilation. To specify use of a particular buffer for error messages, type C-x ` in that buffer.

4.6 Seeing the OPI from Mozart


When the OPI.ozf file is applied, a startup file is searched and loaded as follows:

  1. It is first checked whether the environment variable OZRC is set. If it is, its contents is interpreted as a file name that is fed to the OPI compiler.

  2. Else, if the file ~/.oz/ozrc exists and is readable, it is fed to the compiler.

  3. Else, if the file ~/.ozrc exists and is readable, it is fed to the compiler.

Compiler Environment

The environment available when running Mozart from the OPI is an enriched base environment (see ``The Oz Base Environment''). All of Mozarts system modules and tools are available under variables named like the corresponding modules, e. g., the functionality of the open programming component is available as Open. Additionally, the following aliases are introduced:


Long Form

























Compiler Interface

When Mozart is started from the OPI, an instance of the Mozart compiler is created that listens for queries from the interactive development environment. This interaction is handled via a compiler interface called Emacs.interface (see Section 4.4 of ``The Mozart Compiler'').

System Properties

It is possible to test whether Mozart is currently running under the OPI or as a standalone system via the following system property:

{Property.get 'oz.standalone' ?B}

This returns false when Mozart has been started from the OPI. When this is the case, a reference to the compiler interface via which the interaction with the Emacs development environment takes place can be obtained via

{Property.get 'opi.compiler' ?O}

1. This default is actually fixed at the time the Mozart system is configured and built, so it might vary on your system.

Leif Kornstaedt and Denys Duchier
Version 1.4.0 (20080702)