Modula-2
From Wikipedia, the free encyclopedia
|
|
This article does not cite any references or sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (June 2009) |
|
|
This article's external links may not follow Wikipedia's content policies or guidelines. Please improve this article by removing excessive or inappropriate external links. (June 2009) |
| Paradigm | imperative, structured, modular, data and method hiding |
|---|---|
| Appeared in | 1978 |
| Designed by | Niklaus Wirth |
| Typing discipline | strong, static |
| Major implementations | ETH Zurich (originally written by Niklaus Wirth), Gardens Point, p1, Native XDS-x86, gm2 (GNU Modula-2) |
| Dialects | PIM2, PIM3, PIM4, ISO |
| Influenced by | Pascal, Mesa, ALGOL, Simula-67 |
| Influenced | Modula-3, Oberon, Ada, Fortran 90, Lua, Zonnon, Modula-GM |
Modula-2 is a computer programming language invented by Niklaus Wirth at ETH, around 1978, as a successor to his intermediate language Modula. Modula-2 was implemented in 1980 for the Lilith computer, which was commercialized in 1982 by startup company DISER (Data Image Sound Processor and Emitter Receiver System) as MC1 and MC2. DISER sold 120 units worldwide. The Modula-2 language was understood by Niklaus Wirth as a successor to his programming language Pascal. The language design was also influenced by the Mesa programming language and the new programming possibilities of the early personal computer Xerox Alto, both from Xerox, that Wirth saw during his 1976 sabbatical year at Xerox PARC[1].
Contents |
[edit] Description
Modula-2 is a general purpose procedural language, sufficiently flexible to do systems programming, but with much broader application. In particular, it was designed to support separate compilation and data abstraction in a straightforward way. Much of the syntax is based on Wirth's earlier and better-known language, Pascal. Modula-2 was designed to be broadly similar to Pascal, with some elements and syntactic ambiguities removed and the important addition of the module concept, and direct language support for multiprogramming.
The Modula-2 module may be used to encapsulate a set of related subprograms and data structures, and restrict their visibility from other portions of the program. The module design implemented the data abstraction feature of Modula-2 in a very clean way. Modula-2 programs are composed of modules, each of which is made up of two parts: a definition module, the interface portion, which contains only those parts of the subsystem that are exported (visible to other modules), and an implementation module, which contains the working code that is internal to the module.
The language has strict scope control. In particular the scope of a module can be considered as an impenetrable wall: Except for standard identifiers no object from the outer world is visible inside a module unless explicitly imported; no internal module object is visible from the outside unless explicitly exported.
Suppose module M1 exports objects a, b, c, and P by enumerating its identifiers in an explicit export list
DEFINITION MODULE M1; EXPORT QUALIFIED a, b, c, P; ...
Then the objects a, b,c, and P from module M1 become now known outside module M1 as M1.a, M1.b, M1.c, and M1.P. They are exported in a qualified manner to the universe (assumed module M1 is global). The exporting module's name, i.e. M1, is used as a qualifier followed by the object's name.
Suppose module M2 contains the following IMPORT declaration
MODULE M2; IMPORT M1; ...
Then this means that the objects exported by module M1 to the universe of its enclosing program can now be used inside module M2. They are referenced in a qualified manner like this: M1.a, M1.b, M1.c, and M1.P. Example:
... M1.a := 0; M1.c := M1.P (M1.a + M1.b); ...
Qualified export avoids name clashes: For instance, if another module M3 would also export an object called P, then we can still distinguish the two objects, since M1.P differs from M3.P. Thanks to the qualified export it does not matter that both objects are called P inside their exporting modules M1 and M3.
There is an alternative technique available, which is in wide use by Modula-2 programmers. Suppose module M4 is formulated as this
MODULE M4; FROM M1 IMPORT a, b, c, P;
Then this means that objects exported by module M1 to the universe can again be used inside module M4, but now by mere references to the exported identifiers in an "unqualified" manner like this: a, b, c, and P. Example:
... a := 0; c := P (a + b); ...
This technique of unqualifying import allows use of variables and other objects outside their exporting module in exactly the same simple, i.e. unqualified, manner as inside the exporting module. The walls surrounding all modules have now become irrelevant for all those objects for which this has been explicitly allowed. Of course unqualifying import is only usable if there are no name clashes.
These export and import rules may seem unnecessarily restrictive and verbose. But they do not only safeguard objects against unwanted access, but also have the pleasant side-effect of providing automatic cross-referencing of the definition of every identifier in a program: if the identifier is qualified by a module name, then the definition comes from that module. Otherwise if it occurs unqualified, simply search backwards, and you will either encounter a declaration of that identifier, or its occurrence in an IMPORT statement which names the module it comes from. This property becomes very useful when trying to understand large programs containing many modules.
The language provides for (limited) single-processor concurrency (monitors, coroutines and explicit transfer of control) and for hardware access (absolute addresses, bit manipulation, and interrupts). It uses name equivalence.
[edit] Dialects
There are two major dialects of Modula-2. The first is PIM, named after the book "Programming in Modula-2" by Niklaus Wirth. There were three major editions of PIM, the second, third (corrected) and fourth editions, each describing slight variants of the language. The second major dialect is ISO, from the standardization effort by the International Organization for Standardization.
- PIM2 (1983)
- Required explicit EXPORT clause in definition modules.
- PIM3 (1985)
- Removed the EXPORT clause from definition modules following the observation that everything within a definition module defines the interface to that module, hence the EXPORT clause was redundant.
- PIM4 (1989)
- Specified the behaviour of the MOD operator when the operands are negative.
- ISO (1996)
- ISO Modula-2 resolved most of the ambiguities in PIM Modula-2. It added the data types COMPLEX and LONGCOMPLEX, exceptions, module termination (FINALLY clause) and a complete standard I/O library. There are numerous minor differences and clarifications.
[edit] Language elements
[edit] Reserved words
PIM [2,3,4] defines the following 40 reserved words:
AND ELSIF LOOP REPEAT ARRAY END MOD RETURN BEGIN EXIT MODULE SET BY EXPORT NOT THEN CASE FOR OF TO CONST FROM OR TYPE DEFINITION IF POINTER UNTIL DIV IMPLEMENTATION PROCEDURE VAR DO IMPORT QUALIFIED WHILE ELSE IN RECORD WITH
[edit] Pervasive Identifiers
PIM [3,4] defines the following 29 pervasive (built-in) identifiers:
ABS EXCL LONGINT REAL BITSET FALSE LONGREAL SIZE BOOLEAN FLOAT MAX TRUE CAP HALT MIN TRUNC CARDINAL HIGH NIL VAL CHAR INC ODD CHR INCL ORD DEC INTEGER PROC
[edit] Related languages
Although Modula-2 is by far the best-known and most widely used variant, there are several languages which are related in one way or another. These fall into three categories: ancestors of Modula-2, languages that are supersets of Modula-2 adding language extensions for specific application domains, and derivative languages which resemble Modula-2 very closely but are new languages in their own right. These should not be regarded as "better versions" or "replacements" for Modula-2; most are different languages with different purposes, and with strengths and weaknesses of their own.
[edit] Modula-2 Ancestors
The immediate ancestor of Modula-2 is the original, and quite different, Modula, developed by Wirth for systems implementation. Another ancestor is Mesa, developed at Xerox PARC where Wirth had spent a sabbatical in 1976. Earlier ancestors are Pascal and Algol-W.
[edit] Modula-2 Supersets
There are several supersets of Modula-2 with language extensions for specific application domains: Modula-2+, Modula-2* (parallel extension), ISO Modula-2's OO and generic extensions, Objective Modula-2 (extended with Smalltalk-like object oriented constructs, similar to how Objective C extends C), Modula-Prolog (adding a Prolog layer) and Modula/R (with relational database extensions), Modula-GM and Mod51 (both for embedded systems).
[edit] Modula-2 Derivatives
Modula-2 was developed as the system language for the Lilith workstation, and formed the ancestor for the Oberon language and workstation project (System Oberon) developed at ETH Zürich. The most well known derivatives of Modula-2 are Modula-3 (by ex-Xerox employees who moved to DEC and Olivetti; adding garbage collection, objects, and generics, as in Cedar), Oberon (another, later, Wirth design), Oberon-2 (Oberon with OO extensions). Some others are Umbriel and YAFL. Many other, current programming languages have adopted features of Modula-2.
[edit] Modula-2 in Embedded Systems
[edit] Modula-GM
Delco Electronics, then a subsidiary of GM Hughes Electronics, developed a version of Modula-2 for embedded control systems starting in 1985. Delco named it Modula-GM. It was the first high level language used to replace machine language code for embedded systems in Delco's engine control units (ECUs). This was significant because Delco was producing over 28,000 ECUs per day in 1988 for GM; this was then the world's largest producer of ECUs[2]. The first experimental use of Modula-GM in an embedded controller was in the 1993 Gen-4 ECU used by the CART (Championship Auto Racing Teams) and IRL (Indy Racing League) teams[3]. The first production use of Modula-GM was its use in GM trucks starting with the 1990 model year VCM (Vehicle Control Module) used to manage GM Powertrain's Vortec engines. Modula-GM was also used on all ECUs for GM's 90° Buick V6 family 3800 Series II used in the 1997-2005 model year Buick Park Avenue. The Modula-GM compilers and associated software management tools were sourced by Delco from Intermetrics.
Modula-2 was selected as the basis for Delco's high level language because of its many strengths over other alternative language choices in 1986. After Delco Electronics was spun off from GM (with other component divisions) to form Delphi in 1997, global sourcing required that a non proprietary high level software language be used. ECU embedded software now developed at Delphi use commercial C compilers.
[edit] Current compilers
- ACK Modula-2 for Minix 2.0 (freeware)
- Aglet Modula-2 for Amiga OS 4.0/PPC (freeware)
- Cambridge Modula-2 for various micro-controllers and embedded MINOS operating system (commercial + proprietary software)
- Canterbury Modula-2 generates Java source code
- DEC Modula-2 for BSD and Ultrix, both VAX and MIPS (freeware)
- FST Fitted Software Tools Modula-2 for MS-DOS (freeware)
- Gardens Point Modula-2 for BSD, Linux, OS/2, Solaris and .NET - ISO compliant (freeware)
- GNU Modula-2 compiler for GCC platforms, work in progress but already generates code, PIM compliant (free software, GPLed)
- M2Amiga for Amiga (free software)
- M2M by N. Wirth and collaborators from ETH Zurich, platform independent, generates M-code for virtual machine (freeware)
- MacMETH by N. Wirth and collaborators from ETH Zurich for Macintosh, but Classic only (freeware)
- Mod51 for the Intel 80x51 micro-controller family (commercial + proprietary)
- ModulaWare for OpenVMS, both VAX and Alpha, ISO compliant (commercial + proprietary)
- MTC Modula-2 to C translator, available in Modula-2 and C source (free software)
- Native XDS-x86 for Windows and Linux, ISO compliant Modula-2 and Oberon-2 native compilers with optional TopSpeed Compatibility Pack (freeware)
- Objective Modula-2 compiler, cross-platform - outputs Objective-C (available for peer review and testing purposes only)
- p1 Modula-2 for Macintosh, both Classic and Mac OS X but only supported API is Carbon, ISO compliant (commercial + proprietary)
- The Karlsruhe Modula-2 Compiler MOCKA for various platforms, PIM compliant (commercial, freeware Linux/BSD versions)
- TERRA M2VMS for OpenVMS, both VAX and Alpha, PIM compliant (commercial + proprietary)
- The Ulm Modula-2 System for Solaris, both SPARC and MC68K (free software, GPLed)
- XDS-C hosted on Windows and Linux, generates ANSI or K&R C source thus targeting most 16- and 32-bit platforms, ISO compliant Modula-2 and Oberon-2 with optional TopSpeed Compatibility Pack (freeware)
[edit] Discontinued compilers
- Benchmark Modula-2 for the Amiga
- Borland Turbo Modula-2 for CP/M
- Borland Turbo Modula-2 for MS-DOS (sold to Jensen and Partners, became TopSpeed Modula-2)
- epc Modula-2 (from former Edinburgh Portable Compilers Limited; company no longer exists, is now a division of Analog Devices)
- FTL Modula-2 (v1.15 1986) for MS-DOS, ATARI ST and CP/M Z80 by Dave Moore, Cerenkof Computing. Distributed in Australia by JED Microprocessors Pty Ltd.
- Logitech had a series of Modula-2 compilers for CP/M and MS-DOS.
- M2F for Linux, predecessor to GNU Modula-2, generates i386 code, follows PIM2 (GPled)
- M2S for the Amiga
- M2SDS (IBM PC), Interface Technologies Inc. (ITC) Houston, TX.
- Megamax Modula-2 for Atari ST & TT computers. German language only. Documentation and source code is now available for free. Much of it is written in 68k assembler code.
- Metrowerks' first products were Modula-2 compilers for various platforms, including the Macintosh
- Mill Hill & Canterbury Native OS/2 Compiler (demo here)
- Modula Corporation had a series of Modula-2 compilers for MS-DOS (M2M-PC), the Apple II and the Macintosh
- Modula-2 PC (IBM PC), PCollier Systems, Tucson, AZ.
- Mosys Modula-2 System for Sage / Stride 68000 computers. Brian Kirk, Robinson Systems Ltd. UK
- Stony Brook Modula-2
- TDI Modula-2 for the Amiga and Atari ST
- TopSpeed Modula-2 (MS-DOS and OS/2). Jensen and Partners International (JPI). Now included in Clarion owned by SoftVelocity
- Waterloo Modula-2 (IBM 370 VM/SP CMS). WATCOM Products Inc.
- Volition Systems Modula-2 (UCSD p-System). Randy Bush, Richard Gleaves, Volition Systems Del Mar, CA.
[edit] Books
- Niklaus Wirth, Programming in Modula-2, Fourth Edition, 1989, ISBN 0-387-50150-9
- K. N. King, Modula-2, a comprehensive and clearly written text, continuously in print for now about two decades, ISBN 0-669-11091-4
- Richard J. Sutcliffe, "Modula-2: Abstractions for Data and Programming Structures," (Using ISO-Standard Modula-2) 2004-2005 Edition
[edit] References
- ^ N.Wirth, Programming in Modula-2, fourth Edition, page 4.
- ^ Delco Electronics Electron Magazine, The Atwood Legacy, Spring '89, page 25
- ^ Development of Electronics for GM Auto Racing
[edit] External links
- Modula-2 Internet directory
- The Modula-2 website ring
- Modula-2 FAQ by Rick Sutcliffe
- List of Modula-2 compilers
- Lilith and Modula-2
- Free Modula-2 Pages News Portal
- Sources Store for Modula-2 and Oberon-2
This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.