GO-V.ORG
As seen in

Oberon-2

Oberon-2 is an extension of the original Oberon programming language that adds limited reflective programming (reflection) and object-oriented programming facilities, open arrays as pointer base types, read-only field export, and reintroduces the FOR loop from Modula-2. It was developed in 1991 at ETH Zurich by Niklaus Wirth and Hanspeter Mössenböck, who is now at Institut für Systemsoftware (SSW) of the University of Linz, Austria. Oberon-2 is a superset of Oberon, is fully compatible with it, and was a redesign of Object Oberon. Oberon-2 inherited limited reflection and single inheritance ("type extension") without the interfaces or mixins from Oberon, but added efficient virtual methods... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

Oberon-2 is an extension of the original Oberon programming language that adds limited reflective programming (reflection) and object-oriented programming facilities, open arrays as pointer base types, read-only field export, and reintroduces the FOR loop from Modula-2. It was developed in 1991 at ETH Zurich by Niklaus Wirth and Hanspeter Mössenböck, who is now at Institut für Systemsoftware (SSW) of the University of Linz, Austria. Oberon-2 is a superset of Oberon, is fully compatible with it, and was a redesign of Object Oberon. Oberon-2 inherited limited reflection and single inheritance ("type extension") without the interfaces or mixins from Oberon, but added efficient virtual methods ("type bound procedures"). Method calls were resolved at runtime using C++-style virtual method tables. Compared to fully object-oriented languages like Smalltalk, in Oberon-2, basic data types and classes are not objects, many operations are not methods, there is no message passing (it can be emulated somewhat by reflection and through message extension, as demonstrated in ETH Oberon), and polymorphism is limited to subclasses of a common class (no duck typing as in Python, and it's not possible to define interfaces as in Java). Oberon-2 does not support encapsulation at object or class level, but modules can be used for this purpose. Reflection in Oberon-2 does not use metaobjects, but simply reads from type descriptors compiled 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 the library 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 for garbage 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 in C and C++. Separate compiling using symbol files and namespaces via the module architecture ensure fast rebuilds since only modules with changed interfaces need to be recompiled. The language Component Pascal is a refinement (a superset) of Oberon-2. MODULE Trees; TYPE Tree* = POINTER TO Node; Node* = RECORD name-: POINTER TO ARRAY OF CHAR; left, right: Tree END; PROCEDURE (t: Tree) Insert* (name: ARRAY OF CHAR); VAR p, father: Tree; BEGIN p := t; REPEAT father := p; IF name = p.name^ THEN RETURN END; IF name MODULE Birds; TYPE Bird* = RECORD sound* : ARRAY 10 OF CHAR; END; END Birds. MODULE Ducks; IMPORT Birds; TYPE Duck* = RECORD (Birds.Bird) END; PROCEDURE SetSound* (VAR bird : Duck); BEGIN bird.sound := "Quack!" END SetSound; END Ducks. MODULE Cuckoos; IMPORT Birds; TYPE Cuckoo* = RECORD (Birds.Bird) END; PROCEDURE SetSound* (VAR bird : Cuckoo); BEGIN bird.sound := "Cuckoo!" END SetSound; END Cuckoos. MODULE Test; IMPORT Out, Birds, Cuckoos, Ducks; TYPE SomeBird* = RECORD (Birds.Bird) END; VAR sb : SomeBird; c : Cuckoos.Cuckoo; d : Ducks.Duck; PROCEDURE SetSound* (VAR bird : Birds.Bird); BEGIN WITH bird : Cuckoos.Cuckoo DO bird.sound := "Cuckoo!" | bird : Ducks.Duck DO bird.sound := "Quack!" ELSE bird.sound := "Tweet!" END END SetSound; PROCEDURE MakeSound* (VAR b : Birds.Bird); BEGIN Out.Ln; Out.String(b.sound); Out.Ln END MakeSound; BEGIN SetSound(c); SetSound(d); SetSound(sb); MakeSound(c); MakeSound(d); MakeSound(sb) END Test. MODULE PointerBirds; IMPORT Out; TYPE BirdRec* = RECORD sound* : ARRAY 10 OF CHAR; END; DuckRec* = RECORD (BirdRec) END; CuckooRec* = RECORD (BirdRec) END; Bird = POINTER TO BirdRec; Cuckoo = POINTER TO CuckooRec; Duck = POINTER TO DuckRec; VAR pb : Bird; pc : Cuckoo; pd : Duck; PROCEDURE SetDuckSound* (bird : Duck); BEGIN bird.sound := "Quack!" END SetDuckSound; PROCEDURE SetCuckooSound* (bird : Cuckoo); BEGIN bird.sound := "Cuckoo!" END SetCuckooSound; PROCEDURE SetSound* (bird : Bird); BEGIN WITH bird : Cuckoo DO SetCuckooSound(bird) | bird : Duck DO SetDuckSound(bird) ELSE bird.sound := "Tweet!" END END SetSound; BEGIN NEW(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.Ln END PointerBirds. A third approach is possible using the IS 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. 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 ["*" | "-"]. ==See also== A2 (operating system)

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Oberon-2". 1788703400. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1373548768

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·