The recent discussions about strings and the OR compiler and how one should interpret the language report reminded me of a question that has puzzled me for some time now. In the change from Oberon (1990) to Oberon-07 the standard procedure COPY(src, dst) was discarded by NW and the type check of the assignment operator := for strings and character arrays was changed somewhat. In Oberon (1990) str2 := str1 was only possible if str1 and str2 were of the *same* type; and COPY could be used if the types were different, truncating a string if necessary. In Oberon-07 str2 := str1 also is possible if s1 and s2 are of *different* types, provided their lengths are *equal*. At least that is how Wirth's OR compiler behaves; at least one compiler (OBNC) still precludes assignment if str1 and str2 are of different types. Now, in Wirth's document 'Differences between Revised Oberon and Oberon' (https://people.inf.ethz.ch/wirth/Oberon/Oberon07.pdf) under '4. Assignment of arrays and records' one can read: '(...) But now we handle array and record assignments just like other assignments, writing dst := src, and discard the COPY procedure. The destination array must not be shorter than the source array. (...)' So I would expect that something like the following should be possible: ... VAR a8: ARRAY 8 OF CHAR; a32: ARRAY 32 OF CHAR; BEGIN ... a32 := a8; (* error: illegal assignment *) But unfortunately this is not possible with the current implementation of the Oberon-07 language. So now we have to use a Strings procedure to get this done: Strings.Copy(a8, a32) (* equivalent to: a32 := ""; Strings.Insert(a8, 0, a32) *) Whereas the following *is* possible when using the OR compiler, which I would regard as not in the spirit of the Oberon language (and that's why I think OBNC has the proper behaviour): TYPE Man = ARRAY 32 OF CHAR; Woman = ARRAY 32 OF CHAR; NoGender = ARRAY 32 OF CHAR; VAR m: Man; n: NoGender; w: Woman; BEGIN ... m := w; (* OR: no error; OBNC: incompatible types in assignment *) n := m; (* OR: no error; OBNC: incompatible types in assignment *) In my view a32 := a8 should be allowed and m := w or n := m not! What do you think? Hans Klaver
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Hans Klaver Sent: Monday, 1 February 2021 7:35 PM To: ETH Oberon and related systems Subject: [Oberon] Compiler behaviour for a32 := a8
The recent discussions about strings and the OR compiler and how one should interpret the language report reminded me of a question that has puzzled me for some time now.
In the change from Oberon (1990) to Oberon-07 the standard procedure COPY(src, dst) was discarded by NW and the type check of the assignment operator := for strings and character arrays was changed somewhat.
In Oberon (1990) str2 := str1 was only possible if str1 and str2 were of the *same* type; and COPY could be used if the types were different, truncating a string if necessary.
In Oberon-07 str2 := str1 also is possible if s1 and s2 are of *different* types, provided their lengths are *equal*. At least that is how Wirth's OR compiler behaves; at least one compiler (OBNC) still precludes assignment if str1 and str2 are of different types.
Now, in Wirth's document 'Differences between Revised Oberon and Oberon' (https://people.inf.ethz.ch/wirth/Oberon/Oberon07.pdf) under '4. Assignment of arrays and records' one can read: '(...) But now we handle array and record assignments just like other assignments, writing dst := src, and discard the COPY procedure. The destination array must not be shorter than the source array. (...)'
So I would expect that something like the following should be possible:
... VAR a8: ARRAY 8 OF CHAR; a32: ARRAY 32 OF CHAR; BEGIN ... a32 := a8; (* error: illegal assignment *)
But unfortunately this is not possible with the current implementation of the Oberon-07 language. So now we have to use a Strings procedure to get this done: Strings.Copy(a8, a32) (* equivalent to: a32 := ""; Strings.Insert(a8, 0, a32) *)
Whereas the following *is* possible when using the OR compiler, which I would regard as not in the spirit of the Oberon language (and that's why I think OBNC has the proper behaviour):
TYPE Man = ARRAY 32 OF CHAR; Woman = ARRAY 32 OF CHAR; NoGender = ARRAY 32 OF CHAR; VAR m: Man; n: NoGender; w: Woman; BEGIN ... m := w; (* OR: no error; OBNC: incompatible types in assignment *) n := m; (* OR: no error; OBNC: incompatible types in assignment *)
In my view a32 := a8 should be allowed and m := w or n := m not!
What do you think?
Hans Klaver
The document you referred to, 'Differences between Revised Oberon and Oberon' is dated 22.03.2008 / 15.7.2011 and is now obsolete. The latest version of the Language Report is dated Revision 1.10.2013 / 3.5.2016. At the time the 'Differences' document was written, section 9.1. 'Assignments' of the Language Report listed the following exceptions: -------------------------------------------------- 1. The constant NIL can be assigned to variables of any pointer or procedure type. 2. Arrays must have the same element type, and the length of the destination array must not be less than the length of the source array. 3. Strings can be assigned to any array of characters, provided the length of the string is less than that of the array. 4. In the case of records, the type of the destination must be an extension of the type of the source. -------------------------------------------------- Revision 1.10.2013 / 3.5.2016 of the Language Report now states the exceptions as: -------------------------------------------------- 1. The constant NIL can be assigned to variables of any pointer or procedure type. 2. Strings can be assigned to any array of characters, provided the number of characters in the string is less than that of the array. (A null character is appended). Single-character strings can also be assigned to variables of type CHAR. 3. In the case of records, the type of the source must be an extension of the type of the destination. 4. An open array may be assigned to an array of equal base type. -------------------------------------------------- The key point is that Item 2 in the earlier definition has been removed and the rule "The type of the expression must be the same as that of the designator" now applies to array assignments. Hence a32 := a8 is no longer allowed. Note that SYSTEM.COPY is now provided to efficiently copy n words from an array of one type to another of the same or different type. Regards, Chris Burrows CFB Software https://www.astrobe.com/RISC5
Chris wrote:
The key point is that Item 2 in the earlier definition has been removed and the rule "The type of the expression must be the same as that of the designator" now applies to array assignments. Hence a32 := a8 is no longer allowed.
Contrary to the latter rule that you cite a variable of one character array type now can be assigned to a variable of quite another character array type (provided the two array types have the same length). This is a breach in the type checking that amazes me.
Note that SYSTEM.COPY is now provided to efficiently copy n words from an array of one type to another of the same or different type.
I would consider it an abuse of SYSTEM.COPY to use it for assignment of one variable of an anonymous ARRAY len1 OF CHAR type to a variable of another anonymous ARRAY len2 OF CHAR, and using it would be unwieldy and unhelpful: - unwieldy because it would involve several SYSTEM-dependend type casts, - unhelpful because it would not warn for string truncation. Such assignments already can be done SYSTEM-independently with a String.Copy procedure, but it would be nicer if the compiler would allow such assignments of variables of anomymous character array types of different length and check for the suitability of the lengths. So my point is that the logic of the language changes (and their implementation) escape me. Hans
Op 1 feb. 2021, om 11:30 heeft Chris Burrows <chris@cfbsoftware.com> het volgende geschreven:
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Hans Klaver Sent: Monday, 1 February 2021 7:35 PM To: ETH Oberon and related systems Subject: [Oberon] Compiler behaviour for a32 := a8
The recent discussions about strings and the OR compiler and how one should interpret the language report reminded me of a question that has puzzled me for some time now.
In the change from Oberon (1990) to Oberon-07 the standard procedure COPY(src, dst) was discarded by NW and the type check of the assignment operator := for strings and character arrays was changed somewhat.
In Oberon (1990) str2 := str1 was only possible if str1 and str2 were of the *same* type; and COPY could be used if the types were different, truncating a string if necessary.
In Oberon-07 str2 := str1 also is possible if s1 and s2 are of *different* types, provided their lengths are *equal*. At least that is how Wirth's OR compiler behaves; at least one compiler (OBNC) still precludes assignment if str1 and str2 are of different types.
Now, in Wirth's document 'Differences between Revised Oberon and Oberon' (https://people.inf.ethz.ch/wirth/Oberon/Oberon07.pdf) under '4. Assignment of arrays and records' one can read: '(...) But now we handle array and record assignments just like other assignments, writing dst := src, and discard the COPY procedure. The destination array must not be shorter than the source array. (...)'
So I would expect that something like the following should be possible:
... VAR a8: ARRAY 8 OF CHAR; a32: ARRAY 32 OF CHAR; BEGIN ... a32 := a8; (* error: illegal assignment *)
But unfortunately this is not possible with the current implementation of the Oberon-07 language. So now we have to use a Strings procedure to get this done: Strings.Copy(a8, a32) (* equivalent to: a32 := ""; Strings.Insert(a8, 0, a32) *)
Whereas the following *is* possible when using the OR compiler, which I would regard as not in the spirit of the Oberon language (and that's why I think OBNC has the proper behaviour):
TYPE Man = ARRAY 32 OF CHAR; Woman = ARRAY 32 OF CHAR; NoGender = ARRAY 32 OF CHAR; VAR m: Man; n: NoGender; w: Woman; BEGIN ... m := w; (* OR: no error; OBNC: incompatible types in assignment *) n := m; (* OR: no error; OBNC: incompatible types in assignment *)
In my view a32 := a8 should be allowed and m := w or n := m not!
What do you think?
Hans Klaver
The document you referred to, 'Differences between Revised Oberon and Oberon' is dated 22.03.2008 / 15.7.2011 and is now obsolete. The latest version of the Language Report is dated Revision 1.10.2013 / 3.5.2016.
At the time the 'Differences' document was written, section 9.1. 'Assignments' of the Language Report listed the following exceptions:
-------------------------------------------------- 1. The constant NIL can be assigned to variables of any pointer or procedure type. 2. Arrays must have the same element type, and the length of the destination array must not be less than the length of the source array. 3. Strings can be assigned to any array of characters, provided the length of the string is less than that of the array. 4. In the case of records, the type of the destination must be an extension of the type of the source. --------------------------------------------------
Revision 1.10.2013 / 3.5.2016 of the Language Report now states the exceptions as:
-------------------------------------------------- 1. The constant NIL can be assigned to variables of any pointer or procedure type. 2. Strings can be assigned to any array of characters, provided the number of characters in the string is less than that of the array. (A null character is appended). Single-character strings can also be assigned to variables of type CHAR. 3. In the case of records, the type of the source must be an extension of the type of the destination. 4. An open array may be assigned to an array of equal base type. --------------------------------------------------
The key point is that Item 2 in the earlier definition has been removed and the rule "The type of the expression must be the same as that of the designator" now applies to array assignments. Hence a32 := a8 is no longer allowed.
Note that SYSTEM.COPY is now provided to efficiently copy n words from an array of one type to another of the same or different type.
Regards, Chris Burrows CFB Software https://www.astrobe.com/RISC5
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On 2021-02-01 14:39, Hans Klaver wrote:
Chris wrote:
The key point is that Item 2 in the earlier definition has been removed and the rule "The type of the expression must be the same as that of the designator" now applies to array assignments. Hence a32 := a8 is no longer allowed.
Contrary to the latter rule that you cite a variable of one character array type now can be assigned to a variable of quite another character array type (provided the two array types have the same length). This is a breach in the type checking that amazes me.
As mentioned before in this mailing list, I asked Niklaus Wirth in 2017 if structural equivalence of arrays and procedures is to be seen as a language extension and he answered: "Yes, I consider this type compatibility as an addition to the language definition. I think it makes sense, and it is easy to implement. Please look at the source of the compiler under Project Oberon." What I don't understand is why it hasn't been added to the language report if he thinks it both makes sense and is easy to implement. -- August
Thanks to Chris and August it's becoming clearer to me now. The documents on Prof. Wirth's website are not always in sync with the reality of the compiler. August wrote:
As mentioned before in this mailing list, I asked Niklaus Wirth in 2017 if structural equivalence of arrays and procedures is to be seen as a language extension and he answered:
"Yes, I consider this type compatibility as an addition to the language definition. I think it makes sense, and it is easy to implement. Please look at the source of the compiler under Project Oberon."
I'm not really at home in the compiler source files. Could you tell me where exactly in the source text one can read about this structural equivalence of arrays? Regards, Hans
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Hans Klaver Sent: Tuesday, 2 February 2021 9:35 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Compiler behaviour for a32 := a8
Thanks to Chris and August it's becoming clearer to me now. The documents on Prof. Wirth's website are not always in sync with the reality of the compiler.
A message I posted here last year is somewhat relevant: http://lists.inf.ethz.ch/pipermail/oberon/2020/014095.html Regards, Chris Burrows CFB Software https://www.astrobe.com/RISC5
On 2021-02-02 00:31, Chris Burrows wrote:
A message I posted here last year is somewhat relevant:
Niklaus Wirth says that "It is the privilege of a report to leave certain constructs undefined. In this case a user should simply avoid using the (undefined) feature." To me this makes perfect sense for the "gray areas." However, I didn't know it also applies to the rules of type compatibility. The conclusion then is that although the PO compiler supports structural equivalence of arrays and procedures, and access to intermediate constants, types and procedures we shouldn't use these features. -- August
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Hans Klaver Sent: Tuesday, 2 February 2021 9:35 AM To: ETH Oberon and related systems Subject: Re: [Oberon] Compiler behaviour for a32 := a8
Thanks to Chris and August it's becoming clearer to me now. The documents on Prof. Wirth's website are not always in sync with the reality of the compiler.
August wrote:
As mentioned before in this mailing list, I asked Niklaus Wirth in 2017 if structural equivalence of arrays and procedures is to be seen as a language extension and he answered:
"Yes, I consider this type compatibility as an addition to the language definition. I think it makes sense, and it is easy to implement. Please look at the source of the compiler under Project Oberon."
I'm not really at home in the compiler source files. Could you tell me where exactly in the source text one can read about this structural equivalence of arrays?
The parsing of statements is performed in ORP.Mod. Look for the word 'assignment' in comments and you will find the relevant places. Regards, Chris Burrows CFB Software https://www.astrobe.com/RISC5
Chris: what is the run time footprint of Astrobe itself, w/o loading any applications? I am seeing 58,144 in your example screen shot. Are these bytes? Is it really as high as 57 kB at run time, or am I misreading the screen? Thanks, Wojtek
-----Original Message----- From: Skulski, Wojciech [mailto:skulski@pas.rochester.edu] Sent: Saturday, 13 February 2021 11:19 AM To: chris@cfbsoftware.com; ETH Oberon and related systems Subject: Astrobe memory footprint
Chris:
what is the run time footprint of Astrobe itself, w/o loading any applications? I am seeing 58,144 in your example screen shot. Are these bytes? Is it really as high as 57 kB at run time, or am I misreading the screen?
Correct, but I would word it differently. It is really *as low as* 57 kB at run time. Given 11 modules and a total of 2550 lines of code, that's an average of about 5 kB per module or just over 20 bytes per line of source code. If you are trying to make comparisons with other operating systems, keep in mind also that any applications to be loaded that use any of the OS runtime facilities (memory allocation, file handling, text handling, input etc) may be comparatively smaller as they don't have the overhead of linking in any of that code that is already loaded. They just reuse what is already resident in memory. Regards, Chris Burrows CFB Software https://www.astrobe.com/RISC5
Chris:
Correct, but I would word it differently. It is really *as low as* 57 kB at run time.
Thank you for the clarification. It is an important piece of info for my planning. I have a number of boards where I plan to embed the run time OS. It is important to know what is the footprint when there is no external RAM on board.
Given 11 modules and a total of 2550 lines of code, that's an average of about 5 kB per module or just over 20 bytes per line of source code.
Thank you for quoting these numbers too! The first is very important as it sizes a long term maintenance effort. It is feasible for me to tell the collaborators "yes we can" if the code size is a few thousand lines.
They just reuse what is already resident in memory.
Yes, I know. FYI, one of our former associates wrote a resident run time entirely in the form of a single MODULE* (note the star). It seemed a very good idea as the code size was pretty small, like 16 kB. Now that I looked at the code, I was quite terrified how many details he had to code himself. Most of these details would be provided by the Astrobe kernel. So now I think that we should follow the Astrobe path. Pretty obvious, is it not? We just hired a bright intern and we will see how far we can go. Thank you! Wojtek
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of August Karlstrom Sent: Tuesday, 2 February 2021 7:47 AM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] Compiler behaviour for a32 := a8
On 2021-02-01 14:39, Hans Klaver wrote:
Chris wrote:
The key point is that Item 2 in the earlier definition has been removed and the rule "The type of the expression must be the same as that of the designator" now applies to array assignments. Hence a32 := a8 is no longer allowed.
Contrary to the latter rule that you cite a variable of one character array type now can be assigned to a variable of quite another character array type (provided the two array types have the same length). This is a breach in the type checking that amazes me.
As mentioned before in this mailing list, I asked Niklaus Wirth in 2017 if structural equivalence of arrays and procedures is to be seen as a language extension and he answered:
"Yes, I consider this type compatibility as an addition to the language definition. I think it makes sense, and it is easy to implement. Please look at the source of the compiler under Project Oberon."
What I don't understand is why it hasn't been added to the language report if he thinks it both makes sense and is easy to implement.
Note that when the language was updated he did add: 4. An open array may be assigned to an array of equal base type Which should allow you now to write: TYPE Ident = ARRAY 32 OF CHAR; VAR a8: ARRAY 8 OF CHAR; a32: ARRAY 32 OF CHAR; id1, id2: Ident; PROCEDURE Assign(VAR dst: Ident; src: ARRAY OF CHAR); BEGIN dst := src END Assign; ... ... Assign(id1, a8); Assign(id2, a32); Which is not too laborious as an alternative to id1 := a8; and also allows the equivalent of: id2 := a32; You can expect a runtime error if src is larger than dst. Regards, Chris Burrows CFB Software https://www.astrobe.com/RISC5
On 2021-02-02 01:55, Chris Burrows wrote:
Note that when the language was updated he did add:
4. An open array may be assigned to an array of equal base type
Which should allow you now to write:
TYPE Ident = ARRAY 32 OF CHAR; VAR a8: ARRAY 8 OF CHAR; a32: ARRAY 32 OF CHAR; id1, id2: Ident;
PROCEDURE Assign(VAR dst: Ident; src: ARRAY OF CHAR); BEGIN dst := src END Assign; ... ... Assign(id1, a8);
How can we conclude from the language report that a shorter array can be assigned to id1? Sure, it makes sense for strings but what about non-character arrays? The statement above may as well trigger a run-time exception.
Assign(id2, a32);
This should be valid though. -- August
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of August Karlstrom Sent: Tuesday, 2 February 2021 9:51 PM To: ETH Oberon and related systems Subject: Re: [Oberon] Compiler behaviour for a32 := a8
On 2021-02-02 01:55, Chris Burrows wrote:
Note that when the language was updated he did add:
4. An open array may be assigned to an array of equal base type
Which should allow you now to write:
TYPE Ident = ARRAY 32 OF CHAR; VAR a8: ARRAY 8 OF CHAR; a32: ARRAY 32 OF CHAR; id1, id2: Ident;
PROCEDURE Assign(VAR dst: Ident; src: ARRAY OF CHAR); BEGIN dst := src END Assign; ... ... Assign(id1, a8);
How can we conclude from the language report that a shorter array can be assigned to id1? Sure, it makes sense for strings but what about non-character arrays? The statement above may as well trigger a run- time exception.
Because the Language Report does *not* say: 4. An open array may be assigned to an array of equal base type *and equal length* Why prohibit non-character arrays? I have had occasions when I just want to copy the first couple of elements of a 4-byte array to a 2-byte array. Regards, Chris Burrows CFB Software https://www.astrobe.com/RISC5
On 2021-02-01 10:04, Hans Klaver wrote:
In Oberon-07 str2 := str1 also is possible if s1 and s2 are of *different* types, provided their lengths are *equal*. At least that is how Wirth's OR compiler behaves; at least one compiler (OBNC) still precludes assignment if str1 and str2 are of different types.
This is the reason I wondered if these kind of extensions are documented and why they exist; I'm no talking about gray areas or unspecified behavior but the important rules of type compatibility. The next question is if structural equivalence of arrays in assignments are used in the PO compiler. -- August
participants (4)
-
August Karlstrom -
Chris Burrows -
Hans Klaver -
Skulski, Wojciech