Modula-2

Modula -2 is a further development of the Pascal programming language created in 1978 and has been like this from Niklaus Wirth developed. Main features of Modula-2 are the language features for modularization of programs. Modula-2 itself later served as a template for the programming language Oberon.

  • 5.1 Qualifying imports
  • 5.2 Export of enumeration types
  • 5.3 Data type CARDINAL
  • 5.4 Type of transfer functions and other low-level devices

Formation

Wirth had 1977/78 at the Palo Alto Research Center Xerox Research Institute of the pioneering architecture of Alto workstations know that already like the mouse, graphical screen and window technology. It was programmed to the Alto in the Pascal - like programming language Mesa. After his return to the ETH Zurich Wirth began his own group, the development of such a workstation, which was later called Lilith, with hardware and software have been developed in the context.

Standard Pascal, which was developed as a language for teaching programming, was not suitable for programming an operating system for Lilith, notably for two reasons:

  • It lacks devices for concurrent programming
  • The division of a large program into numerous modules with clean interfaces defined according to the teachings of the software technology is not possible.

Therefore, the new language that was called the " modulation " contained, against Pascal ( amongst a number of changes in the syntax ), two new concepts:

  • Procedures NewProcess, TRANSFER and IOTRANSFER for the treatment of concurrent processes (threads ) in the sense of a cooperative multi-tasking and
  • The MODULE as a unit for the separate translation of parts of the program.

Modula was known outside the ETHZ only in version Modula -2. The clear separation of the definition and implementation in separate files (usually with extension DEF or MOD) was a pioneering and was indeed copied by later programming languages, but not reached in their clarity. Modula-2 was later independent of Wirth 's successor as Modula-2 and Modula - plus third Since 1996 there is an international standard ISO / IEC 10514-1 for Modula -2.

Properties

Since Modula-2 is an evolution of Pascal, it is sufficient to consider the important differences between this language.

Modules

The most prominent new feature in Modula -2, the modules as a device for the modular programming according to the ideas of software engineering, first proposed by David Parnas. Also, the main program is called so instead MODULE PROGRAM as in Pascal. All separately translated from the main program parts have to be split into two files: A DEFINITION MODULE contains only the description of the interface of the module, that is, it lists the constants, types, variables and procedures, which provided for other modules are available ( "exports " ) should be. A separate IMPLEMENTATION MODULE then the implementation.

It is logical in the sense of strict modularization that concepts such as Ein-/Ausgabe and mathematical functions that were in the normal Pascal language range in the language Modula-2 are not included. You have to be imported if necessary, prepare appropriate modules ( for Ein-/Ausgabe and MathLib for the mathematical functions usually InOut ).

Data types

The Lilith should get a word width of 16 bits. Whole numbers would have an area of -32,768 to 32,767 had what Wirth felt as too restrictive. In addition to the data type INTEGER got Modula-2, therefore, a data type CARDINAL for the non -negative numbers between 0 and 65,535. Mixed expressions that contain both INTEGER and CARDINAL subexpressions were prohibited. Therefore, there are general ways to transform types:

  • Type conversion functions VAL (type, expression) expected an expression so that it belongs to the new type, while
  • Type transfer functions ( "type casts" in Wirth: "type cheats ") of the form type (expression) can be a bit pattern unchanged and only change the data type for the compiler.

For example, results VAL ( CARDINAL, -1), an error message while CARDINAL (-1 ) = 65.535 applies.

An innovation compared with Pascal also provides the data type is PROCEDURE, with the weakness of Pascal should be fixed: In Pascal, it was possible, a procedure to pass a function as an argument, identified by the keyword FUNCTION. However, it could not be verified whether the later date passed function in the number and type of their parameters was ever suitable. Declaring, however, by way of example in Modula -2

TYPE myFunction = PROCEDURE (INTEGER ): REAL; so can when calling a procedure ( the keyword FUNCTION does not exist in Modula -2)

PROCEDURE myProcedure ( f: myFunction; n: INTEGER ): REAL; determine the compiler on each call to myProcedure whether the currently passed for f function has the correct type. Since procedures so are ordinary data types, it is also possible to incorporate them into other data structures such as arrays and records.

