<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="DE-CH" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Hi<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">In the meantime, I implemented 3)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">The type extensions in a CASE are only allowed to get broader and broader.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">In other words: the extension depth is only allowed to get smaller.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">I made the following changes to ORP.Mod.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;color:#70AD47;mso-fareast-language:EN-US">Parameter “depth” added to<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">PROCEDURE IsExtension(t0, t1: ORB.Type;
<b><span style="color:red">VAR depth: INTEGER</span></b>): BOOLEAN;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> BEGIN (* t1 is an extension of t0 *)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">
<b><span style="color:red">INC(depth);</span><o:p></o:p></b></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> RETURN (t0 = t1) OR (t1 = NIL) & IsExtension(t0, t1.base<b>,
<span style="color:red">depth</span></b>)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> END IsExtension;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;color:#70AD47;mso-fareast-language:EN-US">Parameter “depth” added to<br>
</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">PROCEDURE TypeTest(VAR x: ORG.Item; T: ORB.Type; guard: BOOLEAN;
<b><span style="color:red">VAR depth: INTEGER</span></b>);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;color:#70AD47;mso-fareast-language:EN-US">Hierarchy logic added to<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">PROCEDURE TypeCase(obj: ORB.Object; VAR x: ORG.Item;
<b><span style="color:red">VAR prvDepth: INTEGER</span></b>);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">
<span style="color:red">VAR depth: INTEGER;</span><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> BEGIN<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">…<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">
<b><span style="color:red">depth := 0</span></b>; TypeTest(x, typobj.type, FALSE,
<b><span style="color:red">depth</span></b><span style="color:red">)</span>; obj.type := typobj.type;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">
<span style="color:red">IF depth > prvDepth THEN ORS.Mark(“type more specific than previous”) END;<o:p></o:p></span></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;color:red;mso-fareast-language:EN-US"> prvDepth := depth<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">…<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> END TypeCase;<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;color:#70AD47;mso-fareast-language:EN-US">and finally in StatSequence: start with an “infinite” depth (I took 9999) and propagate depth from label to label<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">ELSIF sym = ORS.case<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> ….<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> IF (orgtype.form = ORB.Pointer) OR (orgtype.form = ORB.Record) & (obj.class = ORB.Par) THEN<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> Check(ORS.of);
<b><span style="color:red">depth := 9999;</span></b><span style="color:red"> </span>
TypeCase(obj, x, <b><span style="color:red">depth</span></b>); L0 := 0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> WHILE sym = ORS.bar DO<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"> ORS.Get(sym); ORG.FJump(L0); ORG.Fixup(x); obj.type := orgtype; TypeCase(obj, x,
<b><span style="color:red">depth</span></b>)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">
</span><span style="font-size:11.0pt;mso-fareast-language:EN-US">END<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"> …<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US">END<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US">Jörg<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">Von:
</span></b><span style="font-size:12.0pt;color:black">Oberon <oberon-bounces@lists.inf.ethz.ch> im Auftrag von Joerg <joerg.straube@iaeth.ch><br>
<b>Datum: </b>Montag, 28. </span><span lang="EN-US" style="font-size:12.0pt;color:black">August 2023 um 23:10<br>
<b>An: </b>ETH Oberon and related systems <oberon@lists.inf.ethz.ch><br>
<b>Betreff: </b>Re: [Oberon] Case statements containing base type labels<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">August<br>
<br>
When I saw your code, this was basically my first reaction why I said the CASE label „Shape“ is not allowed as it is no extension.<br>
<br>
Then came Diego and said „Shape“ is an extension of itself. He is right as the report explicitely states it. Because I never thought of types with different extension levels, I thought: the missing ELSE could be handled elegantly with this „trick“
<br>
<br>
Personally, I find the CASE construct seen as a combination of IF-ELSE with implicit WITHs a nice „syntactic sugar“. But I have to agree with Chris, that it’s not obvious that then the order of CASE labels is important!<br>
<br>
To define the clear semantic I propse 4 options:<br>
1) state that all extension have to be on the same level aka must have the same „depth“ —> Shape generates an error.<br>
<br>
2) state that the „CASE with types“ is a syntactic sugar for an IF-ELSE cascade with implicit WITHs. Basically, leaving the order to the programmer. „Shape“ as last CASE label is an elegant way for an ELSE. But having „Shape“ as first label, makes the labels
„Circle“ and „Rectangle“ void.<br>
<br>
3) as type extensions build a hierarchy state that in the „CASE with types“ the labes have to be sorted from specific to broader. If a label is a more specific than a previous one, generate an error.<br>
<br>
4) state that the compiler sorts the labels from specific to broader. The hierarchy/order is guarateed by the compiler<br>
<br>
Looking at these 4 options, I would go for 1) or 3)<br>
<br>
br<br>
Jörg<br>
<br>
> Am 28.08.2023 um 19:28 schrieb August Karlstrom <fusionfile@gmail.com>:<br>
> </span><span style="font-size:11.0pt"></span><span lang="EN-US" style="font-size:11.0pt">On 2023-08-28 15:20, Chris Burrows wrote:<br>
>> Refer to the pair of examples on P 61 of Programming in Oberon, 2014:<br>
>> </span><a href="https://people.inf.ethz.ch/wirth/Oberon/PIO.pdf"><span lang="EN-US" style="font-size:11.0pt">https://people.inf.ethz.ch/wirth/Oberon/PIO.pdf</span></a><span lang="EN-US" style="font-size:11.0pt"> <</span><a href="https://people.inf.ethz.ch/wirth/Oberon/PIO.pdf"><span lang="EN-US" style="font-size:11.0pt">https://people.inf.ethz.ch/wirth/Oberon/PIO.pdf</span></a><span lang="EN-US" style="font-size:11.0pt">><br>
> <br>
> The examples you refer to in "Programming in Oberon" are in the context of message records and all labels are (proper) direct extensions of the base type Message so there is no ambiguity in this case; the labels can be arranged in any order without affecting
the behavior of the case statement (as it should be).<br>
> <br>
> My current conclusion is that a case statement where one type label is an extension of another is not well-defined. I think an ambitious compiler could even reject such a statement, similar to how repeated case labels can be handled.<br>
> <br>
> <br>
> /August<br>
> --<br>
> Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems<br>
> </span><a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon"><span lang="EN-US" style="font-size:11.0pt">https://lists.inf.ethz.ch/mailman/listinfo/oberon</span></a><span lang="EN-US" style="font-size:11.0pt"><br>
--<br>
Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems<br>
</span><a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon"><span lang="EN-US" style="font-size:11.0pt">https://lists.inf.ethz.ch/mailman/listinfo/oberon</span></a><span lang="EN-US" style="font-size:11.0pt"><o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</body>
</html>