<div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default">Hi Nicolas,</div></div><div><br></div><div class="gmail_default">   re "((hex as: RunArray) runs size * 4) < ((hex as: RunArray) runs size * 3)", I *love* it!  I hadn't thought of this way.  That's great.  I/we should add some comments to indicate what we're wanting to achieve.</div><div class="gmail_default"><br></div><div class="gmail_default">P.S. modifying the bytecode compiler so it respects the base of integer constants when doing pretty printing is IMO something we've needed for years and years.  LiteralNode could have an optional base or we could have a NumericLiteralNode subclass.  But it is the Scanner that needs to collect the information in the first place.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 27, 2020 at 7:22 AM <<a href="mailto:commits@source.squeak.org">commits@source.squeak.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"> <br>
Nicolas Cellier uploaded a new version of VMMaker to project VM Maker:<br>
<a href="http://source.squeak.org/VMMaker/VMMaker.oscog-nice.2912.mcz" rel="noreferrer" target="_blank">http://source.squeak.org/VMMaker/VMMaker.oscog-nice.2912.mcz</a><br>
<br>
==================== Summary ====================<br>
<br>
Name: VMMaker.oscog-nice.2912<br>
Author: nice<br>
Time: 27 December 2020, 4:21:39.377922 pm<br>
UUID: 607e7bf3-9cd1-4a6b-ac0c-7261a969519b<br>
Ancestors: VMMaker.oscog-nice.2910<br>
<br>
Complexify the rule for generating hex literal constants when more intellegible than decimal.<br>
<br>
This is useful for having a chance to decipher generated code for bit tricks.<br>
<br>
This replaces VMMaker.oscog-nice.2911 that screwed things up (hex generates the radix 16r).<br>
VMMaker.oscog-nice.2911 should be thrown away.<br>
<br>
=============== Diff against VMMaker.oscog-nice.2910 ===============<br>
<br>
Item was changed:<br>
  ----- Method: CCodeGenerator>>cLiteralFor: (in category 'C code generator') -----<br>
  cLiteralFor: anObject<br>
        "Return a string representing the C literal value for the given object."<br>
+               <br>
        anObject isNumber<br>
                ifTrue:<br>
                        [anObject isInteger ifTrue:<br>
+                               [| hex dec useHexa |<br>
+                                hex := anObject printStringBase: 16.<br>
+                                dec := anObject printStringBase: 10.<br>
+                                useHexa := (anObject > 255<br>
+                                                               and: [(hex asSet size * 3) <= (dec asSet size * 2)<br>
+                                                                       or: [((hex as: RunArray) runs size * 4) < ((hex as: RunArray) runs size * 3)]])<br>
+                                       or: [anObject > 0<br>
-                               [| hex |<br>
-                                hex := (anObject > 0<br>
                                                                and: [(anObject >> anObject lowBit + 1) isPowerOfTwo<br>
                                                                and: [(anObject highBit = anObject lowBit and: [anObject > 65536])<br>
+                                                                         or: [anObject highBit - anObject lowBit >= 4]]]].<br>
+                               ^self cLiteralForInteger: anObject hex: useHexa].<br>
-                                                                         or: [anObject highBit - anObject lowBit >= 4]]]).<br>
-                               ^self cLiteralForInteger: anObject hex: hex].<br>
                        anObject isFloat ifTrue:<br>
                                [^anObject printString]]<br>
                ifFalse:<br>
                        [anObject isSymbol ifTrue:<br>
                                [^self cFunctionNameFor: anObject].<br>
                        anObject isString ifTrue:<br>
                                [^'"', (anObject copyReplaceAll: (String with: Character cr) with: '\n') , '"'].<br>
                        anObject == nil ifTrue: [^ 'null' ].<br>
                        anObject == true ifTrue: [^ '1' ].<br>
                        anObject == false ifTrue: [^ '0' ].<br>
                        anObject isCharacter ifTrue:<br>
                                [^anObject == $'<br>
                                        ifTrue: ['''\'''''] "i.e. '\''"<br>
                                        ifFalse: [anObject asString printString]]].<br>
        self error: 'Warning: A Smalltalk literal could not be translated into a C constant: ', anObject printString.<br>
        ^'"XXX UNTRANSLATABLE CONSTANT XXX"'!<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div></div></div>