Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Oberon-2

From Wikipedia, the free encyclopedia
Programming language
This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages)
icon
This articlerelies excessively onreferences toprimary sources. Please improve this article by addingsecondary or tertiary sources.
Find sources: "Oberon-2" – news ·newspapers ·books ·scholar ·JSTOR
(April 2011) (Learn how and when to remove this message)
This article'suse ofexternal links may not follow Wikipedia's policies or guidelines. Pleaseimprove this article by removingexcessive orinappropriate external links, and converting useful links where appropriate intofootnote references.(February 2024) (Learn how and when to remove this message)
(Learn how and when to remove this message)

Oberon-2
ParadigmsImperative,structured,modular,object-oriented
FamilyWirthOberon
Designed byNiklaus Wirth
Hanspeter Mössenböck
DeveloperETH Zurich
First appeared1991; 35 years ago (1991)
Typing disciplineStrong, hybrid (static anddynamic)
ScopeLexical
PlatformCeres (NS32032),IA-32,x86-64
OSWindows,Linux,Solaris,macOS
Websitewww.ethoberon.ethz.ch
Influenced by
Oberon,Modula-2,Object Oberon
Influenced
Oberon-07,Zonnon,Active Oberon,Component Pascal,Go,Nim

Oberon-2 is an extension of the originalOberonprogramming language that adds limitedreflective programming (reflection) andobject-oriented programming facilities, openarrays as pointer base types, read-only field export, and reintroduces theFOR loop fromModula-2.

It was developed in 1991 atETH Zurich byNiklaus Wirth andHanspeter Mössenböck, who is now at Institut für Systemsoftware (SSW) of theUniversity of Linz, Austria. Oberon-2 is a superset of Oberon, is fully compatible with it, and was a redesign ofObject Oberon.

Oberon-2 inherited limited reflection and singleinheritance ("type extension") without the interfaces ormixins from Oberon, but added efficient virtualmethods ("type bound procedures"). Method calls were resolved atruntime usingC++-style virtual method tables.

