[PATCH] First class shape

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

[PATCH] First class shape

Gwenaël Casaccio
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


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