Modula-2
Encyclopedia
Modula-2 is a computer programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 designed and developed between 1977 and 1980 by Niklaus Wirth
Niklaus Wirth
Niklaus Emil Wirth is a Swiss computer scientist, best known for designing several programming languages, including Pascal, and for pioneering several classic topics in software engineering. In 1984 he won the Turing Award for developing a sequence of innovative computer languages.-Biography:Wirth...

 at ETH
Eth
Eth is a letter used in Old English, Icelandic, Faroese , and Elfdalian. It was also used in Scandinavia during the Middle Ages, but was subsequently replaced with dh and later d. The capital eth resembles a D with a line through the vertical stroke...

 Zurich as a revision of Pascal
Pascal (programming language)
Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...

 to serve as the sole programming language for the operating system and application software for the personal workstation Lilith
Lilith (computer)
Lilith is the name of custom built workstation using the AMD 2901 bit-slice processor by the group of Niklaus Wirth at ETH Zürich. The project started in 1977 and by 1984 several hundred workstations were in use. It had a high resolution full page display, a mouse, a laser printer interface, and a...

. The principal concepts were:
  • The module as a compilation unit for separate compilation
  • The coroutine as the basic building block for concurrent processes
  • Types and procedures that allow access to machine-specific data.


Modula-2 was understood by Niklaus Wirth
Niklaus Wirth
Niklaus Emil Wirth is a Swiss computer scientist, best known for designing several programming languages, including Pascal, and for pioneering several classic topics in software engineering. In 1984 he won the Turing Award for developing a sequence of innovative computer languages.-Biography:Wirth...

 as a successor to his earlier programming language Pascal
Pascal (programming language)
Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...

. The language design was also influenced by the Mesa programming language
Mesa programming language
Mesa was an innovative programming language developed in the late 1970s at the Xerox Palo Alto Research Center in Palo Alto, California, United States. The language was named after the mesas of the American Southwest, referring to its design intent to be a "high-level" programming language.Mesa is...

 and the new programming possibilities of the early personal computer Xerox Alto
Xerox Alto
The Xerox Alto was one of the first computers designed for individual use , making it arguably what is now called a personal computer. It was developed at Xerox PARC in 1973...

, both from Xerox, that Wirth saw during his 1976 sabbatical year
Sabbatical year
Sabbatical or a sabbatical is a rest from work, or a hiatus, often lasting from two months to a year. The concept of sabbatical has a source in shmita, described several places in the Bible...

 at Xerox PARC
Xerox PARC
PARC , formerly Xerox PARC, is a research and co-development company in Palo Alto, California, with a distinguished reputation for its contributions to information technology and hardware systems....

.

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
Pascal (programming language)
Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object 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
Multiprogramming
Computer multiprogramming is the allocation of a computer system and its resources to more than one concurrent application, job or user ....

.

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
Monitor (synchronization)
In concurrent programming, a monitor is an object or module intended to be used safely by more than one thread. The defining characteristic of a monitor is that its methods are executed with mutual exclusion. That is, at each point in time, at most one thread may be executing any of its methods...

, coroutine
Coroutine
Coroutines are computer program components that generalize subroutines to allow multiple entry points for suspending and resuming execution at certain locations...

s and explicit transfer of control) and for hardware access (absolute addresses, bit manipulation, and interrupt
Interrupt
In computing, an interrupt is an asynchronous signal indicating the need for attention or a synchronous event in software indicating the need for a change in execution....

s). It uses name equivalence.

Dialects

There are two major dialects of Modula-2. The first is PIM, named after the book
"Programming in Modula-2" by Niklaus Wirth
Niklaus Wirth
Niklaus Emil Wirth is a Swiss computer scientist, best known for designing several programming languages, including Pascal, and for pioneering several classic topics in software engineering. In 1984 he won the Turing Award for developing a sequence of innovative computer languages.-Biography: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
International Organization for Standardization
The International Organization for Standardization , widely known as ISO, is an international standard-setting body composed of representatives from various national standards organizations. Founded on February 23, 1947, the organization promulgates worldwide proprietary, industrial and commercial...

.
  • 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.

Supersets

There are several supersets of Modula-2 with language extensions for specific application domains:
  • PIM supersets
    • Canterbury Modula-2, extended with Oberon-like extensible records
    • Modula-2+
      Modula-2+
      Modula-2+ is a programming language descended from the Modula-2 language. It was developed at DEC Systems Research Center and Acorn Computers Ltd Research Centre in Palo Alto, California. Modula-2+ is Modula-2 with exceptions and threads. The group who developed the language was led by P...

      , extended with preemptive threads and exceptions
    • Modula-2*, parallel extension
    • Modula-P, another parallel extension
    • Modula-Prolog, adding a Prolog layer
    • Modula/R, with relational database extensions
    • Modula-GM, extensions for embedded systems

  • ISO supersets
    • Mod51, extended with IEC1131 constructs for embedded development

