Modula-3 (Modula-3, M3) is a system programming language that is a continuation of the Modula-2 language. Developed at the System Research Center (SRC) of Digital Equipment Corporation (DEC) , in collaboration with Olivetti. Developers: Luca Cardelli, Jim Donahue, Mick Jordan, Bill Kalsow and Greg Nelson. The language is not widely used in industry, although it is used in academic circles. During development, the language was significantly influenced by the Modula-2 + language, which was used at that time in SRC to write software for the DEC Firefly multiprocessor workstation.
| Modula-3 | |
|---|---|
| Semantics | imperative , structural , modular , object oriented , generalized |
| Language class | , and |
| Type of execution | compiled |
| Appeared in | 1986 - 1988 |
| Author | DEC SRC , Olivetti |
| Developer | |
| Type system | strict, static |
| Main implementations | CM3 , PM3 , EzM3 , HM3 |
| Influenced | Algol , Modula-2 , Modula-2 + , Oberon , Pascal |
| Influenced | C # , Java , Ocaml , Python , Nim |
| Website | modula3.org |
The main features of Modula-3 are: simplicity, type safety and the possibility of application for writing system software . Modula-3 supports generalized programming , multitasking , automatic memory management ( garbage collection ), exception handling , object-oriented programming (including hiding data and methods). The language developers aimed to supplement Modula-2 with new means of modern programming languages. At the same time, potentially dangerous and complex tools, such as multiple inheritance and operator overloading , were not included in the language.
Content
- 1 History
- 2 Language features
- 3 Language Properties
- 4 Examples
- 5 Some modules included in the standard library
- 6 Low level programming
- 7 Major implementations
- 8 Notes
- 9 Literature
- 10 Projects Using Modula-3
- 11 Links
History
The development of Modula-3 began in 1986. Maurice Wilkes wrote to Niklaus Virt some ideas for creating a new version of Modula. Wilkes, who had previously worked at DEC, returned to England and settled in the Olivetti Research Center. Wirth at that time was busy developing a new programming language Oberon , but did not refuse to help Wilkes. The description of Modula-3 was completed in August 1988 and amended in January 1989. At the same time, compilers from DEC SRC and Olivetti appeared, as well as third-party compilers.
In the nineties of the XX century, Modula-3 was distributed mainly in the academic environment, as a language for teaching programming, and was hardly used in industry. The reason for this could be the death of DEC, the main language developer. At the same time, Critical Mass Corporation proposed the commercial CM3 compiler and the Reactor IDE. In 2000, Critical Mass ceased operations. Currently, technical support for Modula-3 is provided by Elego Software Solutions GmbH, which inherited CM3 source code from Critical Mass. The Reactor Integrated Environment is now renamed the CM3 IDE and is distributed with the source code. In March 2002, Elego received the source code for the PM3 compiler, previously developed at Ecole Polytechnique de Montreal.
Language Features
Exception handling in blocks TRY ... EXCEPT ... END and TRY ... FINALLY ... END. The EXCEPT construct is implemented similarly to the CASE construct. Modula-3 also supports the LOOP ... EXIT ... END loop.
Implemented support for object-oriented programming. The object type is OBJECT. This type differs from records (RECORD) in that it is a reference, and allows you to create procedures associated with the type (methods), and also supports method overloading. All methods are virtual. For example, the construction:
TYPE A = OBJECT a: INTEGER; METHODS p (): = AP END;
defines an object type containing an integer field a and method p. The AP procedure is an implementation of the p method and has the following form:
PROCEDURE AP (self: A) = BEGIN ... END AP;
The method is called like this: op () ;, where o is a variable (object) of type A.
The REVEAL design provides a simple, but at the same time very powerful mechanism for hiding the details of the implementation of the object from customers.
Modula-3 is one of the few languages that requires program units imported from external modules to be strictly qualified. For example, if module A uses the variable x from module B, the access to this variable should be written in the following form: Bx In other words, Module-3 does not allow importing all objects exported by any module. Due to this, it is almost impossible to disable the program by adding new functionality to it. A large number of users can simultaneously expand the program without fear that this will lead to crashes. Also, Modula-3 sets the difference between a method signature declaration (METHODS block) and its overload (OVERRIDES block).
Language Properties
- Modules consist of an interface (INTERFACE) and a body (MODULE);
- Modules containing unsafe code are marked with the UNSAFE keyword;
- Automatic memory management (garbage collection);
- Strong typing, compound (RECORD) and extensible (OBJECT) types;
- Exception handling;
- Multithreading support;
- Generalizations (GENERIC, an analogue of C ++ templates).
Examples
Hello World! might look like this:
MODULE Main;
IMPORT IO;
BEGIN
IO.Put ("Hello World \ n")
END Main.
or so (the output stream working module is used):
MODULE Hello EXPORTS Main;
IMPORT Wr, Stdio;
BEGIN
Wr.PutText (Stdio.stdout, "Hello, World! \ N");
Wr.Close (Stdio.stdout);
END Hello.
Some modules included in the standard library
Similar to the C language, most of the procedures for writing programs on Module 3 are implemented in the standard library. I / O operations are also implemented in the standard library.
- IO - input-output interface.
- Rd / Wr - interfaces that implement read / write streams, respectively.
- Text - an interface for working with strings (type TEXT).
- Word - procedures for working with unsigned integers.
- Fmt - formatting data of various types for printing.
Also, the standard library includes interfaces for working with floating-point numbers, dictionaries, lists, etc.
Low Level Programming
Modula-3, in addition to links , also supports pointers . The ADDRESS type is an analogue of the void * type in C. A pointer to an integer variable will look like this:
TYPE IntPtr = UNTRACED REF INTEGER;
To get the address of a variable, the built-in ADR () function is used, which is an analog of the & operation in C. It is important to note that the garbage collector does not follow pointers (this is indicated by the word UNTRACED). All pointers must be manually released using the built-in DISPOSE procedure.
Also, Modula-3 supports all data types available in the C language. Due to this, the code on Module 3 can be freely linked with the code in the C language. All type definitions are contained in the Ctypes module.
Major Implementations
Most compilers have Open Source status.
- DEC SRC M3 is the original DEC Modula-3 compiler.
- Critical Mass CM3 is the most developed successor to the DEC SRC M3.
- Polytechnique Montreal Modula-3 PM3 is another successor to the DEC SRC M3 (now merged with CM3).
- EzM3 is a lightweight independent compiler based on PM3. Developed in conjunction with CVSup
- HM3 is the successor to PM3 (version 1.1.15), with support for POSIX Threading (NPTL).
All implementations support a large number of platforms (over 20). Data types are binary compatible with C language types, which allows you to use these two languages together.
Notes
Literature
Some of these books can be found in foreign online stores. Most of them are available free of charge on the Internet.
- Greg Nelson, ed. Systems Programming with Modula-3 The definitive reference on the Modula-3 language with interesting articles on object-oriented systems software construction and a documentation of the discussion leading to the final features of the language.
- Samuel P. Harbison, Modula-3 Easy to use class textbook.
- Robert Sedgewick, Algorithms in Modula-3
- Laszlo Boszormenyi & Carsten Weich, Programming in Modula-3: An Introduction in Programming with Style
- Renzo Orsini, Agostino Cortesi Programmare in Modula-3: introduzione alla programmazione imperativa ea oggetti an italian book of the language explaining its main features.
Projects using Modula-3
- The operating system SPIN ( en ) was written on Module 3. The kernel interfaces are compatible with DEC Unix.
- CVSup is a program for synchronizing repositories, also written in Module 3.
Links
- Modula-3 resource page - resources on the Modula-3 language (English)
- Open CM3 - CM3 Compiler Site
- Elego Software Solutions
- Module 3 newsgroup