Modula-3
Modula-3 is a programming language conceived as a successor to an upgraded version of Modula-2 known as Modula-2+. It has been influential in research circles (influencing the designs of languages such as Java, C#, Python[8] and Nim), but it has not been adopted widely in industry. It was designed by Luca Cardelli, James Donahue, Lucille Glassman, Mick Jordan (before at the Olivetti Software Technology Laboratory), Bill Kalsow and Greg Nelson at the Digital Equipment Corporation (DEC) Systems Research Center (SRC) and the Olivetti Research Center (ORC) in the late 1980s. Modula-3's main features are modularity, simplicity and safety while preserving the power of a systems-programming language. Modula-3 aimed to continue the Pascal tradition of type safety, while introducing new constructs for practical real-world programming. In particular Modula-3 added support for generic programming (similar to templates), multithreading, exception handling, garbage collection, object-oriented programming, partial revelation, and explicit marking of unsafe code. The design goal of Modula-3 was a language that implements the most important features of modern imperative programming languages in quite basic forms. Thus allegedly dangerous and complicating features such as multiple inheritance and operator overloading were omitted. Historical developmentThe Modula-3 project started in November 1986 when Maurice Wilkes wrote to Niklaus Wirth with some ideas for a new version of Modula. Wilkes had been working at DEC just prior to this point, and had returned to England and joined Olivetti's Research Strategy Board. Wirth had already moved on to Oberon, but had no problems with Wilkes's team continuing development under the Modula name. The language definition was completed in August 1988, and an updated version in January 1989. Compilers from DEC and Olivetti soon followed, and 3rd party implementations after that. Its design was heavily influenced by work on the Modula-2+ language in use at SRC and at the Acorn Computers Research Center (ARC, later ORC when Olivetti acquired Acorn) at the time, which was the language in which the operating system for the DEC Firefly multiprocessor VAX workstation was written and in which the Acorn Compiler for Acorn C and Modula Execution Library (CAMEL) at ARC for the ARX operating system project of ARM based Acorn Archimedes range of computers was written. As the revised Modula-3 Report states, the language was influenced by other languages such as Mesa, Cedar, Object Pascal, Oberon and Euclid.[9] During the 1990s, Modula-3 gained considerable currency as a teaching language, but it was never widely adopted for industrial use. Contributing to this may have been the demise of DEC, a key Modula-3 supporter (especially when it ceased to maintain it effectively before DEC was sold to Compaq in 1998). In any case, in spite of Modula-3's simplicity and power, it appears that there was little demand for a procedural compiled language with restricted implementation of object-oriented programming. For a time, a commercial compiler named CM3 maintained by one of the chief implementors prior at DEC SRC who was hired before DEC being sold to Compaq, an integrated development environment (IDE) named Reactor and an extensible Java virtual machine (licensed in binary code and source code formats and buildable with Reactor) were offered by Critical Mass, Inc., but that company ceased active operations in 2000 and gave some of the source code of its products to elego Software Solutions GmbH. Modula-3 is now taught in universities mostly in comparative programming language courses, and its textbooks are out of print. Essentially the only corporate supporter of Modula-3 is elego, which inherited the sources from Critical Mass and has since made several releases of the CM3 system in source and binary code. The Reactor IDE has been open source released after several years it had not, with the new name CM3-IDE. In March 2002, elego also took over the repository of another active Modula-3 distribution, PM3, until then maintained at the École Polytechnique de Montréal but which later continued by the work on HM3 improved over the years later until it was obsoleted. Syntax
A common example of a language's syntax is the "Hello, World!" program. MODULE Main;
IMPORT IO;
BEGIN
IO.Put("Hello World\n")
END Main.
All programs in Modula-3 have at least a module file, while most also include an interface file that is used by clients to access data from the module. As in some other languages, a Modula-3 program must export a Main module, which can either be a file named Main.m3, or a file can call MODULE Foo EXPORTS Main
Module file names are advised to be the same as the name in source code. If they differ, the compiler only emits a warning. Other conventions in the syntax include naming the exported type of an interface Language featuresModularityFirst and foremost, all compiled units are either MODULE HelloWorld EXPORTS Main;
IMPORT IO;
BEGIN
IO.Put("Hello World\n")
END HelloWorld.
Any compiled unit may MODULE HelloWorld EXPORTS Main;
FROM IO IMPORT Put;
BEGIN
Put("Hello World\n")
END HelloWorld.
Typically, one only imports the interface, and uses the 'dot' notation to access the items within the interface (similar to accessing the fields within a record). A typical use is to define one data structure (record or object) per interface along with any support procedures. Here the main type will get the name 'T', and one uses as in In the event of a name collision between an imported module and other entity within the module, the reserved word
Safe vs unsafeSome ability is deemed unsafe, where the compiler can no longer guarantee that results will be consistent; for example, when interfacing to the C language. The keyword An interface that imports an unsafe module must also be unsafe. A safe interface may be exported by an unsafe implementation module. This is the typical use when interfacing to external libraries, where two interfaces are built: one unsafe, the other safe. GenericsA generic interface and its corresponding generic module,
prefix the For example, one could define a GenericStack, then instantiate it with interfaces such as The bare types FILE: IntegerElem.i3 INTERFACE IntegerElem;
CONST Name = "Integer";
TYPE T = INTEGER;
PROCEDURE Format(x: T): TEXT;
PROCEDURE Scan(txt: TEXT; VAR x: T): BOOLEAN;
END IntegerElem.
FILE: GenericStack.ig GENERIC INTERFACE GenericStack(Element);
(* Here Element.T is the type to be stored in the generic stack. *)
TYPE
T = Public OBJECT;
Public = OBJECT
METHODS
init(): TStack;
format(): TEXT;
isEmpty(): BOOLEAN;
count(): INTEGER;
push(elm: Element.T);
pop(VAR elem: Element.T): BOOLEAN;
END;
END GenericStack.
FILE: GenericStack.mg GENERIC MODULE GenericStack(Element);
< ... generic implementation details... >
PROCEDURE Format(self: T): TEXT =
VAR
str: TEXT;
BEGIN
str := Element.Name & "Stack{";
FOR k := 0 TO self.n -1 DO
IF k > 0 THEN str := str & ", "; END;
str := str & Element.Format(self.arr[k]);
END;
str := str & "};";
RETURN str;
END Format;
< ... more generic implementation details... >
END GenericStack.
FILE: IntegerStack.i3 INTERFACE IntegerStack = GenericStack(IntegerElem) END IntegerStack.
FILE: IntegerStack.m3 MODULE IntegerStack = GenericStack(IntegerElem) END IntegerStack.
TraceabilityAny identifier can be traced back to where it originated, unlike the 'include' feature of other languages. A compiled unit must import identifiers from other compiled units, using an INTERFACE A;
TYPE Color = {Black, Brown, Red, Orange, Yellow, Green, Blue, Violet, Gray, White};
END A;
MODULE B;
IMPORT A;
FROM A IMPORT Color;
VAR
aColor: A.Color; (* Uses the module name as a prefix *)
theColor: Color; (* Does not have the module name as a prefix *)
anotherColor: A.Color;
BEGIN
aColor := A.Color.Brown;
theColor := Color.Red;
anotherColor := Color.Orange; (* Can't simply use Orange *)
END B.
Dynamic allocationModula-3 supports the allocation of data at runtime. There are two kinds of memory that can be allocated, Object-orientedObject-oriented programming techniques may be used in Modula-3, but their use is not a requirement. Many of the other features provided in Modula-3 (modules, generics) can usually take the place of object-orientation. Object support is intentionally kept to its simplest terms. An object type (termed a "class" in other object-oriented languages) is introduced with the INTERFACE Person;
TYPE T <: Public;
Public = OBJECT
METHODS
getAge(): INTEGER;
init(name: TEXT; age: INTEGER): T;
END;
END Person.
This defines an interface To create a new VAR jim := NEW(Person.T).init("Jim", 25);
RevelationModula-3's MODULE Person;
REVEAL T = Public BRANDED
OBJECT
name: TEXT; (* These two variables *)
age: INTEGER; (* are private. *)
OVERRIDES
getAge := Age;
init := Init;
END;
PROCEDURE Age(self: T): INTEGER =
BEGIN
RETURN self.age;
END Age;
PROCEDURE Init(self: T; name: TEXT; age: INTEGER): T =
BEGIN
self.name := name;
self.age := age;
RETURN self;
END Init;
BEGIN
END Person.
Note the use of the Modula-3 is one of a few programming languages which requires external references from a module to be strictly qualified. That is, a reference in module Because of the language's requirements on name qualification and method overriding, it is impossible to break a working program simply by adding new declarations to an interface (any interface). This makes it possible for large programs to be edited concurrently by many programmers with no worries about naming conflicts; and it also makes it possible to edit core language libraries with the firm knowledge that no extant program will be broken in the process. ExceptionsException handling is based on a Multi-threadedThe language supports the use of multi-threading, and synchronization between threads. There is a standard module within the runtime library (m3core) named Thread, which supports the use of multi-threaded applications. The Modula-3 runtime may make use of a separate thread for internal tasks such as garbage collection. A built-in data structure For example, in the input/output (I/O) section of the library libm3, readers and writers (Rd.T, and Wr.T) are derived from MUTEX, and they lock themselves before accessing or modifying any internal data such as buffers. SummaryIn summary, the language features:
In Systems Programming with Modula-3, four essential points of the language design are intensively discussed. These topics are: structural vs. name equivalence, subtyping rules, generic modules, and parameter modes like Standard library featuresContinuing a trend started with the C language, many of the features needed to write real programs were left out of the language definition and instead provided via a standard library set. Most of the interfaces below are described in detail in[11] Standard libraries providing the following features. These are called standard interfaces and are required (must be provided) in the language.
Some recommended interfaces implemented in the available implementations but are not required
As in C, I/O is also provided via libraries, in Modula-3 called ImplementationsSeveral compilers are available, most of them open source.
Since the only aspect of C data structures that is missing from Modula-3 is the union type, all extant Modula-3 implementations are able to provide good binary code compatibility with C language type declarations of arrays and structs. BooksNone of these books are still in print, although used copies are obtainable and some are digitized, partly or fully, and some chapters of one them have prior or posterior versions obtainable as research reports from the web.
Projects using Modula-3Software which is programmed with Modula-3 includes:
Influences on other programming languagesAlthough Modula-3 did not gain mainstream status, several parts of the DEC-SRC M3 distribution did. Probably the most influential part was the Network Objects library, which formed the basis for Java's first Remote Method Invocation (RMI) implementation, including the network protocol. Only when Sun moved from the Common Object Request Broker Architecture (CORBA) standard to the IIOP based protocol was it dropped. The Java documentation on garbage collection of remote objects still refer to the pioneering work done for Modula-3 Network Objects.[23] Python's implementation of classes was also inspired by the class mechanism found in C++ and Modula-3.[24] Also the language Nim makes use of some aspects of Modula-3, such as traced vs untraced pointers. References
External links
|
Portal di Ensiklopedia Dunia