Discussion:
is oberon-1 style oop supported in oberon-2?
(too old to reply)
noch
2006-02-22 14:41:28 UTC
Permalink
Hello.
I tried to compile with oo2c 2 and xds oberon-2 compiler following
source
(example of oop programming in oberon from
http://www.modulaware.com/mdltws.htm )

---

MODULE ooptest;
TYPE T = RECORD x, y: INTEGER END;
TYPE
T0 = RECORD (T) z: REAL END; (* extension of T *)
T1 = RECORD (T) w: LONGREAL END; (* extension of T *)
TYPE
action = PROCEDURE (a,b: INTEGER): INTEGER; (* a procedural type
*)
T2 = RECORD (T)
Add: action (* "Add" is a "method" of the T2 class *)
END;
VAR
object: T2; result: INTEGER;
BEGIN
object.x := 123; object.y := 456;
result := object.Add (object.x, object.y); (* method call *)
END ooptest.

---

It compiled without errors and warnings, but crashed on a line
result := object.Add (object.x, object.y);

Is it compilers fault or mine?

Thanks

Norayr
anonymus
2006-02-22 16:05:48 UTC
Permalink
Post by noch
I tried to compile with oo2c 2 and xds oberon-2 compiler following
source (example of oop programming in oberon from
http://www.modulaware.com/mdltws.htm )
---
MODULE ooptest;
TYPE T = RECORD x, y: INTEGER END;
TYPE
T0 = RECORD (T) z: REAL END; (* extension of T *)
T1 = RECORD (T) w: LONGREAL END; (* extension of T *)
TYPE
action = PROCEDURE (a,b: INTEGER): INTEGER; (* a procedural type
*)
T2 = RECORD (T)
Add: action (* "Add" is a "method" of the T2 class *)
END;
VAR
object: T2; result: INTEGER;
BEGIN
object.x := 123; object.y := 456;
result := object.Add (object.x, object.y); (* method call *)
END ooptest.
---
It compiled without errors and warnings, but crashed on the line
result := object.Add (object.x, object.y);
Is it compilers fault or mine?
Both, the compilers which generated the test and yours who programmed it that.
Post by noch
Thanks
You're wellcome.
Post by noch
Norayr
August Karlstrom
2006-02-22 16:48:50 UTC
Permalink
Post by noch
MODULE ooptest;
TYPE T = RECORD x, y: INTEGER END;
TYPE
T0 = RECORD (T) z: REAL END; (* extension of T *)
T1 = RECORD (T) w: LONGREAL END; (* extension of T *)
TYPE
action = PROCEDURE (a,b: INTEGER): INTEGER; (* a procedural type
*)
T2 = RECORD (T)
Add: action (* "Add" is a "method" of the T2 class *)
END;
VAR
object: T2; result: INTEGER;
BEGIN
object.x := 123; object.y := 456;
result := object.Add (object.x, object.y); (* method call *)
Here you will get a run-time error as you can't call a NIL procedure.


August
--
I am the "ILOVEGNU" signature virus. Just copy me to your
signature. This email was infected under the terms of the GNU
General Public License.
j***@yahoo.com
2006-02-23 17:15:34 UTC
Permalink
As someone else pointed out, you didn't initialize your procedure
variable.
O-1 style OOP is used extensively for System 3 "gadgets" programming.
Anyway, here's a working version of your module.

MODULE ooptest;
IMPORT
Out;

TYPE T = RECORD x, y: INTEGER END;
TYPE
T0 = RECORD (T) z: REAL END; (* extension of T *)
T1 = RECORD (T) w: LONGREAL END; (* extension of T *)
TYPE
action = PROCEDURE (a,b: INTEGER): INTEGER; (* a procedural type
*)
T2 = RECORD (T)
Add: action (* "Add" is a "method" of the T2 class *)
END;

VAR
object: T2; result: INTEGER;

PROCEDURE AddIt(a, b : INTEGER): INTEGER;
BEGIN
RETURN a + b;
END AddIt;

PROCEDURE Do*;
BEGIN
Out.Int(result, 5);
Out.Ln();
END Do;

BEGIN
object.x := 123; object.y := 456; object.Add := AddIt;
result := object.Add (object.x, object.y); (* method call *)
END ooptest.

Regards,

John M. Drake

Loading...