Modula-2 Explained

Modula-2
Paradigms:imperative, structured, modular, data and procedure hiding, concurrent
Family:Wirth/Modula
Designer:Niklaus Wirth
Typing:Static, strong, safe
Scope:Lexical (static)
Platform:Lilith (AMD 2901)
Operating System:Cross-platform
File Ext:.mod, .m2, .def, .MOD, .DEF, .mi, .md
Implementations:ETH compiler written by Niklaus Wirth
GNU Modula-2
ADW Modula-2
Dialects:PIM2, PIM3, PIM4, ISO
Influenced By:Modula, Mesa, Pascal, ALGOL W, Euclid
Influenced:Modula-2+, Modula-3, Oberon, Ada, Fortran 90, Lua, Seed7, Zonnon, Modula-GM

Modula-2 is a structured, procedural programming language developed between 1977 and 1985/8 by Niklaus Wirth at ETH Zurich. It was created as the language for the operating system and application software of the Lilith personal workstation.[1] It was later used for programming outside the context of the Lilith.

Wirth viewed Modula-2 as a successor to his earlier programming languages Pascal and Modula.[2] [3] The main concepts are:

  1. The module as a compiling unit for separate compiling
  2. The coroutine as the basic building block for concurrent processes
  3. Types and procedures that allow access to machine-specific data

The language design was influenced by the Mesa language and the Xerox Alto, both from Xerox PARC, that Wirth saw during his 1976 sabbatical year there.[4] The computer magazine Byte devoted the August 1984 issue to the language and its surrounding environment.[5]

Wirth created the Oberon series of languages as the successor to Modula-2, while others (particularly at Digital Equipment Corporation and Acorn Computers, later Olivetti) developed Modula-2 into Modula-2+ and later Modula-3.

Description

Modula-2 is a general purpose procedural language suitable for both systems programming and applications programming. The syntax is based on Wirth's earlier language, Pascal, with some elements and syntactic ambiguities removed. The module concept, designed to support separate compilation and data abstraction; and direct language support for multiprogramming were added.

The language allows the use of one-pass compilers. Such a compiler by Gutknecht and Wirth was about four times faster than earlier multi-pass compilers.[6]

Here is an example of the source code for the "Hello world" program:

MODULE Hello;FROM STextIO IMPORT WriteString;BEGIN WriteString("Hello World!")END Hello.