Derivatives

There are several derivative languages that resemble Modula-2 very closely but are new languages in their own right. Most are different languages with different purposes and with strengths and weaknesses of their own:
  • Modula-3
    Modula-3
    In computer science, Modula-3 is a programming language conceived as a successor to an upgraded version of Modula-2 known as Modula-2+. While it has been influential in research circles it has not been adopted widely in industry...

    , developed by a team of ex-Xerox employees who had moved to DEC and Olivetti
  • Objective Modula-2, extended with Smalltalk-like object oriented constructs (still being designed, no compiler available)
  • Oberon
    Oberon (programming language)
    Oberon is a programming language created in 1986 by Professor Niklaus Wirth and his associates at ETH Zurich in Switzerland. It was developed as part of the implementation of the Oberon operating system...

    , developed at ETH
    Eth
    Eth is a letter used in Old English, Icelandic, Faroese , and Elfdalian. It was also used in Scandinavia during the Middle Ages, but was subsequently replaced with dh and later d. The capital eth resembles a D with a line through the vertical stroke...

     Zürich for System Oberon
    Oberon operating system
    Oberon is an operating system developed in the late 1980s at ETH Zürich using the Oberon programming language. It has an innovative visual text-based user interface for activating commands.- History :...

     available online.
  • Oberon-2, Oberon with OO extensions
  • Active Oberon
    Active Oberon
    Active Oberon is an extension of the programming language Oberon. Compared to its predecessors, Oberon and Oberon-2, it adds objects , system-guarded assertions, preemptive priority scheduling and a slightly changed syntax for methods...

    , yet another object-oriented Extension of Oberon
    Oberon (programming language)
    Oberon is a programming language created in 1986 by Professor Niklaus Wirth and his associates at ETH Zurich in Switzerland. It was developed as part of the implementation of the Oberon operating system...

    , developed also at ETH
    Eth
    Eth is a letter used in Old English, Icelandic, Faroese , and Elfdalian. It was also used in Scandinavia during the Middle Ages, but was subsequently replaced with dh and later d. The capital eth resembles a D with a line through the vertical stroke...

     with the main objective to support parallel programming on multiprocessor and multicore systems.
  • Parallaxis, a language for machine-independent data-parallel programming
  • Umbriel, developed by Pat Terry as a teaching language
  • YAFL, a research language by Darius Blasband


Many other current programming languages have adopted features of Modula-2.

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

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

Cambridge Modula-2

Cambridge Modula-2 by Cambridge Microprocessor Systems is based on a subset of PIM4 with language extensions for embedded development. The compiler runs on MS-DOS and it generates code for M68K based embedded microcontrollers running the MINOS operating system.

Mod51

Mod51 by Mandeno Granville Electronics is based on ISO Modula-2 with language extensions for embedded development following IEC1131, an industry standard for programmable logic controllers (PLC) closely related to Modula-2. The Mod51 compiler generates standalone code for 80C51 based microcontrollers.

Modula-GM

Delco Electronics
Delco Electronics
Delco Electronics Corporation was the automotive electronics design and manufacturing subsidiary of General Motors based in Kokomo, Indiana.The name Delco came from the Dayton Engineering Laboratories Co., founded in Dayton, Ohio by Charles Kettering and Edward A...

, then a subsidiary of GM Hughes
Hughes
Hughes may refer to:*Hughes *Hughes Medal*David E. Hughes inventorPlaces:* Hughes Range In Australia:* Division of Hughes, electoral district* Hughes, Australian Capital Territory, suburb of Canberra...

 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. The first experimental use of Modula-GM in an embedded controller was in the 1985 Antilock Braking System Controller which was based on the Motorola 68xxx microprocessor, and in 1993 Gen-4 ECU used by the CART
Champ Car
Champ Car was the name for a class and specification of open wheel cars used in American Championship Car Racing for many decades, primarily for use in the Indianapolis 500 auto race...

 (Championship Auto Racing Teams) and IRL (Indy Racing League) teams. 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
Buick V6 engine
The Buick V6, initially marketed as Fireball at its introduction in 1962, was a large V6 engine used by General Motors. The block is made of cast iron and all use two-valve-per-cylinder iron heads, actuated by pushrods....

 3800 Series II used in the 1997-2005 model year Buick Park Avenue
Buick Park Avenue
The Buick Park Avenue is a full-size car built by General Motors and sold by its Buick division. The nameplate was first used since 1975 as a top trim level of the Buick Electra, and the Park Avenue became a standalone model for the 1991 model year, replacing the Electra...

