All Topics  
Modula-2

 

   Email Print
   Bookmark   Link






 

Modula-2



 
 
Modula-2 is a computer programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 invented by Niklaus Wirth
Niklaus Wirth

Niklaus Emil Wirth is a Switzerland computer science, best known for designing several programming languages, including Pascal , and for pioneering several classic topics in software engineering....
 at ETH
Eth

Eth is a Letter used in Old English language, Icelandic alphabet, Faroese language#alphabet , and Dalecarlian language. It was also used in Scandinavia during the Middle Ages, but was subsequently replaced with dh and later d....
, around 1978, as a successor to his intermediate language Modula
Modula

The Modula programming language is a descendent of the Pascal . It was developed in Switzerland in the late 1970s by Niklaus Wirth, the same individual who designed Pascal....
. Modula-2 was implemented in 1980 for the Lilith
Lilith (computer)

Lilith is the name of custom built workstation using the AMD AMD Am2900 bit-slice Central processing unit by the group of Niklaus Wirth at ETH Z?rich....
 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
Niklaus Wirth

Niklaus Emil Wirth is a Switzerland computer science, best known for designing several programming languages, including Pascal , and for pioneering several classic topics in software engineering....
 as a successor to his programming language Pascal
Pascal (programming language)

Pascal is an influential imperative programming and Procedural programming 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 structure....
.






Discussion
Ask a question about 'Modula-2'
Start a new discussion about 'Modula-2'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Modula-2 is a computer programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 invented by Niklaus Wirth
Niklaus Wirth

Niklaus Emil Wirth is a Switzerland computer science, best known for designing several programming languages, including Pascal , and for pioneering several classic topics in software engineering....
 at ETH
Eth

Eth is a Letter used in Old English language, Icelandic alphabet, Faroese language#alphabet , and Dalecarlian language. It was also used in Scandinavia during the Middle Ages, but was subsequently replaced with dh and later d....
, around 1978, as a successor to his intermediate language Modula
Modula

The Modula programming language is a descendent of the Pascal . It was developed in Switzerland in the late 1970s by Niklaus Wirth, the same individual who designed Pascal....
. Modula-2 was implemented in 1980 for the Lilith
Lilith (computer)

Lilith is the name of custom built workstation using the AMD AMD Am2900 bit-slice Central processing unit by the group of Niklaus Wirth at ETH Z?rich....
 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
Niklaus Wirth

Niklaus Emil Wirth is a Switzerland computer science, best known for designing several programming languages, including Pascal , and for pioneering several classic topics in software engineering....
 as a successor to his programming language Pascal
Pascal (programming language)

Pascal is an influential imperative programming and Procedural programming 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 structure....
. The language design was also influenced by the Mesa programming language
Mesa programming language

Mesa was an innovative computer programming programming language developed at PARC in the late 1970s . The language was named after the mesas of the American Southwest, referring to its design intent to be a high-level programming language....
 and the new programming possibilities of the early personal computer Xerox Alto
Xerox Alto

The Xerox Alto was an early personal computer developed at Xerox PARC in 1973. It was the first computer to use the desktop metaphor and graphical user interface ....
, both from Xerox, that Wirth saw during his 1976 sabbatical year
Sabbatical year

A sabbatical is a rest from work, a hiatus, typically lasting two or more months. The concept of a sabbatical has a source in several places in the Bible , where there is a commandment to desist from working the fields in the seventh year....
 at Xerox PARC
Xerox PARC

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

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 programming and Procedural programming 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 structure....
. Modula-2 was designed to be broadly similar to Pascal, with some elements 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
Monitor (synchronization)

In concurrent programming, a monitor is an Object 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....
, coroutine
Coroutine

In computer science, coroutines are program components that generalize subroutines to allow multiple entry points for suspending and resuming of 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 communication signal from hardware 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 Switzerland computer science, best known for designing several programming languages, including Pascal , and for pioneering several classic topics in software engineering....
. 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....
.

  • 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 and REM operators when their 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.


Language elements


Reserved words


PIM3 contained the following 40 reserved words:

AND ELSIF   LOOP       REPEAT
ARRAY       END     MODRETURN
BEGIN       EXIT    MODULE     SET
BY  EXPORT  NOTTHEN
CASEFOR     OF TO
CONST       FROM    OR TYPE
DEFINITION  IF      POINTER    UNTIL
DIV IMPLEMENTATION  PROCEDURE  VAR
DO  IMPORT  QUALIFIED  WHILE
ELSEIN      RECORD     WITH


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: the original, and quite different, Modula (intended for systems implementation), Modula-2+
Modula-2+

