Paradigms | imperative,structured,modular,data and procedure hiding,concurrent |
---|---|
Family | Wirth/Modula |
Designed by | Niklaus Wirth |
First appeared | 1978; 47 years ago (1978) |
Typing discipline | Static,strong,safe |
Scope | Lexical (static) |
Platform | Lilith (AMD2901) |
OS | Cross-platform |
Filename extensions | .mod, .m2, .def, .MOD, .DEF, .mi, .md |
Website | www |
Majorimplementations | |
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, proceduralprogramming language developed between 1977 and 1985/8 byNiklaus Wirth atETH Zurich. It was created as the language for theoperating system andapplication software of theLilith personalworkstation.[1] It was later used for programming outside the context of theLilith.
Wirth viewed Modula-2 as a successor to his earlier programming languagesPascal andModula.[2][3] The main concepts are:
The language design was influenced by theMesa language and theXerox Alto, both fromXerox PARC, that Wirth saw during his 1976sabbatical year there.[4] The computer magazineByte devoted the August 1984 issue to the language and its surrounding environment.[5]
Wirth created theOberon series of languages as the successor to Modula-2, while others (particularly atDigital Equipment Corporation andAcorn Computers, laterOlivetti) developed Modula-2 intoModula-2+ and laterModula-3.
Modula-2 is a general purposeprocedural language suitable for bothsystems programming and applications programming. The syntax is based on Wirth's earlier language,Pascal, with some elements and syntactic ambiguities removed. Themodule concept, designed to support separate compilation and data abstraction; and direct language support formultiprogramming were added.
The language allows the use ofone-pass compilers. Such acompiler by Gutknecht and Wirth was about four times faster than earliermulti-pass compilers.[6]
Here is an example of the source code for the "Hello world" program:
MODULEHello;FROMSTextIOIMPORTWriteString;BEGINWriteString("Hello World!")ENDHello.
A Modula-2module may be used to encapsulate a set of related subprograms and data structures, and restrict their visibility from other parts of the program.[7] Modula-2 programs are composed of modules, each of which is made up of two parts: adefinition module, the interface portion, which contains only those parts of the subsystem that areexported (visible to other modules), and animplementation module, which contains the working code that is internal to the module.
The language has strictscope control. Except for standard identifiers, noobject 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
DEFINITIONMODULEM1;EXPORTQUALIFIEDa,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 aqualified 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
MODULEM2;IMPORTM1;...
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 aqualified 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:
MODULEM4;FROMM1IMPORTa,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 anunqualified 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 sameunqualified 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, andinterrupts). It uses anominal type system.
There are two major dialects of Modula-2. The first isPIM, named for the bookProgramming 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 isISO, named for the standardization effort by theInternational Organization for Standardization. Here are a few of the differences among them.
EXPORT
clause in definition modules.SIZE
needs to be imported from moduleSYSTEM
EXPORT
clause from definition modules following the observation that everything within a definition module defines the interface to that module, hence theEXPORT
clause was redundant.SIZE
is pervasive (visible in any scope without import)MOD
operator when the operands are negative.ARRAY OF CHAR
strings to be terminated by ASCII NUL, even if the string fits exactly into its array.COMPLEX
andLONGCOMPLEX
, exceptions, module termination (FINALLY
clause) and a complete standardinput/output (I/O)library. There are many minor differences and clarifications.[8]There are several supersets of Modula-2 with language extensions for specific application domains:
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.
PIM [2,3,4] defines 40reserved words:
AND ELSIF LOOP REPEATARRAY END MOD RETURNBEGIN EXIT MODULE SETBY EXPORT NOT THENCASE FOR OF TOCONST FROM OR TYPEDEFINITION IF POINTER UNTILDIV IMPLEMENTATION PROCEDURE VARDO IMPORT QUALIFIED WHILEELSE IN RECORD WITH
PIM [3,4] defines 29 built-inidentifiers:
ABS EXCL LONGINT REALBITSET FALSE LONGREAL SIZEBOOLEAN FLOAT MAX TRUECAP HALT MIN TRUNCCARDINAL HIGH NIL VALCHAR INC ODDCHR INCL ORDDEC INTEGER PROC
Modula-2 is used to program manyembedded systems.
Cambridge Modula-2 by Cambridge Microprocessor Systems is based on a subset of PIM4 with language extensions for embedded development. The compiler runs onDOS and it generates code forMotorola 68000 series (M68k) based embedded microcontrollers running a MINOS operating system.
Mod51 by Mandeno Granville Electronics is based on ISO Modula-2 with language extensions for embedded development followingIEC 1131, an industry standard forprogrammable logic controllers (PLC) closely related to Modula-2. The Mod51 compiler generates standalone code for 80C51 based microcontrollers.
Delco Electronics, then a subsidiary of GMHughes Electronics, developed a version of Modula-2 for embedded control systems starting in 1985. Delco named it Modula-GM. It was the firsthigh-level programming language used to replacemachine code (language) for embedded systems in Delco'sengine 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.[19] The first experimental use of Modula-GM in anembedded 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 theChamp Car World Series Championship Auto Racing Teams (CART) andIndy Racing League (IRL) teams.[20] The first production use of Modula-GM was its use in GM trucks starting with the 1990 model yearvehicle control module (VCM) used to manage GM Powertrain'sVortec 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 yearBuick Park Avenue. The Modula-GM compilers and associated software management tools were sourced by Delco fromIntermetrics.
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 formDelphi 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 languageC.
The satellites of the Russianradionavigation-satellite service frameworkGLONASS, similar to the United StatesGlobal Positioning System (GPS), are programmed in Modula-2.[21]
Turbo Modula-2 was a compiler and anintegrated development environment forMS-DOS developed, but not published, byBorland. 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 itsClarion product line at that time.[45]
AZilog Z80CP/M version of Turbo Modula-2 was briefly marketed by Echelon under license from Borland. A companion release forHitachi HD64180 was sold by Micromint as a development tool for their SB-180 single-board computer.[46]
IBM had a Modula-2 compiler for internal use which ran on bothOS/2 andAIX, and had first class support in IBM'sE2 editor.[47] IBM Modula-2 was used for parts of theOS/400Vertical Licensed Internal Code (effectively the kernel of OS/400).[48] This code was mostly replaced withC++ when OS/400 was ported to theIBM RS64 processor family, although some remains in modern releases of the operating system.[49][50] AMotorola 68000 backend also existed, which may have been used in embedded systems products.[47]
Modula-2 is used to program someoperating systems (OSs). The Modula-2 module structure and support are used directly in two related OSs.
The OS namedMedos-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.[51][52][53]
The OS namedExcelsior, for theKronos workstation, was developed by theAcademy 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.[54]
Photo of the floppy disk