. The Modula-GM compilers and associated software management tools were sourced by Delco from Intermetrics
Intermetrics
Intermetrics, Inc. was a software company founded in Cambridge, Massachusetts in 1969 by several veterans of M.I.T.'s Instrumentation Laboratory who had worked on the software for NASA's Apollo Program including the Apollo Guidance Computer....

.

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
Delphi (auto parts)
Delphi Automotive PLC is an automotive parts company headquartered in Troy, Michigan, USA. Delphi is one of the world's largest automotive parts manufacturers and has approximately 146,600 employees ....

 in 1997, global sourcing required that a non-proprietary high-level software language be used. ECU embedded software now developed at Delphi is compiled with commercial C compilers.

Current compilers

  • ACK Modula-2 for Minix (freeware
    Freeware
    Freeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...

    )
  • Aglet Modula-2 for Amiga OS 4.0/PPC (freeware
    Freeware
    Freeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...

    )
  • Cambridge Modula-2 for various micro-controllers and embedded MINOS operating system (commercial + proprietary software
    Proprietary software
    Proprietary software is computer software licensed under exclusive legal right of the copyright holder. The licensee is given the right to use the software under certain conditions, while restricted from other uses, such as modification, further distribution, or reverse engineering.Complementary...

    )
  • Canterbury Modula-2 generates Java source code
  • [ftp://ftp.psg.com/pub/modula-2/fst/fst-40s.lzh FST] Fitted Software Tools Modula-2 for MS-DOS (freeware
    Freeware
    Freeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...

    )
  • Gardens Point Modula-2 for BSD, Linux, OS/2, Solaris and .NET
    .NET Framework
    The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...

     - ISO compliant (freeware
    Freeware
    Freeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...

    )
  • GNU Modula-2 for GCC platforms, version 1.0 released December 11, 2010; PIM2, PIM3, PIM4, and ISO compliant (free software
    Free software
    Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

    , GPLed
    GNU General Public License
    The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....

    )
  • M2Amiga for Amiga (free software
    Free software
    Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

    )
  • M2M by N. Wirth and collaborators from ETH Zurich, platform independent, generates M-code for virtual machine (freeware
    Freeware
    Freeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...

    )
  • MacMETH by N. Wirth and collaborators from ETH Zurich for Macintosh, but Classic only (freeware
    Freeware
    Freeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...

    )
  • Mod51 for the Intel 80x51 micro-controller family, ISO compliant, IEC1132 extensions (commercial + proprietary
    Proprietary software
    Proprietary software is computer software licensed under exclusive legal right of the copyright holder. The licensee is given the right to use the software under certain conditions, while restricted from other uses, such as modification, further distribution, or reverse engineering.Complementary...

    )
  • Modula-2 R10 Reference compiler for Modula-2 R10 (open-source/peer-review)
  • ModulaWare for OpenVMS, both VAX and Alpha, ISO compliant (commercial + proprietary
    Proprietary software
    Proprietary software is computer software licensed under exclusive legal right of the copyright holder. The licensee is given the right to use the software under certain conditions, while restricted from other uses, such as modification, further distribution, or reverse engineering.Complementary...

    )
  • [ftp://ftp.psg.com/pub/modula-2/grosch/mtc.tar.Z MTC] Modula-2 to C translator, available in Modula-2 and C source (free software
    Free software
    Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

    )
  • Native XDS-x86 for Windows and Linux (x86), ISO compliant, TopSpeed compatible library(freeware
    Freeware
    Freeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...

    )
  • Objective Modula-2, targets C and LLVM, cross-platform, with extensions for Cocoa and GNUstep (BSD style license)
  • p1 Modula-2 for Macintosh, both Classic and Mac OS X (PPC and Carbon API only), ISO compliant (commercial + proprietary
    Proprietary software
    Proprietary software is computer software licensed under exclusive legal right of the copyright holder. The licensee is given the right to use the software under certain conditions, while restricted from other uses, such as modification, further distribution, or reverse engineering.Complementary...

    )
  • The Karlsruhe Modula-2 Compiler MOCKA for various platforms, PIM compliant (commercial, freeware
    Freeware
    Freeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...

     Linux/BSD versions)
  • TERRA M2VMS for OpenVMS, both VAX and Alpha, PIM compliant (commercial + proprietary
    Proprietary software
    Proprietary software is computer software licensed under exclusive legal right of the copyright holder. The licensee is given the right to use the software under certain conditions, while restricted from other uses, such as modification, further distribution, or reverse engineering.Complementary...

    )
  • The Ulm Modula-2 System for Solaris, both SPARC and MC68K (free software, GPLed
    GNU General Public License
    The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....

    )
  • XDS-C for Windows and Linux, 16- and 32-bit platforms, targeting C (K&R & ANSI), ISO compliant, TopSpeed compatible library (freeware
    Freeware
    Freeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...

    )

Source for all entries: Modula2.net

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
  • Gleaves, Richard, Modula-2 for Pascal Programmers, First Edition, 1984.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK