<div dir="ltr"><div><div>&gt; Hi Ralph,<br>
...<br><br>
&gt; &gt;<br>
&gt; &gt; I was aware of caseOf: in Squeak.  I always found it awkward to use and<br>
&gt; &gt; felt a true case statement would be simpler.  Alas, it&#39;s impossible to<br>
&gt; &gt; have a true case statement added to Smalltalk now I think.<br>
<br>
&gt; So what&#39;s a &quot;true&quot; case statement?  For me, at least, the Squeak one *is*,<br>
&gt; and is more general than one limited to purely integer keys, as for example<br>
&gt; is C&#39;s switch statement.  A number of languages provide case statements<br>
&gt; that are like Squeak&#39;s.  What do you consider a &quot;true&quot; case statement?<br><br></div>I mean that:  caseOf: is not part of the language itself but rather part of the<br>standard library or set of packages that one finds in the IDE.  To be part of the<br>language it would need to be something the compiler is aware of.  That is to<br>day the Smalltalk language is not very much.  Smalltalk (Squeak) the language<br>would not include Sets or Dictionaries but would include (some) Array classes<br>because some aspects of Arrays are dealt with directly by the compiler.<br>Selectors such as  ifTrue: and  to:do:  are part of the language because they are inlined by the compiler.<br></div><div>Put another way,  if I could get my doBlockAt: method incorporated into the Squeak IDE<br></div><div>it would nevertheless NOT be part of Squeak the language.<br></div><div>The consequence of  caseOf:  not being part of the language is that the compiler/VM<br></div><div>cannot perform optimizations when caseOf:  is run into but must treat it as<br></div><div>user written code.<br><br></div><div>Squeak&#39;s  caseOf:  is more general than C&#39;s switch statement but it could be more<br>general in that there is a hard coded message (=).  I would like to be able to replace<br></div><div>the &#39;=&#39; message by an arbitrary binary operator such as  includes:  or &#39;&gt;&#39;.<br><br></div><div>I have to backtrack here:  I looked at the code and it looks like the compiler inlines <br></div><div>caseOf:  and caseOf:otherwise.  If so then these selectors are part of the language<br></div><div>by my definition.<br></div><div><div>
<br>
...<br><div id=":31o" class="">
<br>
&gt; &gt; But I wouldn&#39;t want to be forced to implement my FSMs this way.<br>
&gt; &gt; It might be acceptable for small FSMs.<br>
&gt; &gt; I want to avoid sequential search and<br>
&gt; &gt;  even binary search might be rather expensive.<br>
&gt; &gt; I look at computed gotos as the solution but,<br>
&gt; &gt; as you pointed out, computed gotos pose problems for JIT.<br>
&gt; &gt; Admittedly, for large FSM&#39;s, it might be best or necessary to<br>
&gt; &gt; use a FSM simulator anyway, as I do now.<br>
<br>
<br>
&gt; Nah.  One should always be able to map it down somehow.  Tis will be easier<br>
&gt; with the Spur instruction set which lifts number of literals and length of<br>
&gt; branches limits.<br><br></div><div id=":31o" class="">Good to hear.<br><br><br>
&gt; &gt; Again, for my FSM, case this would often be considered to be good.<br>
&gt; &gt; But if the state transition tables are sparse then Dictionaries<br>
&gt; &gt; might be preferable to Arrays.<br>
&gt;<br>
<br>
&gt; Yes, but getting to the limit of what the VM can reasonably interpret.<br>
&gt; Better would be an Array of value. pc pairs, where the keys are the values<br>
&gt; the switch bytecode compares top of stack against, and the pcs are where to<br>
&gt; jump to on a match.  The JIT can therefore implement the table as it sees<br>
&gt; fit, whereas the interpreter can just do a linear search through the Array.<br><br></div><div id=":31o" class="">I am looking at this from the point of view of a compiler writer/generator and consider<br></div><div id=":31o" class="">your proposal as inadequate for my needs.  You, I think, are looking at this from<br>the point of view of a VM writer and what can reasonably be delivered.  I don&#39;t think<br></div><div id=":31o" class="">what I want is overly difficult for the interpreter to deliver but as you pointed out,<br></div><div id=":31o" class="">and you know much better than I, what I want causes serious problems for the VM.<br></div><div id=":31o" class="">
<br>
&gt; &gt; My expection is that  at:  be sent to the collection object<br>
&gt; &gt;  to get the address to go to.  Knowing that the collection<br>
&gt; &gt; is an array though makes it easier for the compiler/VM to<br>
&gt; &gt; ensure that the addresses stored in the collection are valid.<br>
&gt; &gt; Actually, the compiler will be generating the addresses.<br>
&gt; &gt; Does the VM have absolute trust in the compiler to generate valid<br>
&gt; &gt; addresses?<br>
<br>
<br>
&gt; Yes.  Generate bad bytecode and the VM crashes.<br> <br></div><div id=":31o" class="">This is what I expected to hear but wanted it to be clear for compilers generated<br>by my parser generator tool as you did.<br><br></div><div id=":31o" class="">Ralph<br></div></div></div></div>