Hi, Just realised when Pictures type is extended from Bitmaps, Bitmaps.New(P,..) needs to accept pointer to its `superclass', otherwise some type members are duplicated. Correct??? I need to to be also explained, what we call `superclass', `baseclass' in Oberon terminology. Order of type extension: T1 -> T2 (T1) -> T3 (T2).. Tn(Tm) Order of type creation: M1.New(T2,..) <- M2.New(T3,..) <- .. Mn.New(Tm,..) For the reason above I use two New procedures in Bitmaps: PROCEDURE Bitmaps.New(w, h, dpt) : Bitmaps; PROCEDURE Bitmaps.New2(B: Bitmap; w, h, dpt) : Bitmaps; Is there a better recommended naming standard for this, than the above? Many thanks. -- Tomas Kral <thomas.kral@email.cz>
On 2017-10-01 18:57, Tomas Kral wrote:
Just realised when Pictures type is extended from Bitmaps, Bitmaps.New(P,..) needs to accept pointer to its `superclass', otherwise some type members are duplicated. Correct???
I need to to be also explained, what we call `superclass', `baseclass' in Oberon terminology.
Order of type extension: T1 -> T2 (T1) -> T3 (T2).. Tn(Tm)
Order of type creation: M1.New(T2,..) <- M2.New(T3,..) <- .. Mn.New(Tm,..)
For the reason above I use two New procedures in Bitmaps:
PROCEDURE Bitmaps.New(w, h, dpt) : Bitmaps; PROCEDURE Bitmaps.New2(B: Bitmap; w, h, dpt) : Bitmaps;
Is there a better recommended naming standard for this, than the above?
If I'm not mistaken the common approach is to separate memory allocation and initialization like this: Picture = POINTER TO RECORD w, h: INTEGER END Bitmap = POINTER TO RECORD (Picture) (*...*) END PROCEDURE InitPicture(p: Picture; w, h: INTEGER); BEGIN p.w := w; p.h := h END InitPicture PROCEDURE InitBitmap(b: Bitmap; w, h: INTEGER); BEGIN InitPicture(b, w, h) (*...*) END InitBitmap PROCEDURE Test; VAR bitmap: Bitmap; BEGIN NEW(bitmap); InitBitmap(bitmap, 100, 100) END Test -- August
On Sun, 1 Oct 2017 20:23:21 +0200 August Karlstrom <fusionfile@gmail.com> wrote:
common approach is to separate memory allocation and initialization
Hi, I would know the reason for separating. As FPGA { Oberon-07, V5 } is about building system from scratch while making it simple, we could possibly also experiment with new tricks here. I have therefore merged these procedures into one.
PROCEDURE Bitmaps.New(w, h, dpt) : Bitmaps; PROCEDURE Bitmaps.New2(B: Bitmap; w, h, dpt) : Bitmaps;
PROCEDURE New*(B: Bitmap; w, h, dpt: INTEGER) : Bitmap; BEGIN IF B = NIL THEN NEW(B) END; (* create itself *) IF B # NIL THEN (* initialise itself *) (* ... *) (* allocate itself *) END RETURN B END New; VAR b: Bitmap; p: Picture b := Bitmaps.New(NIL, w, h, 1); (* creating bitmap *) NEW(b); Bitmaps.New(b, w, h, 1); (* also creating bitmap *) NEW(p); p := Bitmaps.New(p, w, h, 1); (* creating picture *) Seems simple, does the job, bad idea? -- Tomas Kral <thomas.kral@email.cz>
On Sun, 1 Oct 2017 20:23:21 +0200 August Karlstrom <fusionfile@gmail.com> wrote:
common approach is to separate memory allocation and initialization
Hi, EDIT(1) I would NOT know the reason for separating. As FPGA { Oberon-07, V5 } is about building system from scratch while making it simple, we could possibly also experiment with new tricks here. I have therefore merged these procedures into one.
PROCEDURE Bitmaps.New(w, h, dpt) : Bitmaps; PROCEDURE Bitmaps.New2(B: Bitmap; w, h, dpt) : Bitmaps;
PROCEDURE New*(B: Bitmap; w, h, dpt: INTEGER) : Bitmap; BEGIN IF B = NIL THEN NEW(B) END; (* create itself *) IF B # NIL THEN (* initialise itself *) (* ... *) (* allocate itself *) END RETURN B END New; VAR b: Bitmap; p: Picture b := Bitmaps.New(NIL, w, h, 1); (* creating bitmap *) NEW(b); Bitmaps.New(b, w, h, 1); (* also creating bitmap *) NEW(p); p := Bitmaps.New(p, w, h, 1); (* creating picture *) Seems simple, does the job, bad idea? -- Tomas Kral <thomas.kral@email.cz>
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Monday, 2 October 2017 9:01 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - Pictures.Mod composition
On Sun, 1 Oct 2017 20:23:21 +0200 August Karlstrom <fusionfile@gmail.com> wrote:
I would NOT know the reason for separating. As FPGA { Oberon-07, V5 } is about building system from scratch while making it simple, we could possibly also experiment with new tricks here. I have therefore merged these procedures into one.
See chapter 8.1 'Initialization of Objects' in Hanspeter Mossenbock's book 'Object-Oriented Programming in Oberon-2' for the reason. You can download it from: http://ssw.jku.at/Research/Books (scroll down). The direct link is http://ssw.jku.at/Research/Books/Oberon2.pdf (5.9Mb file) Although the book is about Oberon-2, the examples in this section can also be used in Oberon-07. Regards, Chris Burrows CFB Software http://www.astrobe.com
On Mon, 2 Oct 2017 21:22:56 +1030 Chris Burrows <chris@cfbsoftware.com> wrote:
See chapter 8.1 'Initialization of Objects' in Hanspeter Mossenbock's book Hi Chris, Have had the book already, just did not have enough motivation to read, apart from PO2013 docs. Now I seem to have. Thank you.
-- Tomas Kral <thomas.kral@email.cz>
On Sun, 1 Oct 2017 20:23:21 +0200 August Karlstrom <fusionfile@gmail.com> wrote:
common approach is to separate memory allocation and initialization
Hi, I would know the reason for separating. As FPGA { Oberon-07, V5 } is about building system from scratch while making it simple, we could possibly also experiment with new tricks here. I have therefore merged these procedures into one.
PROCEDURE Bitmaps.New(w, h, dpt) : Bitmaps; PROCEDURE Bitmaps.New2(B: Bitmap; w, h, dpt) : Bitmaps;
PROCEDURE New*(B: Bitmap; w, h, dpt: INTEGER) : Bitmap; BEGIN IF B = NIL THEN NEW(B) END; (* create itself *) IF B # NIL THEN (* initialise itself *) (* ... *) (* allocate itself *) END RETURN B END New; VAR b: Bitmap; p: Picture b := Bitmaps.New(NIL, w, h, 1); (* creating bitmap *) NEW(b); Bitmaps.New(b, w, h, 1); (* also creating bitmap *) NEW(p); b := Bitmaps.New(p, w, h, 1); (* creating picture *) Seems simple, does the job, bad idea? -- Tomas Kral <thomas.kral@email.cz>
Tomas Good coding practice in Oberon (-2 or -07) is: "Split creation (NEW) from initialization" As Chris mentioned reason is described in http://ssw.jku.at/Research/Books/Oberon2.pdf chapter 8.1 I would call the procedures not "New" and "New2" but rather "InitBitmap" and "InitPicture" or "InitBM" and "InitPic" if you prefer shorter names :-) br Jörg -----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Tomas Kral Sent: Monday, October 02, 2017 12:37 PM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] FPGA - Pictures.Mod composition On Sun, 1 Oct 2017 20:23:21 +0200 August Karlstrom <fusionfile@gmail.com> wrote:
common approach is to separate memory allocation and initialization
Hi, I would know the reason for separating. As FPGA { Oberon-07, V5 } is about building system from scratch while making it simple, we could possibly also experiment with new tricks here. I have therefore merged these procedures into one.
PROCEDURE Bitmaps.New(w, h, dpt) : Bitmaps; PROCEDURE Bitmaps.New2(B: Bitmap; w, h, dpt) : Bitmaps;
PROCEDURE New*(B: Bitmap; w, h, dpt: INTEGER) : Bitmap; BEGIN IF B = NIL THEN NEW(B) END; (* create itself *) IF B # NIL THEN (* initialise itself *) (* ... *) (* allocate itself *) END RETURN B END New; VAR b: Bitmap; p: Picture b := Bitmaps.New(NIL, w, h, 1); (* creating bitmap *) NEW(b); Bitmaps.New(b, w, h, 1); (* also creating bitmap *) NEW(p); b := Bitmaps.New(p, w, h, 1); (* creating picture *) Seems simple, does the job, bad idea? -- Tomas Kral <thomas.kral@email.cz> -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
participants (4)
-
August Karlstrom -
Chris Burrows -
Jörg -
Tomas Kral