Compared to fully object-oriented languages likeSmalltalk, in Oberon-2, basicdata types andclasses are notobjects, many operations are not methods, there is nomessage passing (it can be emulated somewhat by reflection and through message extension, as demonstrated in ETH Oberon), andpolymorphism is limited to subclasses of a common class (noduck typing as inPython,[1] and it's not possible to define interfaces as inJava). Oberon-2 does not supportencapsulation at object or class level, but modules can be used for this purpose.

Reflection in Oberon-2 does not usemetaobjects, but simply reads from type descriptorscompiled into the executable binaries, and exposed in the modules that define the types and/or procedures. If the format of these structures are exposed at the language level (as is the case for ETH Oberon, for example), reflection could be implemented at thelibrary level. It could thus be implemented almost entirely at library level, without changing the language code. Indeed, ETH Oberon makes use of language-level and library-level reflection abilities extensively.

Oberon-2 provides built-in runtime support forgarbage collection similar to Java and performs bounds and array index checks, etc., that eliminate the potential stack and array bounds overwriting problems and manual memory management issues inherent inC and C++. Separate compiling using symbol files andnamespaces via the module architecture ensure fast rebuilds since only modules with changed interfaces need to be recompiled.

The languageComponent Pascal[2] is a refinement (a superset) of Oberon-2.

Example code

[edit]

The following Oberon-2 code implements a simple binary tree:

MODULETrees;TYPETree*=POINTERTONode;Node*=RECORDname-:POINTERTOARRAYOFCHAR;left,right:TreeEND;PROCEDURE(t:Tree)Insert*(name:ARRAYOFCHAR);VARp,father:Tree;BEGINp:=t;REPEATfather:=p;IFname=p.name^THENRETURNEND;IFname<p.name^THENp:=p.leftELSEp:=p.rightENDUNTILp=NIL;NEW(p);p.left:=NIL;p.right:=NIL;NEW(p.name,LEN(name)+1);COPY(name,p.name^);IFname<father.name^THENfather.left:=pELSEfather.right:=pENDENDInsert;PROCEDURE(t:Tree)Search*(name:ARRAYOFCHAR):Tree;VARp:Tree;BEGINp:=t;WHILE(p#NIL)&(name#p.name^)DOIFname<p.name^THENp:=p.leftELSEp:=p.rightENDEND;RETURNpENDSearch;PROCEDURENewTree*():Tree;VARt:Tree;BEGINNEW(t);NEW(t.name,1);t.name[0]:=0X;t.left:=NIL;t.right:=NIL;RETURNtENDNewTree;ENDTrees.

Oberon-2 extensions to Oberon

[edit]

Source:[3]

Type-bound procedures

[edit]

Procedures can be bound to a record (or pointer) type. They are equivalent to instance methods in object-oriented terminology.

Read-only export

[edit]

The use of exported variables and record fields can be restricted to read-only access. This is shown with a "-" visibility flag.

Open arrays

[edit]

Open arrays which formerly could only be declared as formal parameter types may now be declared as pointer base types.

FOR statement

[edit]

TheFOR statement of Pascal and Modula-2 was not implemented in Oberon. It is reintroduced in Oberon-2.

Runtime type checking

[edit]

Oberon-2 provides several mechanisms for checking thedynamic type of an object. For example, where a Bird object might be instantiated to either a Duck or a Cuckoo, Oberon-2 allows the programmer to respond to the actual type of the object at runtime.

The first, most conventional, approach is to rely on thetype binding system. The second approach is to use theWITH statement, which allows the dynamicsubtype of a variable to be checked directly. In both cases, once the subtype has been identified, the programmer can make use of any type-bound procedures or variables that are appropriate to the subtype. Examples of these approaches are shown below.

Note that the form ofWITH statement used in Oberon-2 is unrelated to the Pascal and Modula-2 WITH statement. This method of abbreviating access to record fields is not implemented in Oberon or Oberon-2.

Type binding

[edit]
MODULEBirds;TYPEBird*=RECORDsound*:ARRAY10OFCHAR;END;ENDBirds.MODULEDucks;IMPORTBirds;TYPEDuck*=RECORD(Birds.Bird)END;PROCEDURESetSound*(VARbird:Duck);BEGINbird.sound:="Quack!"ENDSetSound;ENDDucks.MODULECuckoos;IMPORTBirds;TYPECuckoo*=RECORD(Birds.Bird)END;PROCEDURESetSound*(VARbird:Cuckoo);BEGINbird.sound:="Cuckoo!"ENDSetSound;ENDCuckoos.

WITH statement

[edit]
MODULETest;IMPORTOut,Birds,Cuckoos,Ducks;TYPESomeBird*=RECORD(Birds.Bird)END;VARsb:SomeBird;c:Cuckoos.Cuckoo;d:Ducks.Duck;PROCEDURESetSound*(VARbird:Birds.Bird);BEGINWITHbird:Cuckoos.CuckooDObird.sound:="Cuckoo!"|bird:Ducks.DuckDObird.sound:="Quack!"ELSEbird.sound:="Tweet!"ENDENDSetSound;PROCEDUREMakeSound*(VARb:Birds.Bird);BEGINOut.Ln;Out.String(b.sound);Out.LnENDMakeSound;BEGINSetSound(c);SetSound(d);SetSound(sb);MakeSound(c);MakeSound(d);MakeSound(sb)ENDTest.

POINTER

[edit]
MODULEPointerBirds;IMPORTOut;TYPEBirdRec*=RECORDsound*:ARRAY10OFCHAR;END;DuckRec*=RECORD(BirdRec)END;CuckooRec*=RECORD(BirdRec)END;Bird=POINTERTOBirdRec;Cuckoo=POINTERTOCuckooRec;Duck=POINTERTODuckRec;VARpb:Bird;pc:Cuckoo;pd:Duck;PROCEDURESetDuckSound*(bird:Duck);BEGINbird.sound:="Quack!"ENDSetDuckSound;PROCEDURESetCuckooSound*(bird:Cuckoo);BEGINbird.sound:="Cuckoo!"ENDSetCuckooSound;PROCEDURESetSound*(bird:Bird);BEGINWITHbird:CuckooDOSetCuckooSound(bird)|bird:DuckDOSetDuckSound(bird)ELSEbird.sound:="Tweet!"ENDENDSetSound;BEGINNEW(pc);NEW(pd);SetCuckooSound(pc);SetDuckSound(pd);Out.Ln;Out.String(pc^.sound);Out.Ln;Out.Ln;Out.String(pd^.sound);Out.Ln;SetSound(pc);SetSound(pd);Out.Ln;Out.String(pc^.sound);Out.Ln;Out.Ln;Out.String(pd^.sound);Out.Ln;(* -------------------------------------- *)(* Pass dynamic type to procedure         *)pb:=pd;SetDuckSound(pb(Duck));Out.Ln;Out.String(pb^.sound);Out.Ln;pb:=pc;SetCuckooSound(pb(Cuckoo));Out.Ln;Out.String(pb^.sound);Out.Ln;(* -------------------------------------- *)SetSound(pb);Out.Ln;Out.String(pb^.sound);Out.Ln;pb:=pd;SetSound(pb);Out.Ln;Out.String(pb^.sound);Out.Ln;(* -------------------------------------- *)NEW(pb);SetSound(pb);Out.Ln;Out.String(pb^.sound);Out.LnENDPointerBirds.

IS operator

[edit]

A third approach is possible using theIS operator. This is a relation operator with the same precedence as equals (=), greater (>), etc. but which tests dynamic type. Unlike the two other approaches, however, it does not allow the programmer access to the subtype that has been detected.

Syntax

[edit]

The development of theALGOLPascalModula-2 → Oberon →Component Pascal language family is marked by areduction in the complexity of thelanguage syntax. The entire Oberon-2 language is described (Mössenböck & Wirth, March 1995) using only 33 grammatical productions in theextended Backus–Naur form, as shown below.

Module=MODULE ident";"[ImportList]DeclSeq[BEGIN StatementSeq]END ident".".ImportList=IMPORT[ident":="]ident{","[ident":="]ident}";".DeclSeq={CONST{ConstDecl";"}|TYPE{TypeDecl";"}|VAR{VarDecl";"}}{ProcDecl";"|ForwardDecl";"}.ConstDecl=IdentDef"="ConstExpr.TypeDecl=IdentDef"="Type.VarDecl=IdentList":"Type.ProcDecl=PROCEDURE[Receiver]IdentDef[FormalPars]";"DeclSeq[BEGIN StatementSeq]END ident.ForwardDecl=PROCEDURE"^"[Receiver]IdentDef[FormalPars].FormalPars="("[FPSection{";"FPSection}]")"[":"Qualident].FPSection=[VAR]ident{","ident}":"Type.Receiver="("[VAR]ident":"ident")".Type=Qualident|ARRAY[ConstExpr{","ConstExpr}]OF Type|RECORD["("Qualident")"]FieldList{";"FieldList}END|POINTER TO Type|PROCEDURE[FormalPars].FieldList=[IdentList":"Type].StatementSeq=Statement{";"Statement}.Statement=[Designator":="Expr|Designator["("[ExprList]")"]|IF Expr THEN StatementSeq{ELSIF Expr THEN StatementSeq}[ELSE StatementSeq]END|CASE Expr OF Case{"|"Case}[ELSE StatementSeq]END|WHILE Expr DO StatementSeq END|REPEAT StatementSeq UNTIL Expr|FOR ident":="Expr TO Expr[BY ConstExpr]DO StatementSeq END|LOOP StatementSeq END|WITH Guard DO StatementSeq{"|"Guard DO StatementSeq}[ELSE StatementSeq]END|EXIT|RETURN[Expr]].Case=[CaseLabels{","CaseLabels}":"StatementSeq].CaseLabels=ConstExpr[".."ConstExpr].Guard=Qualident":"Qualident.ConstExpr=Expr.Expr=SimpleExpr[Relation SimpleExpr].SimpleExpr=["+"|"-"]Term{AddOp Term}.Term=Factor{MulOp Factor}.Factor=Designator["("[ExprList]")"]|number|character|string|NIL|Set|"("Expr")"|"~"Factor.Set="{"[Element{","Element}]"}".Element=Expr[".."Expr].Relation="="|"#"|"<"|"<="|">"|">="|IN|IS.AddOp="+"|"-"|OR.MulOp="*"|"/"|DIV|MOD|"&".Designator=Qualident{"."ident|"["ExprList"]"|"^"|"("Qualident")"}.ExprList=Expr{","Expr}.IdentList=IdentDef{","IdentDef}.Qualident=[ident"."]ident.IdentDef=ident["*"|"-"].

Implementations

[edit]

Oberon-2 compilers maintained byETH include versions forWindows,Linux,Solaris,macOS.

TheOxford Oberon-2 compiler compiles to native machine code and can use a JIT on Windows, Linux, and macOS. It is created and maintained byMike Spivey and uses the Keiko Virtual Machine.[4][5]

There is an Oberon-2Lex scanner andYaccparser by Stephen J. Bevan of Manchester University, UK, based on the one in the Mössenböck and Wirth reference. It is at version 1.4.

There is a release namedNative Oberon which includes an operating system, and can directly boot on PC class hardware.

A.NET implementation of Oberon with the addition of some minor .NET-related extensions has been developed at ETHZ.

Programmer's Open Workbench (POW!)[6] is a very simpleintegrated development environment, which is provided with editor, linker, and Oberon-2 compiler. This compiles toWindows executables. Fullsource code is provided; the compiler is written in Oberon-2.

TheJava to Oberon Compiler (JOB) was written at the University of Vologda in Russia. It produces object code in the form of Java class files (bytecode). Some JOB-specific classes are provided which are Java compatible, but which use a more Oberon-like component hierarchy.

TheOptimizing Oberon-2 Compiler compiles to C, using theGNU Compiler Collection (GCC) toolchain for program generation.

Oberon Script is a compiler that translates the full Oberon language intoJavaScript. The compiler is written in JavaScript and can thus be called from Web pages to process scripts written in Oberon.

XDS Modula2/Oberon2 is a development system by Excelsior LLC, Novosibirsk, Russia. It contains an optimizing compiler for IntelPentium, or "via-C" translator forcross-platform software development. Available for Windows and Linux. The compiler is written in Oberon-2 and compiles itself.

Oberon Revival is a project to bring Oberon 2 andComponent Pascal (BlackBox Component Builder) to Linux and Win32. The Linux port of BlackBox was unavailable before and it originally ran on only Microsoft Windows.

XOberon is areal-time operating system forPowerPC, written in Oberon-2.

The Portable Oberon-2 Compiler (OP2) was developed to port theOberon System onto commercially available platforms.[7]

Keiko bytecode

[edit]

Oberon-2 can target the Keiko Virtual machine.[8][9]For example, like some other language compilers (seeO-code,p-code, etc.),theOxford Oberon-2 compiler first compiles to an intermediate bytecode (Keiko bytecode) which can be interpreted with a byte-code interpreter or usejust-in-time compilation.

See also

[edit]

References

[edit]
  1. ^"Related Reading".Dr. Dobb's.
  2. ^Pfister, Cuno (2001)."What's New in Component Pascal (changes from Oberon-2 to CP)"(PDF).Oberon microsystems. Archived fromthe original(PDF) on 15 May 2011. Retrieved10 January 2007.
  3. ^Differences between Oberon and Oberon-2, Mössenböck and Wirth (1993)
  4. ^Spivey, Michael (2014).Specification of Keiko.Spivey's Corner (Report). Oriel College, University of Oxford. Archived fromthe original on 4 March 2016. Retrieved9 July 2023.
  5. ^Spivey, Michael (30 September 2020).Design overview for OBC: The Keiko Abstract Machine.Spivey's Corner (Report). Oriel College, University of Oxford. Retrieved9 July 2023.The Oxford Oberon-2 compiler translates source programs into code for a stack-based abstract machine. ... the Keiko machine.
  6. ^Collingbourne, H. (February 2000). "What Pascal's inventor did next".PC Plus. No. 160.
  7. ^Crelier, Régis (1994).Separate Compilation and Module Extension (PhD). ETH Zurich.doi:10.3929/ethz-a-000945227.hdl:20.500.11850/141604. Retrieved18 November 2018.
  8. ^Dr. Michael Spivey."Specification of Keiko".
  9. ^Dr. Michael Spivey."Design overview for OBC: The Keiko Abstract Machine".quote:"The Oxford Oberon--2 compiler translates source programs into code for a stack-based abstract machine... the Keiko machine"

Further reading

[edit]
Wikibooks has a book on the topic of:Oberon

External links

[edit]
Modula
By Wirth
Modula (1975) →Modula-2 (1978)
By others
Operating systems
Workstations
Developers
Organizations
People
Oberon
By Wirth
Oberon (1987) →Oberon-2 (1991) →Lola (1995) →Active Oberon (1998) →Oberon-07 (2007)
Operating
systems
Workstation
Ceres (1985)
By others
Developers
Organizations
People
Categories:ModulaOberon
Software
Programming
languages
Euler (1965) →PL360 (1966) →ALGOL W (1966) →Pascal (1970) →Modula (1975) →Modula-2 (1978) →Object Pascal (1986) →Oberon (1987) →Oberon-2 (1991) →Lola (1995) →Active Oberon (1998) →Oberon-07 (2007)
Operating
systems
Formalisms
Books
Workstations
Lilith (1977) →Ceres (1985)
Workplaces
Collaborators
Awards
Retrieved from "https://en.wikipedia.org/w/index.php?title=Oberon-2&oldid=1320902140"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp