About MPW Oberon

MPW Oberon is an implementation of the Oberon language for the Macintosh Programmer's Workshop (Version 3.0 or later). It consists of several files: MPW Oberon supports the Oberon language defined by N. Wirth at the ETH Zürich. MPW Oberon is based on the compiler described in "Project Oberon" written by N. Wirth and J. Gutknecht. Besides compatibility with Oberon, MPW Oberon supports all features of the Oberon-2 language. Oberon-2 was defined by H. Mössenböck.

MPW Oberon includes the following new features expanding the power and flexibility of Oberon programming:

MPW Oberon currently does not support garbage collection. You must dispose of structures on the heap yourself. A new standard procedure DISPOSE was added to release dynamic variables. See "Predefined routines" for a complete list of standard procedures and functions.
  1. About the Oberon interface files
  2. Using interface files
  3. About the Oberon libraries
  4. About the Oberon examples
  5. Installing MPW Oberon
  6. Creating an application in MPW Oberon
  7. Creating a tool in MPW Oberon
  8. Creating a desk accessory in MPW Oberon
  9. Creating code for different models of the Macintosh

About the Oberon interface files

The MPW Oberon interface files contain declarations for the routines in the MPW Oberon libraries and the MPW 3.x libraries, as well as the User Interface Toolbox and the Operating System routines that are built into the Macintosh ROMs. The Macintosh ROM routines are described in Inside Macintosh. The interface to these routines are divided into files according to their "Manager," as described in Inside Macintosh.

Note: The interface files supplied with MPW Oberon are not the universal interface files needed to develop code for the PowerPC. The universal interface files will be made available with a subsequent release of MPW Oberon.

Using interface files

The interface files for the Oberon and MPW libraries as well as the Macintosh ROMs are in the {OInterfaces} directory. You can determine which interface files to use for a specific routine or data type by finding out which library or Macintosh Manager the routine or data type belongs to. You can also find out the library or Manager name by searching the {OInterfaces} directory for the routine or type name with the MPW Search command.

The compiler searches several directories for interface files, until the specified file is found. It searches the directory containing the source file, directories specified using the -i option to the compiler, and directories specified in the Shell variable {OInterfaces}.

You specify the modules needed for your module by the IMPORT statement:

IMPORT module, module, …;
The compiler assumes that a `module' will be found in the file `module.mod'. This is the file for which it then searches.

Note: Variant records are not supported by Oberon, so the variant record types defined in Inside Macintosh were adapted for MPW Oberon. Each variant is defines in a separate record. Type extension is used to declare the common fields. The data types GrafPort, WindowRecord, and DialogsRecord are also defined using type inheritance where DialogRecord is an extension of WindowRecord which is an extension of GrafPort.

Warning: The replacement of variant records with records defined using type extension creates no problems in many cases. An incompatibility arises when array of variant records are considered. Pascal allocates enough memory for each element to accommodate the largest variant. The same declaration is accepted by Oberon but the compiler does not reserve enough space for each element. Fortunately this construct is not used very often-once-with the interface files supplied with MPW Oberon.

Warning: You may cause system crashes when you are not using the proper variant (extended type) of a parameter block. Most of the routines accept a parameter of type ParmBlkPtr. The following fragment shows an example where a block with the wrong size is passed to PBOpen.

VAR
  block: OSUtils.ParamBlockRec;
…
  error:=PBOpen(SYSTEM.ADR(block), TRUE);
PBOpen expects a pointer parameter block pointing to at least 50 bytes (IOParam). The block passed to PBOpen is not large enough since ParamBlockRec defines only the fields common to all parameter blocks. Check out the interface files for further information.

About the Oberon libraries

The MPW Oberon files include libraries that contain executable code for some auxiliary routines. In addition, libraries include code needed to access the Macintosh ROM routines. Certain libraries are shared by Oberon and other languages; they are in the directory identified by the Shell variable {Libraries}. The library OberonLib.o is specific to Oberon and is contained in the directory {OLibraries}.

Every MPW Oberon program must be linked with the libraries Runtime.o, Interface.o and OberonLib.o. Others are required for different operations. For further information about using the libraries, see the documentation of MPW.

Note: The libraries included with MPW Oberon are not yet final. Some library modules for accessing files within the MPW Shell were implemented using routines from the Pascal library. This will be fixed in a subsequent version of MPW Oberon.

About the Oberon examples