The Modula-2+ programming language is a descendant of the Modula-2 programming language. It was developed at DEC_Systems_Research_Center of Digital_Equipment_Corporation in Palo Alto ....
, Modula-2* (parallel extension), ISO Modula-2's OO and generic extensions, Modula-3
Modula-3

In Computer science, Modula-3 is a programming language conceived as a successor to an upgraded version of Modula-2. While it has been influential in research circles it has not been adopted widely in industry....
 (by DEC and Olivetti; adding garbage collection, objects, and generics), 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....
 (another, later, Wirth design), Oberon-2
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....
 (Oberon with OO extensions), and a number of others. 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.

Modula-2 was developed as the system language for the Lilith
Lilith (computer)

Lilith is the name of custom built workstation using the AMD AMD Am2900 bit-slice Central processing unit by the group of Niklaus Wirth at ETH Z?rich....
 workstation, and formed the ancestor for the 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....
 language and workstation project (System Oberon
Oberon operating system

Oberon is an operating system, originally developed as part of the NS320xx-based Ceres workstation project; it is written entirely in the Oberon programming language....
) developed at ETH
Eth

Eth is a Letter used in Old English language, Icelandic alphabet, Faroese language#alphabet , and Dalecarlian language. It was also used in Scandinavia during the Middle Ages, but was subsequently replaced with dh and later d....
 Zürich. Many current programming languages have adopted features of Modula-2.

Modula-GM

Delco Electronics
Delco Electronics

Delco Electronics Corporation was the automotive electronics design and manufacturing subsidiary of General Motors Corporation based in Kokomo, Indiana....
, then a subsidiary of GM Hughes
Hughes

Hughes may refer to:*Hughes *Hughes MedalPlaces:* 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 1993 Gen-4 ECU used by the CART
Cart

A cart is a vehicle or device designed for transport, using two or four wheels and normally pulled by one or a pair of draught animals. A handcart is pulled or pushed by one or more people....
 (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, is a large V6 engine used by General Motors Corporation. 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 in 1991, 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, Massachusetts in 1969 by several veterans of Massachusetts Institute of Technology Charles Stark Draper Laboratory who had worked on the software for NASA's Project Apollo 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 is an automotive parts company headquartered in Troy, Michigan, United States. Delphi is one of the world's largest automotive parts manufacturers and has approximately 169,500 employees ....
 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.

Current compilers

  • Modula-2 for Minix 2.0 (freeware
    Freeware

    Freeware is computer software that is available for use at no cost or for an optional fee. Freeware is different from shareware; the latter obliges the user to pay ....
    )
  • for various micro-controllers and embedded MINOS operating system (commercial + proprietary software
    Proprietary software

    Proprietary software is a term coined by advocates of the free software movement to describe computer software which is the legal property of one party....
    )
  • generates Java source code
  • for BSD and Ultrix, both VAX and MIPS (freeware
    Freeware

    Freeware is computer software that is available for use at no cost or for an optional fee. Freeware is different from shareware; the latter obliges the user to pay ....
    )
  • [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. Freeware is different from shareware; the latter obliges the user to pay ....
    )
  • for BSD, Linux, OS/2, Solaris and .NET
    .NET Framework

    The Microsoft .NET Framework is a software framework that is available with several Microsoft Windows operating systems. It includes a large Library of coded solutions to prevent common programming problems and a virtual machine that manages the execution of programs written specifically for the Software framework....
     - ISO compliant (freeware
    Freeware

    Freeware is computer software that is available for use at no cost or for an optional fee. Freeware is different from shareware; the latter obliges the user to pay ....
    )
  • for GCC platforms, work in progress but already generates code, PIM compliant (free software
    Free software

    Free Software or software libre 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 minimal restrictions only to ensure that further recipients can also do these things and to prevent consumer-facing hardware...
    , GPLed
    GNU General Public License

    The GNU General Public License is a widely used free software license, originally written by Richard Stallman for the GNU project. The GPL is the most popular and well-known example of the type of strong copyleft license that requires derived works to be available under the same copyleft....
    )
  • for Amiga (free software
    Free software

    Free Software or software libre 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 minimal restrictions only to ensure that further recipients can also do these things and to prevent consumer-facing hardware...
    )
  • 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. Freeware is different from shareware; the latter obliges the user to pay ....
    )
  • for the Intel 80x51 micro-controller family (commercial + proprietary
    Proprietary software

    Proprietary software is a term coined by advocates of the free software movement to describe computer software which is the legal property of one party....
    )
  • for OpenVMS, both VAX and Alpha, ISO compliant (commercial + proprietary
    Proprietary software

    Proprietary software is a term coined by advocates of the free software movement to describe computer software which is the legal property of one party....
    )
  • [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 or software libre 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 minimal restrictions only to ensure that further recipients can also do these things and to prevent consumer-facing hardware...
    )
  • for Windows and Linux, ISO compliant Modula-2 and Oberon-2 native compilers with optional TopSpeed Compatibility Pack (freeware
    Freeware

    Freeware is computer software that is available for use at no cost or for an optional fee. Freeware is different from shareware; the latter obliges the user to pay ....
    )
  • for Macintosh, both Classic and Mac OS X, ISO compliant (commercial + proprietary
    Proprietary software

    Proprietary software is a term coined by advocates of the free software movement to describe computer software which is the legal property of one party....
    )
  • 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. Freeware is different from shareware; the latter obliges the user to pay ....
     Linux/BSD versions)
  • for OpenVMS, both VAX and Alpha, PIM compliant (commercial + proprietary
    Proprietary software

    Proprietary software is a term coined by advocates of the free software movement to describe computer software which is the legal property of one party....
    )
  • for Solaris, both SPARC and MC68K (free software, GPLed
    GNU General Public License

    The GNU General Public License is a widely used free software license, originally written by Richard Stallman for the GNU project. The GPL is the most popular and well-known example of the type of strong copyleft license that requires derived works to be available under the same copyleft....
    )
  • 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
    Freeware

    Freeware is computer software that is available for use at no cost or for an optional fee. Freeware is different from shareware; the latter obliges the user to pay ....
    )


