help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] [PATCH] First class shape


From: Gwenaël Casaccio
Subject: [Help-smalltalk] [PATCH] First class shape
Date: Wed, 08 Jan 2014 21:54:45 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Hi,

I've finally added first class shape in my gst repository
(https://github.com/GwenaelCasaccio/gst/tree/shape) ,
there are few changes in the packages, it's not merged
in the master branch because I want to polish some parts
(adding a licence, unit test for the shape classes, ...) but
tests are green :-)

a small example:

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 ].
        ^self store: anObject through: [:each | shape save: each
 ]

Cheers,
Gwen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]