The Oberon files consist of eight sample Oberon programs included with MPW Oberon: an application, a tool, a desk accessory, and a program that demonstrates the use of the performance tools. In addition, the makefiles, containing the commands needed to build each of the examples are provided in the same folders. These files are in {OExamples}. The following table lists these files.
Makefile Makefile for building sample programs.
Instuctions Instructions for build sample programs.
Sample.mod Sample Oberon application. This is the sample application described in "A Simple Example Program" in Chapter 1 of Inside Macintosh, Volume 1. The source code was adapted to be MultiFinder-aware.
TESample.mod Simple MultiFinder-aware TextEdit application
SillyBalls.mod Simple Color Quickdraw sample application
TubeTest.mod Simple Color Quickdraw and Palette Manager application
ResEqual.mod Sample MPW Tool
Memory.mod Sample desk accessory. The Memory desk accessory display the current free space in the application and system heaps, the free space on the default volume, and the name of the default volume. This information is updated every 5 seconds. When Memory is first opened, it calls _MaxMem to purge memory, thus showing the upper bounds on free space in both heaps.
EditCdev.mod Sample Control Panel device with a TextEdit item
TestPerf.mod Sample program using the Performance Measurement tools
The file Instructions contains step-by-step instruction for building each of the sample programs. To build the sample programs, open this file and follow the instructions. All these sample programs were originally written in MPW Pascal by Apple Computer.

In addition to the samples describes above showing standard Macintosh programming, eleven sample programs are included with MPW Oberon written in Oberon, Pascal, and C. These programs are contained in the folder JMLCSamples and were used to compare the code generation of MPW Oberon with MPW Pascal and MPW C. The results of this comparison were presented at the Joint Modular Languages Conference 1994 in Ulm. The following table lists the targets of the Makefile which may be used for producing reports.

CSizeReport size of compiled programs
CSpeedReport compilation times
ESpeedReport execution times
Report Create a complete report showing size of compiled code and source text, compilation time, and execution time
SLinesReport number of source lines
All reports produced by the Makefile are written to standard output. Times are in milliseconds. The size of the programs is the size of code modules produced by the compilers in bytes.

Note: The first generation of a report may take a while since all programs must be build.

Most of the examples in the test suite above were adapted from textbooks. For "standardized" testing the folder Hennessy contains the standard Hennessy benchmark suite. This suite is provided in Oberon, Pascal and C. You will notice that MPW Oberon performs equally well in both test suites.

Installing MPW Oberon

MPW Oberon may be installed by copying the Oberon files to the proper places. Install MPW Oberon with these steps:
  1. Copy Oberon (the compiler) to the {MPW}Tools folder.
  2. Copy UserStartup•Oberon to the {MPW} folder.
  3. Copy the folder OExamples to the {MPW}Examples folder.
  4. Copy the folder OInterfaces to the {MPW}Interfaces folder.
  5. Copy the folder OLibraries to the {MPW}Libraries folder.
  6. Append the file Oberon.Help to the {MPW}MPW.Help file.
Note: You can put the compiler, examples, and libraries in different directories, provided you change the default values of various Shell variables defined in Startup and UserStartup•Oberon files. The following variables determine the locations of files supplied with MPW Oberon.
{Commands} A comma-separated list of directories containing tools and applications. The directory containing the Oberon compiler should appear in that list.
{OInterfaces} A comma-separated list of directories to search for Oberon interface files. This should include the OInterfaces directory.
{OLibraries} The directory containing OLibraries files. This should be the pathname of the OLibraries directory.

Creating an application in MPW Oberon

An application is a program that can be run under the Macintosh Finder. The code for an application is contained in 'CODE' resources in its resource fork. Additional resources describe menus, windows, dialogs, and other resources used by the application. See Inside Macintosh: Overview for a detailed explanation how to write Macintosh applications.

This section outlines the steps for building an application in MPW Oberon. The Instructions files in the OExamples folder describe some of the tools that can be used to automate to processes. The Makefile file in the OExamples folder illustrates the use of some of the tools. See the MPW documentation for further details about these tools.

Building an application

The easiest way to build any program in MPW is to use the Build menu. To build Sample, an application in the OExamples folder, set the directory to the OExamples folder using the Directory menu. Select Build from the Build menu and type the name of the program to build: Sample.

You will see something like this on the screen:

# 10:22:49 Uhr ----- Build of Sample.
# 10:22:49 Uhr ----- Analyzing dependencies.
# 10:22:51 Uhr ----- Executing build commands.
    Oberon Sample.mod -o Sample.mod.o
    Link -o Sample Sample.mod.o ∂
        "Yogi:Libraries:Libraries:"Runtime.o∂
        "Yogi:Libraries:Libraries:"Interface.o ∂
        "Yogi:Libraries:OLibraries:"OberonLib.o
    SetFile Sample -t APPL -c 'MOOS' -a B
    Rez -rd -o Sample Sample.r -append
# 10:23:03 Uhr ----- Done.
    Sample 
The Build command compiles and links the applications. For details to compile and link the application independently, see the sections "Compiling an application" and "Linking an application" below.

