gst-shape

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

gst-shape

MrGwen
Hi,

I would like to announce gst-shape git://github.com/MrGwen/gst-shape.git
a refactoring of the class shape, a small example of the power of this new
refactoring:

Before:

    primDump: anObject [
        "Private - Basic code to dump anObject on the stream associated with the
         receiver, without using proxies and the like."

        <category: 'private'>
        | class shape |
        self storeClass: (class := anObject class).
        self register: anObject.
        class isVariable ifTrue: [self nextPutLong: anObject basicSize].
        1 to: class instSize do: [:i | self dump: (anObject instVarAt: i)].
        class isVariable ifFalse: [^self].
        class isPointers
            ifTrue: [^self store: anObject through: [:obj | self dump: obj]].
        shape := class shape.
        shape == #character
            ifTrue: [^self store: anObject through: [:char | stream
nextPut: char]].
        (shape == #byte or: [shape == #int8])
            ifTrue: [^self store: anObject through: [:byte | self
nextPutByte: byte]].
        (shape == #short or: [shape == #ushort])
            ifTrue: [^self store: anObject through: [:short | self
nextPutShort: short]].
        (shape == #int or: [shape == #int])
            ifTrue: [^self store: anObject through: [:int | self
nextPutLong: int]].
        (shape == #int64 or: [shape == #uint64])
            ifTrue: [^self store: anObject through: [:int64 | self
nextPutInt64: int64]].
        shape == #utf32
            ifTrue:
                [^self store: anObject through: [:char | self
nextPutLong: char codePoint]].
        shape == #float
            ifTrue: [^self store: anObject through: [:float | self
nextPutFloat: float]].
        shape == #double
            ifTrue:
                [^self store: anObject through: [:double | self
nextPutFloat: double]].
        self notYetImplemented
    ]

After:
ObjectDumper >>
    primDump: anObject [
        "Private - Basic code to dump anObject on the stream associated with the
         receiver, without using proxies and the like."

        <category: 'private'>
        | class |
        self storeClass: (class := anObject class).
        self register: anObject.
        class isVariable ifTrue: [ self nextPutLong: anObject basicSize ].
        1 to: class instSize do: [ :i | self dump: (anObject instVarAt: i) ].
        class isVariable ifFalse: [ ^ self ].
        ^ class shape dumper: self store: anObject
    ]

The support inside Behavior is not totally finished but it goes on the
right direction.
Gwen

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: gst-shape

Paolo Bonzini-2
On 10/18/2010 11:42 AM, Gwenaël Casaccio wrote:
> Hi,
>
> I would like to announce gst-shape git://github.com/MrGwen/gst-shape.git
> a refactoring of the class shape, a small example of the power of this new
> refactoring:

This is very nice, thanks.  You can also use a branch of smalltalk.git
rather than a fully separate repository.  This will make it easier for
me to pull.

However, I wouldn't use class methods.  I think it's bad design. It's
better to use a simpler hierarchy and put these on the instance side
using instance variables:

Shape "class methods for mapping integers to ShapeSymbol instance"
     VMShape
         FixedShape "current NilShape"
         IntegerShape "adds #byteSize, #byteSize:"
             SignedIntegerShape
             UnsignedIntegerShape
         FloatingPointShape
         CharacterShape
              EncodedCharacterShape
              UnicodeCharacterShape
     ShapeAliasSymbol "abstract class maybe not necessary"
         ShapeInherit
         ShapeWord

This is because you can use #nextBytes:signed: and #nextPutBytes:of: to
implement dumping.  Those methods are private, but we can un-privatize them.

"wrongClassIfFloatOrDoubleShape:" and
"wrongClassIfCharacterOrUtf32Shape:" can be unified to
"checkArgumentClass:".

The "subclassResponsibilityIfCharacterOrUtf32Shape" and
"subclassResponsibilityIfNotCharacterOrUtf32Shape" methods are also bad.
  First of all, the former should not be used (it's always using
#ifFalse: in kernel/CharArray.st). Second, I'd anyway use a method
#hasValueAtPrimitives that returns true/false.

Thanks,

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: gst-shape

MrGwen
Thanks,

I'll do a pass and fix it

Cheers,
Gwen

On Mon, Oct 18, 2010 at 12:05 PM, Paolo Bonzini <[hidden email]> wrote:

> On 10/18/2010 11:42 AM, Gwenaël Casaccio wrote:
>>
>> Hi,
>>
>> I would like to announce gst-shape git://github.com/MrGwen/gst-shape.git
>> a refactoring of the class shape, a small example of the power of this new
>> refactoring:
>
> This is very nice, thanks.  You can also use a branch of smalltalk.git
> rather than a fully separate repository.  This will make it easier for me to
> pull.
>
> However, I wouldn't use class methods.  I think it's bad design. It's better
> to use a simpler hierarchy and put these on the instance side using instance
> variables:
>
> Shape "class methods for mapping integers to ShapeSymbol instance"
>    VMShape
>        FixedShape "current NilShape"
>        IntegerShape "adds #byteSize, #byteSize:"
>            SignedIntegerShape
>            UnsignedIntegerShape
>        FloatingPointShape
>        CharacterShape
>             EncodedCharacterShape
>             UnicodeCharacterShape
>    ShapeAliasSymbol "abstract class maybe not necessary"
>        ShapeInherit
>        ShapeWord
>
> This is because you can use #nextBytes:signed: and #nextPutBytes:of: to
> implement dumping.  Those methods are private, but we can un-privatize them.
>
> "wrongClassIfFloatOrDoubleShape:" and "wrongClassIfCharacterOrUtf32Shape:"
> can be unified to "checkArgumentClass:".
>
> The "subclassResponsibilityIfCharacterOrUtf32Shape" and
> "subclassResponsibilityIfNotCharacterOrUtf32Shape" methods are also bad.
>  First of all, the former should not be used (it's always using #ifFalse: in
> kernel/CharArray.st). Second, I'd anyway use a method #hasValueAtPrimitives
> that returns true/false.
>
> Thanks,
>

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: gst-shape

MrGwen
I've migrated the patch on my gst git:
git://github.com/MrGwen/smalltalk.git the shape branch

Gwen

On Mon, Oct 18, 2010 at 12:37 PM, Gwenaël Casaccio <[hidden email]> wrote:

> Thanks,
>
> I'll do a pass and fix it
>
> Cheers,
> Gwen
>
> On Mon, Oct 18, 2010 at 12:05 PM, Paolo Bonzini <[hidden email]> wrote:
>> On 10/18/2010 11:42 AM, Gwenaël Casaccio wrote:
>>>
>>> Hi,
>>>
>>> I would like to announce gst-shape git://github.com/MrGwen/gst-shape.git
>>> a refactoring of the class shape, a small example of the power of this new
>>> refactoring:
>>
>> This is very nice, thanks.  You can also use a branch of smalltalk.git
>> rather than a fully separate repository.  This will make it easier for me to
>> pull.
>>
>> However, I wouldn't use class methods.  I think it's bad design. It's better
>> to use a simpler hierarchy and put these on the instance side using instance
>> variables:
>>
>> Shape "class methods for mapping integers to ShapeSymbol instance"
>>    VMShape
>>        FixedShape "current NilShape"
>>        IntegerShape "adds #byteSize, #byteSize:"
>>            SignedIntegerShape
>>            UnsignedIntegerShape
>>        FloatingPointShape
>>        CharacterShape
>>             EncodedCharacterShape
>>             UnicodeCharacterShape
>>    ShapeAliasSymbol "abstract class maybe not necessary"
>>        ShapeInherit
>>        ShapeWord
>>
>> This is because you can use #nextBytes:signed: and #nextPutBytes:of: to
>> implement dumping.  Those methods are private, but we can un-privatize them.
>>
>> "wrongClassIfFloatOrDoubleShape:" and "wrongClassIfCharacterOrUtf32Shape:"
>> can be unified to "checkArgumentClass:".
>>
>> The "subclassResponsibilityIfCharacterOrUtf32Shape" and
>> "subclassResponsibilityIfNotCharacterOrUtf32Shape" methods are also bad.
>>  First of all, the former should not be used (it's always using #ifFalse: in
>> kernel/CharArray.st). Second, I'd anyway use a method #hasValueAtPrimitives
>> that returns true/false.
>>
>> Thanks,
>>
>

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: gst-shape

Paolo Bonzini-2
On 10/20/2010 09:16 AM, Gwenaël Casaccio wrote:
> I've migrated the patch on my gst git:
> git://github.com/MrGwen/smalltalk.git the shape branch

Cool, I look forward to seeing the refactored version!

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: gst-shape

MrGwen
Just a ping,

I've just made an update would you mind do a "quick" pass
to see  if it is on the right direction (forget the ObjectDumper ext :D)

Thanks,
Gwen

On Wed, Oct 20, 2010 at 10:04 AM, Paolo Bonzini <[hidden email]> wrote:
> On 10/20/2010 09:16 AM, Gwenaël Casaccio wrote:
>>
>> I've migrated the patch on my gst git:
>> git://github.com/MrGwen/smalltalk.git the shape branch
>
> Cool, I look forward to seeing the refactored version!
>
> Paolo
>

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: gst-shape

Paolo Bonzini-2
On 10/22/2010 06:16 PM, Gwenaël Casaccio wrote:
> Just a ping,
>
> I've just made an update would you mind do a "quick" pass
> to see  if it is on the right direction (forget the ObjectDumper ext :D)

MUCH better.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk