VM Maker: VMMaker.oscog-nice.2912.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

VM Maker: VMMaker.oscog-nice.2912.mcz

commits-2
 
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"'!

Reply | Threaded
Open this post in threaded view
|

Re: VM Maker: VMMaker.oscog-nice.2912.mcz

Eliot Miranda-2
 
Hi Nicolas,

  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.

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.

On Sun, Dec 27, 2020 at 7:22 AM <[hidden email]> wrote:
 
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"'!



--
_,,,^..^,,,_
best, Eliot
Reply | Threaded
Open this post in threaded view
|

Re: VM Maker: VMMaker.oscog-nice.2912.mcz

Tobias Pape
 
Hi


> On 29. Dec 2020, at 06:06, Eliot Miranda <[hidden email]> wrote:
>
> Hi Nicolas,
>
>   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.
>

shouldnt that be
((hex as: RunArray) runs size * 4) < ((dec as: RunArray) runs size * 3)
instead of
((hex as: RunArray) runs size * 4) < ((hex as: RunArray) runs size * 3)

?
-t

> 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.
>
> On Sun, Dec 27, 2020 at 7:22 AM <[hidden email]> wrote:
>  
> 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"'!



Reply | Threaded
Open this post in threaded view
|

Re: VM Maker: VMMaker.oscog-nice.2912.mcz

Nicolas Cellier
 
Oh my, 3 pairs of eyes are better than 2!
And yes, it would be simpler to retain the literal node format, at least the base... We could also use special formatting rules for operands of bit ops... 

Le mar. 29 déc. 2020 à 10:04, Tobias Pape <[hidden email]> a écrit :
 
Hi


> On 29. Dec 2020, at 06:06, Eliot Miranda <[hidden email]> wrote:
>
> Hi Nicolas,
>
>   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.
>

shouldnt that be
((hex as: RunArray) runs size * 4) < ((dec as: RunArray) runs size * 3)
instead of
((hex as: RunArray) runs size * 4) < ((hex as: RunArray) runs size * 3)

?
-t

> 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.
>
> On Sun, Dec 27, 2020 at 7:22 AM <[hidden email]> wrote:

> 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"'!