Discontinued compilers

  • Benchmark Modula-2 for the Amiga
    Amiga

    The Amiga is a family of personal computers originally developed by Amiga Corporation. Development on the Amiga began in 1982 with Jay Miner as the principal hardware designer....
  • for CP/M (abandonware)
  • Borland Turbo Modula-2
    Turbo Modula-2

    Turbo Modula-2 was both a compiler and an Integrated Development Environment for the Modula-2 programming language running on MS-DOS, developed by Borland, but never released by them....
     for MS-DOS (sold to Jensen and Partners, became TopSpeed Modula-2)
  • (from former Edinburgh Portable Compilers Limited; company no longer exists, is now a division of )
  • FTL Modula-2 (v1.15 1986) for MS-DOS, ATARI ST and CP/M Z80 by Dave Moore, Cerenkof Computing. Distributed in Australia by
  • had a series of Modula-2 compilers for CP/M and MS-DOS.
  • M2S for the Amiga
    Amiga

    The Amiga is a family of personal computers originally developed by Amiga Corporation. Development on the Amiga began in 1982 with Jay Miner as the principal hardware designer....
  • M2SDS (IBM PC), Interface Technologies Inc. (ITC) Houston, TX.
  • for Atari ST & TT computers. German language only. Documentation and source code is now available for free, yet not very useful as much of it is written in 68k assembler code.
  • Metrowerks
    Metrowerks

    Metrowerks was a company that developed software development tools for various desktop, handheld, embedded, and game platforms. Its flagship product, CodeWarrior, comprised an Integrated Development Environment, compilers, linkers, Library , and related tools....
    ' first products were Modula-2 compilers for various platforms, including the Macintosh
  • Modula Corporation had a series of Modula-2 compilers for MS-DOS
    MS-DOS

    MS-DOS is an operating system commercialized by Microsoft. It was the most commonly used member of the DOS family of operating systems and was the main operating system for personal computers during the 1980s....
     , the Apple II and the Macintosh
    Macintosh

    File:Imac alu.pngMacintosh, commonly shortened to Mac, is a brand name which covers several lines of personal computers designed, developed, and marketed by Apple Inc....
  • Modula-2 PC (IBM PC), PCollier Systems, Tucson, AZ.
  • Mosys Modula-2 System for Sage / Stride 68000 computers. Brian Kirk,
  • TDI Modula-2 for the Amiga
    Amiga

    The Amiga is a family of personal computers originally developed by Amiga Corporation. Development on the Amiga began in 1982 with Jay Miner as the principal hardware designer....
     and Atari
    Atari

    Atari is a corporate and brand name owned by several entities since its inception in 1972. It is currently owned by Atari Interactive, a wholly owned subsidiary of the French publisher Infogrames ....
     ST
  • TopSpeed (aka Clarion, aka JPI, aka Jensen and Partners) had several good 16-bit Modula-2 compilers, with nice productive IDEs. This was the "Turbo Pascal" of Modula-2. Slightly non standard, but very popular both in business and education, an excellent toolchain. They are currently included with Clarion now owned by
  • Volition Systems Modula-2 (UCSD p-System). Randy Bush, Richard Gleaves, Volition Systems Del Mar, CA.


Books

  • 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, "," (Using ISO-Standard Modula-2) 2004-2005 Edition


External links

  • by Rick Sutcliffe, version from 2005.09.09