Compiling an application

To compile a Oberon module, first start the MPW Shell application, then enter the Oberon command in any windows. Typically, the command specifies options and the name of the source file to the compiler. The name of the source file is required but the options are not required. For example, the command
Oberon -p Sample.mod
Compiles the source file Sample.mod, producing the object file Sample.mod.o. The -p option specifies that progress information should be written to diagnostic output. This information appears after the command line.

Linking an application

The linker is used to combine object files from different modules, together with any libraries, to produce executable code resources for a program. An application written partly or totally in Oberon for use on any Macintosh equipped with a MC68020 or better should be linked with the following libraries:
{Libraries}Interfaces.o
{Libraries}Runtime.o
{OLibraries}OberonLib.o
In Oberon there is no main program. Use the $MAIN directive to declare the initialization part of a specific module as the program's main entry point. Only one module may be declared as the main module. Otherwise the linker will report an error.

Creating a tool in MPW Oberon

A tool is a program that operates within the MPW Shell environment. The Oberon compiler, Rez, and Link are all tools. This section contains specific information about writing tools in Oberon. For further details refer to the MPW documentation.

Tools are executed by entering an MPW command. The parameter specified in the command line are passed as parameters to the main program. The exported Shell variables can be accessed using the procedure IntEnv.getenv from the Oberon library. To access these parameters use the IntEnv module.

Tools have direct access to MPW Shell windows and selections. The variables stdin, stdout and stderr refer to MPW' standard input, standard output, and diagnostic output. Any files opened by tools read and write to windows, if the file specified is open in a window. The contents of the window are read or written in place of the file's data fork. Selection in windows can also be read and written as if they were files by the adding the suffix .§ to the filename.

Compiling a tool

You compile a tool in exactly the same way as you compile an application. All information regarding import-file search rules, segmentation, and resources applies equally.

Linking a tool

The MPW Shell recognizes a tool by its type and creator. Specify the following options when linking a tool:
Link -t MPST -c "MPS " …
The command specified the file type and creator of an MPW tool. Follow the same library linking rules for tools as for applications. In addition, if your tool call any of the spinning cursor or error manager routines, link with the following libraries:
{Libraries}Stubs.o
{Libraries}ToolLibs.o
The file Stubs.o contains a collection of "stubs", or dummy routines, that are defined in the run-time library but unnecessary for MPW tools running under the MPW Shell.

Creating a desk accessory in MPW Oberon

A desk accessory is a program that you can run by selecting it from the Apple menu. This section contains information specific to writing desk accessories. See the chapter "Device Manager" in Inside Macintosh: Devices and MPW documentation for further information.

ΔΔElaborateΔΔ

Creating code for different models of the Macintosh

Using MPW Oberon, you can create applications running on all models of the Macintosh. This section outlines the compatibilities among the machines and the strategies for writing and compiling code running on the different models.

Note: Programs written in MPW Oberon will execute on the PowerPC. The PowerPC models will emulate an MC68LC040 processor. Floating-point operations must be performed using the SANE because FPU instructions are not emulated. Do not use the -mc68881 option when writing programs using floating-point that should execute in the PowerPC environment.

Interface files

A set of interface files provided with MPW Oberon gives you access from Oberon to the Macintosh Toolbox and Macintosh Operating System routines built into the Macintosh ROMs. These routines are documented in Inside Macintosh.

Many routines described in Inside Macintosh are not available on certain models of the Macintosh, because they make use of hardware options that are not available on other models. You can import all of the interface-file definitions in code for use on any model, but you cannot call ROM routines that are not present on the machine that will the compiled code.

Compiler options

The code produced by MPW Oberon will execute only on models of the Macintosh equipped with a MC68020 or better. All machines not equipped with such a processor will not be able to execute code produced by MPW Oberon. To ensure compatibility with as many models as possible you should rely on the SANE package for floating-point operations, because not all models of the Macintosh are equipped with a FPU.

Use the -mc68881 option for programs which do a lot of computation involving floating-point numbers. If this option is given to the compiler, it will not generate call to the SANE package but generate opcodes of the MC68881. A large number of transcendental functions is provided by the FPU which can be used with MPW Oberon. See "Arithmetic procedures and functions" for a list of arithmetic functions provided by MPW Oberon.

Note: Some transcendental functions implemented in the SANE package are slightly more accurate that their counterparts provided by the FPU. MPW Oberon is designed for maximum speed, so it will generate direct call for the FPU.

Warning: The type LONGREAL occupies 10 bytes if code for SANE is generated and 12 bytes if code for the MC68881 is generated. Keep this in mind if you want to read files containing binary floating-point numbers.


Previous Section, Next Section, Contents
Jürgen Geßwein; 2. Juni 1995