Modula-2

Modula-2
Modula-2
Paradigm(s) imperative, structured, modular, data and method hiding
Appeared in 1978
Designed by Niklaus Wirth
Typing discipline strong, static
Major implementations

ETH compiler written by Niklaus Wirth,

Dialects PIM2, PIM3, PIM4, ISO
Influenced by Modula, Mesa, Pascal, Algol-W
Influenced Modula-3, Oberon, Ada, Fortran 90, Lua, Zonnon, Modula-GM

Modula-2 is a computer programming language designed and developed between 1977 and 1980 by Niklaus Wirth at ETH Zurich as a revision of Pascal to serve as the sole programming language for the operating system and application software for the personal workstation Lilith.[1] 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 as a successor to his earlier programming language Pascal.[2] 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.[3]

Contents

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.

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.[4]

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+, extended with preemptive threads and exceptions
    • Modula-2*, parallel extension[5]
    • Modula-P, another parallel extension[6]
    • Modula-Prolog, adding a Prolog layer[7]
    • 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, developed by a team of ex-Xerox employees who had moved to DEC and Olivetti[8]
  • Objective Modula-2, extended with Smalltalk-like object oriented constructs[9] (still being designed, no compiler available)
  • Oberon, developed at ETH Zürich for System Oberon[10] available online.
  • Oberon-2, Oberon with OO extensions[11]
  • Active Oberon, yet another object-oriented Extension of Oberon, developed also at ETH with the main objective to support parallel programming on multiprocessor and multicore systems.
  • Parallaxis, a language for machine-independent data-parallel programming[12]
  • Umbriel, developed by Pat Terry as a teaching language[13]
  • YAFL, a research language by Darius Blasband[14]

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

Language elements

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

Use in embedded systems

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, 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.[15] 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 (Championship Auto Racing Teams) and IRL (Indy Racing League) teams.[16] 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 is compiled with commercial C compilers.

Current compilers

Source for all entries: Modula2.net[17]

Books

References

  1. ^ Summary of Projects by N. Wirth, 1962-1999
  2. ^ N. Wirth, Pascal and its Successors. In Software Pioneers, M. Broy and E. Denert, Eds. Springer-Verlag, 2002, ISBN 3-540-43081-4
  3. ^ N. Wirth, Programming in Modula-2, fourth Edition, page 4.
  4. ^ ISO/IEC 10514-1:1996
  5. ^ Tichy et al, Modula-2*: An Extension for Modula-2 for highly parallel portable programs, University of Karlsruhe [1990]
  6. ^ Bräunl, Parallel Programming, Prentice-Hall [1993]
  7. ^ Muller, C. Modula--Prolog: A Software Development (1986) IEEE Software
  8. ^ Cardelli et al, Modula-3 Report, Research Report 31, Systems Research Center, Digital Equipment Corporation, [1988]
  9. ^ B. Kowarsch, An Overview of Objective Modula-2, [2009]
  10. ^ N. Wirth & J. Gutknecht, Project Oberon: the design of an operating system and compiler, ISBN 0-201-54428-8, Addison-Wesley [1992]
  11. ^ Moessenboeck & Wirth, The Programming Language Oberon-2, ETH Zurich [1995]
  12. ^ Thomas Bräunl, Parallaxis, a Language for Structured Data-parallel Programming, University of Stuttgart [1996]
  13. ^ Pat D. Terry, Another Minimal Programming Language, ACM SIGPLAN Notices No. 30 [1995]
  14. ^ D. Blasband, The YAFL Programming Language, Second Edition, [1993]
  15. ^ Delco Electronics Electron Magazine, The Atwood Legacy, Spring '89, page 25
  16. ^ Development of Electronics for GM Auto Racing
  17. ^ List of Modula-2 compilers at modula2.net

External links

This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Modula-3 — Paradigm(s) imperative, structured, modular Appeared in 1980s Designed by DEC and Olivetti …   Wikipedia

  • Modula-2 — Modula Apparu en 1977 Auteur Niklaus Wirth Paradigme générique, procédural, impératif …   Wikipédia en Français

  • Modula-3 — Modula 2 Modula Apparu en 1977 Auteur …   Wikipédia en Français

  • Modula-II — Modula 2 Modula Apparu en 1977 Auteur …   Wikipédia en Français

  • Modula-2 — Paradigmen: imperativ, strukturiert, modular Erscheinungsjahr: 1978 Entwickler: Niklaus Wirth Einflüsse: Pascal …   Deutsch Wikipedia

  • Modula-3 — Información general Paradigma multiparadigma: imperativo, estructurado, modular Apareció en Años 1980 Diseñado por DEC y …   Wikipedia Español

  • Modula — 2 ist eine 1978 entstandene Weiterentwicklung der Programmiersprache Pascal und wurde wie diese von Niklaus Wirth entwickelt. Hauptkennzeichen von Modula 2 sind die Sprachmerkmale zur Modularisierung von Programmen. Modula 2 diente selbst später… …   Deutsch Wikipedia

  • Modula 2 — ist eine 1978 entstandene Weiterentwicklung der Programmiersprache Pascal und wurde wie diese von Niklaus Wirth entwickelt. Hauptkennzeichen von Modula 2 sind die Sprachmerkmale zur Modularisierung von Programmen. Modula 2 diente selbst später… …   Deutsch Wikipedia

  • Modula-2+ — Paradigm(s) imperative, structured, modular Appeared in 1980s Designed by DEC Systems Research Center SRC and Acorn Research Center Developer DEC Systems Research Center SRC and Acorn Research …   Wikipedia

  • Modula-2 — Desarrollador(es) http://www.modula2.org Información general Paradigma Programación imperativa, Programación modular …   Wikipedia Español

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”