[Vm-dev] VM Maker: VMMaker.oscog-nice.2912.mcz
commits at source.squeak.org
commits at source.squeak.org
Sun Dec 27 15:21:52 UTC 2020
Nicolas Cellier uploaded a new version of VMMaker to project VM Maker:
http://source.squeak.org/VMMaker/VMMaker.oscog-nice.2912.mcz
==================== Summary ====================
Name: VMMaker.oscog-nice.2912
Author: nice
Time: 27 December 2020, 4:21:39.377922 pm
UUID: 607e7bf3-9cd1-4a6b-ac0c-7261a969519b
Ancestors: VMMaker.oscog-nice.2910
Complexify the rule for generating hex literal constants when more intellegible than decimal.
This is useful for having a chance to decipher generated code for bit tricks.
This replaces VMMaker.oscog-nice.2911 that screwed things up (hex generates the radix 16r).
VMMaker.oscog-nice.2911 should be thrown away.
=============== Diff against VMMaker.oscog-nice.2910 ===============
Item was changed:
----- Method: CCodeGenerator>>cLiteralFor: (in category 'C code generator') -----
cLiteralFor: anObject
"Return a string representing the C literal value for the given object."
+
anObject isNumber
ifTrue:
[anObject isInteger ifTrue:
+ [| hex dec useHexa |
+ hex := anObject printStringBase: 16.
+ dec := anObject printStringBase: 10.
+ useHexa := (anObject > 255
+ and: [(hex asSet size * 3) <= (dec asSet size * 2)
+ or: [((hex as: RunArray) runs size * 4) < ((hex as: RunArray) runs size * 3)]])
+ or: [anObject > 0
- [| hex |
- hex := (anObject > 0
and: [(anObject >> anObject lowBit + 1) isPowerOfTwo
and: [(anObject highBit = anObject lowBit and: [anObject > 65536])
+ or: [anObject highBit - anObject lowBit >= 4]]]].
+ ^self cLiteralForInteger: anObject hex: useHexa].
- or: [anObject highBit - anObject lowBit >= 4]]]).
- ^self cLiteralForInteger: anObject hex: hex].
anObject isFloat ifTrue:
[^anObject printString]]
ifFalse:
[anObject isSymbol ifTrue:
[^self cFunctionNameFor: anObject].
anObject isString ifTrue:
[^'"', (anObject copyReplaceAll: (String with: Character cr) with: '\n') , '"'].
anObject == nil ifTrue: [^ 'null' ].
anObject == true ifTrue: [^ '1' ].
anObject == false ifTrue: [^ '0' ].
anObject isCharacter ifTrue:
[^anObject == $'
ifTrue: ['''\'''''] "i.e. '\''"
ifFalse: [anObject asString printString]]].
self error: 'Warning: A Smalltalk literal could not be translated into a C constant: ', anObject printString.
^'"XXX UNTRANSLATABLE CONSTANT XXX"'!
More information about the Vm-dev
mailing list