Control structures

To avoid many BEGIN - END brackets will be completed in Modula -2, the IF and WHILE statement each with an END. The familiar from Pascal GOTO does not exist, but a LOOP - EXIT construct.

The pseudo module SYSTEM

As a language for the operating system programming had to Modula-2 equipped with means to access details of the underlying machine. There were a separate module SYSTEM, from which the data types WORD could import for a non-specific memory word and ADDRESS for a memory address, as well as an ADR to determine the memory address of a construct function and TSIZE to determine the memory size for a given data type. Add to this the already mentioned features for concurrent programming.

Called a pseudo module SYSTEM, because it, neither definition nor is the implementation part, but all knowledge of this module is built directly into the compiler.

Development

There are two dialects of Modula -2. On one hand, PIM, developed by Niklaus Wirth and standard work "Programming in Modula -2" variants defined. According to the editions of the book there is the second, third and fourth variant of PIM. With each edition, the language has been changed slightly. The second dialect is ISO, which by an international committee developed ( under the auspices of the International Organization for Standardization) variant.

  • PIM2 (1983 ): Explicit EXPORT in definition modules.
  • PIM3 (1985 ): Explicit export in definition modules necessary.
  • PIM4 (1989 ): specification of the behavior of the MOD operator when the operands are negative.
  • ISO ( 1996): The demand for the development of ISO Modula-2 was to resolve the ambiguities of PIM -2 modulation. In addition, the language were the data types COMPLEX and COMPLEX LONG, exceptions (exceptions), added the Modultermination ( FINALLY clause) and an extensive standard library for input and output - in addition to a number of smaller changes.

Implementations

Modula-2 peaked in the late 1980s, a relatively wide popularity, especially in the version of Jensen and Partners International ( JPI ), which have a 10 - screen editor in their development environment for MS- DOS and a very fast compiler with well- optimized object code brought on the market. Later versions of it were called TopSpeed ​​Modula -2; in the development environment and C and C were added.

Current Modula-2 compiler:

  • Megamax Modula-2 - Atari ST ( e) ( MC68K )
  • Hänisch Modula-2 - Atari ST / TT ( MC68K )
  • Aglet Modula-2 - Amiga (PPC )
  • GNU Modula-2 - GNU compiler collection (GCC )
  • Objective Modula-2 - Cocoa and GNUstep support
  • XDS Modula-2 - Windows and Linux

Criticism

Wirth himself lists in connection with the development of Oberon following problems from Modula-2 to:

Qualifying imports

The recommended method for use of constituents of other modules is

IMPORT M; This all exported identifiers of M by so-called qualified identifiers, such as MA, MB are available. Alternatively knows Modula-2, the qualifying Import

M FROM IMPORT A, B; This import the identifiers are then available simply in the form of A or B; the origin of the module M is in place then no longer directly visible. This can make mistakes programmers. In Oberon there is the qualifying import therefore no longer.

Export of enumeration types

Contains the exported type a module

TYPE = traffic light (red, yellow, green); as concerns the logic of language, an import of that type only the type name (traffic light), but in reality the names are red, yellow and green mitimportiert, which in the case of Bezeichnerkonflikten in place to confuse the programmer. In Oberon there are enumerated types, therefore, no longer, because you'll also their export could not prevent it.

Data type CARDINAL

Unsigned arithmetic works quite differently as a signed arithmetic; therefore are expressions that contain unsigned and signed values ​​at the same time, problematic. Modula-2 has therefore those mixtures generally prohibited, which met with the programmers to protest because the programs have been unnecessarily complicated by the use of type conversion functions. Moreover, asymmetries arise in the treatment of certain program structures and in the mathematical modulo function (MOD ).

Type transfer functions and other low-level devices

With the type of transfer functions (type casts ) it is possible to discover properties of the underlying machine, which should give the programmer a high level language actually remain hidden, such as endianness, that is the question, the order in which the individual bits of a machine word are stored. Depending on is in fact

BITSET ( 65520 ) = { 4 .. 15} or

BITSET ( 65520 ) = { 0 .. 11} for a 16- bit architecture.

577797
de