A Modula-2 module may be used to encapsulate a set of related subprograms and data structures, and restrict their visibility from other parts of the program. 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. Except for standard identifiers, no object from the outside 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 are known outside module M1 as M1.a, M1.b, M1.c, and M1.P. They are exported in a qualified manner to the outside (assuming 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 outside of its enclosing program can now be used inside module M2. They are referenced in a qualified manner: 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 example, if another module M3 exports an object called P, then the two objects can be distinguished since M1.P differs from M3.P. It does not matter that both objects are called P inside their exporting modules M1 and M3.

An alternative method exists. Suppose module M4 is formulated as this:

MODULE M4; FROM M1 IMPORT a, b, c, P;

This means that objects exported by module M1 to the outside can again be used inside module M4, but now by mere references to the exported identifiers in an unqualified manner as: a, b, c, and P. Example:

... a := 0; c := P(a + b); ...

This method of import is usable if there are no name clashes. It allows variables and other objects to be used outside their exporting module in the same unqualified, manner as inside the exporting module.

The export and import rules not only safeguard objects against unwanted access, but also allow a cross-reference of the definition of every identifier in a program to be created. This property helps with the maintenance of large programs containing many modules.

The language provides for single-processor concurrency (monitors, coroutines and explicit transfer of control) and for hardware access (absolute addresses, bit manipulation, and interrupts). It uses a nominal type system.

Dialects

There are two major dialects of Modula-2. The first is PIM, named for the book Programming in Modula-2 by Niklaus Wirth.[4] There were three major editions of PIM: the second, third (corrected), and fourth. Each describes slight variants of the language. The second major dialect is ISO, named for the standardization effort by the International Organization for Standardization. Here are a few of the differences among them.

Supersets

There are several supersets of Modula-2 with language extensions for specific application domains:

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:

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

Language elements

Reserved words

PIM [2,3,4] defines 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

Built-in identifiers

PIM [3,4] defines 29 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

Embedded system use

Modula-2 is used to program many 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 DOS and it generates code for Motorola 68000 series (M68k) based embedded microcontrollers running a MINOS operating system.

Mod51

Mod51 by Mandeno Granville Electronics is based on ISO Modula-2 with language extensions for embedded development following IEC 1131, 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 programming language used to replace machine code (language) 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.[18] 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 Champ Car World Series Championship Auto Racing Teams (CART) and Indy Racing League (IRL) teams.[19] The first production use of Modula-GM was its use in GM trucks starting with the 1990 model year vehicle control module (VCM) used to manage GM Powertrain's Vortec engines. Modula-GM was also used on all ECUs for GM's 90° Buick V6 engine 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 Automotive Systems in 1995, global sourcing required that a non-proprietary high-level software language be used. ECU embedded software now developed at Delphi is compiled with commercial compilers for the language C.

Russian radionavigation satellites

The satellites of the Russian radionavigation-satellite service framework GLONASS, similar to the United States Global Positioning System (GPS), are programmed in Modula-2.[20]

Compilers

Turbo Modula-2

Turbo Modula-2 was a compiler and an integrated development environment for MS-DOS developed, but not published, by Borland. Jensen and Partners, which included Borland cofounder Niels Jensen, bought the unreleased codebase and turned it into TopSpeed Modula-2. It was eventually sold to Clarion, now SoftVelocity, who then offered the Modula-2 compiler as part of its Clarion product line at that time.[43]

A Zilog Z80 CP/M version of Turbo Modula-2 was briefly marketed by Echelon under license from Borland. A companion release for Hitachi HD64180 was sold by Micromint as a development tool for their SB-180 single-board computer.[44]

IBM Modula-2

IBM had a Modula-2 compiler for internal use which ran on both OS/2 and AIX, and had first class support in IBM's E2 editor.[45] IBM Modula-2 was used for parts of the OS/400 Vertical Licensed Internal Code (effectively the kernel of OS/400).[46] This code was mostly replaced with C++ when OS/400 was ported to the IBM RS64 processor family, although some remains in modern releases of the operating system.[47] [48] A Motorola 68000 backend also existed, which may have been used in embedded systems products.[45]

Operating systems

Modula-2 is used to program some operating systems (OSs). The Modula-2 module structure and support are used directly in two related OSs.

The OS named Medos-2, for the Lilith workstation, was developed at ETH Zurich, by Svend Erik Knudsen with advice from Wirth. It is a single user, object-oriented operating system built from Modula-2 modules.[49] [50] [51]

The OS named Excelsior, for the Kronos workstation, was developed by the Academy of Sciences of the Soviet Union, Siberian branch, Novosibirsk Computing Center, Modular Asynchronous Developable Systems (MARS) project, Kronos Research Group (KRG). It is a single user system based on Modula-2 modules.[52]

Books

Notes and References

  1. Web site: Summary of Projects by N. Wirth, 1962–1999 . . . Department of Computer Science . ETH Zurich.
  2. Book: Wirth, Niklaus . Niklaus Wirth . Pascal and its Successors . 2002 . Broy . Manfred . Denert . Ernst . Software Pioneers: Contributions to Software Engineering . Berlin, Heidelberg . . 108–120 . 10.1007/978-3-642-59412-0 . 978-3-642-59412-0 . 2698265.
  3. Wirth . Niklaus . Niklaus Wirth . 18 February 2005 . History and Goals of Modula-2 . . Informa PLC.
  4. Book: Wirth, Niklaus . Niklaus Wirth . Programming in Modula-2 . 1988 . Berlin, Heidelberg . Springer . 4th . 978-3-642-83565-0 . 10.1007/978-3-642-83565-0 . 41899609. Page 4.
  5. Wirth . Niklaus . Niklaus Wirth . Gutknecht . Jürg . Jürg Gutknecht . Ohran . Richard . Paul . Robert J. . Coar . David . August 1984 . Theme: Modula-2 . . 9 . 8 . 143–232 . Available at Archive.org
  6. Web site: Wirth . Niklaus . Niklaus Wirth . 1 May 1984 . A Single-pass Modula-2 Compiler for Lilith . CFB Software . 23 November 2023.
  7. ISO/IEC 10514-1:1996
  8. Tichy et al., Modula-2*: An Extension for Modula-2 for highly parallel portable programs, University of Karlsruhe [1990]
  9. Bräunl, Parallel Programming, Prentice-Hall [1993]
  10. Muller . C. . November 1986 . Modula–Prolog: A Software Development . IEEE Software . 3 . 6 . 39–45. }
  11. https://freepages.modula2.org/m2faq.html modula2.org, 5. Where can I get information about ISO Modula-2?
  12. Cardelli et al., Modula-3 Report, Research Report 31, Systems Research Center, Digital Equipment Corporation, [1988]
  13. N. Wirth & J. Gutknecht, Project Oberon: the design of an operating system and compiler,, Addison-Wesley [1992]
  14. Moessenboeck & Wirth, The Programming Language Oberon-2, ETH Zurich [1995]
  15. Thomas Bräunl, Parallaxis, a Language for Structured Data-parallel Programming, University of Stuttgart [1996]
  16. Pat D. Terry, Another Minimal Programming Language, ACM SIGPLAN Notices No. 30 [1995]
  17. D. Blasband, The YAFL Programming Language, Second Edition, [1993]
  18. Delco Electronics Electron Magazine, The Atwood Legacy, Spring '89, page 25
  19. [Development of electronics for GM auto racing]
  20. Web site: Koltashev . A. A. . 2006 . Also at http://www.inr.ac.ru/~info21/texts/aakmodula2.htm --> Modula-2 in Russian Space . Kronos: History of a Project . xTech . ru . 8 April 2021.
  21. Web site: ACK . Given . David . 9 October 2020 . GitHub . 13 March 2021.
  22. Web site: ADW Modula-2 . . . Modula-2.org . 13 March 2021.
  23. Web site: Aglet Modula-2 . . 15 February 2012 . Aglet Modula-2 . 13 March 2021.
  24. Web site: [ftp://ftp.psg.com/pub/modula-2/fst/fst-40s.lzh FST Modula-2 ]. psg.com . 13 October 2021.
  25. Web site: Gardens Point Modula . . 29 January 2007 . Programming Languages and Systems Group, Faculty of Information Technology . Queensland University of Technology, Brisbane . 13 March 2021 . dead . https://web.archive.org/web/20130323002046/http://plas.fit.qut.edu.au/gpm/ . 23 March 2013.
  26. Web site: Gardens Point Modula-2 (GPM/CLR) . K John Gough . 25 October 2010 . GitHub . 16 October 2022.
  27. Web site: GNU Modula-2 . . 30 August 2018 . Savannah . Free Software Foundation . 13 March 2021.
  28. Web site: Logitech Modula-2 . The Electronic Developer Magazine for OS/2 (EDM/2) . 29 May 2022.
  29. Web site: 1988: Modula-2 and Logitech RTK . 12 April 2022 . Øyvind Teig . Photo of the floppy disk.
  30. Web site: M2Amiga . Degen . René . Nieder . Claudio . Preusing . Bernd . Schaub . Markus . Straube . Jörg . 2004 . Claudio's web site . A+L AG . 13 March 2021 . live . https://web.archive.org/web/20190120022439/https://m2amiga.claudio.ch/ . 20 January 2019.
  31. Web site: Lilith and Modula-2 . . . CFB Software . 23 November 2023.
  32. Web site: MacMETH: A Fast Modula-2 Language System for Macintosh Computers . . 22 January 2020 . ETH Zurich: Terrestrial Systems Ecology . 13 March 2021.
  33. Web site: Mod51 Structured Text Programming Language . . . Design Tools . 13 March 2021 . dead . https://web.archive.org/web/20081021043956/http://www.designtools.co.nz/mod51.htm . 21 October 2008.
  34. Web site: Thomas Tempelmann's home page . Tempelmann . Thomas . 1 September 2020 . 18 March 2021.
  35. Web site: Modula-2 R10 . 13 October 2021.
  36. Web site: ModulAware . Dotzel . Chih-Ya . 21 January 2020 . 18 March 2021.
  37. Web site: p1 Modula-2 . Wiedemann . Albert . 13 January 2021 . p1 Society for Computer Science . 19 March 2021.
  38. Web site: Beck . Michael . Geiss . Rubino . 2006 . The Karlsruhe Modula-2 Compiler MOCKA . Institute for Program Structures and Data Organization (IPD) . . dead . https://web.archive.org/web/20090904204227/http://www.info.uni-karlsruhe.de/~modula/index.php . 4 September 2009 . 21 March 2021.
  39. Modula-2 compiler . Australian Personal Computer . August 1986 . 8 October 2022 . Jefferson . Gareth . 49, 52, 54, 56, 58.
  40. Web site: . 12 November 2002 . Modula-2 systems for OpenVMS/Alpha and OpenVMS/VAX . Terra Datentechnik . Erlenbach, Switzerland . en, de . 23 March 2021.
  41. Web site: Borchert . Andreas . Hasch . Martin . 21 January 2003 . m2c: Ulm's Modula-2 System . Ulm University . Ulm, Germany . en . 23 March 2021.
  42. Web site: XDS Family of Products: Modula-2 – Oberon-2 development tools . . 1999–2009 . Excelsior LLC . dead . https://web.archive.org/web/20090527060148/http://www.excelsior-usa.com/xds.html . 27 May 2009 . 23 March 2021.
  43. Web site: About Clarion . https://web.archive.org/web/20021207222218/http://softvelocity.com/core/default.html . 31 March 2023. 7 December 2002.
  44. Circuit Cellar . . 11 . 13 . 98 .
  45. Web site: IBM Modula-2 . 2 March 2019 . edm2.com . 2021-03-12.
  46. Web site: Reader Feedback on AS/400 to i Mystery Solved . 2011-02-21 . 2021-03-12 . itjungle.com.
  47. Book: Soltis, Frank G. . 1997 . Inside the AS/400 . 2nd . Duke Press . 978-1882419661.
  48. Re: Re: MI emulator. Leif Svalgaard. 2003-10-08. 2021-02-26. MI400.
  49. Knudsen . Svend Erik . 1983 . Medos-2: A Modula-2 Oriented Operating System for the Personal Computer Lilith . PhD . . 10.3929/ethz-a-000300091. 20.500.11850/137906.
  50. Book: Knudsen, Svend Erik . 25 October 2000 . Medos in Retrospect . Böszörményi . László . Gutknecht . Jürg . Jürg Gutknecht . Pomberger . Gustav . The School of Niklaus Wirth: The Art of Simplicity . 69–86 . Morgan Kaufmann . 978-1558607231. & dpunkt, .
  51. Sand . Paul A. . September 1984 . The Lilith Personal Computer . . 300–311 . 6 March 2021. Reprint.
  52. Web site: Kuznetsov . D.N. . Nedorya . A.E. . Tarasov . E.V. . Filippov . V.E. . . Kronos: a family of processors for high-level languages . Kronos: History of a Project . xTech . ru . 13 April 2021.