[Glass] Variable - pointer classes, do you have them?

Dale Henrichs via Glass glass at lists.gemtalksystems.com
Thu Sep 4 15:27:00 PDT 2014


Mariano,

Here's the method that i use for extracting the fields from an object for
STON:

  1 to: self class instSize do: [ :each | self instVarAt: each put: (block
value: (self instVarAt: each)) ].
  (self class isVariable and: [ self class isBytes not ])
    ifTrue: [ 1 to: self _basicSize do: [ :each | self basicAt: each put:
(block value: (self basicAt: each)) ] ]

and here is method that I use for constructing an inspector in tODE:

  | parentObj coll specialElements ivs dvs indexableSize moreElements |
  parentObj := parentNode basicContents.
  ivs := parentObj class allInstVarNames.
  dvs := (parentObj respondsTo: #'dynamicInstanceVariables')
    ifTrue: [ parentObj dynamicInstanceVariables ]
    ifFalse: [ #() ].
  moreElements := #().
  indexableSize := Reflection sizeOf: parentObj.
  indexableSize > self indexableWindowSize
    ifTrue: [
      indexableEndIndex := self indexableStartIndex + self
indexableWindowSize - 1
        min: indexableSize.
      indexableEndIndex < indexableSize
        ifTrue: [ moreElements := #('<<more>>') ] ]
    ifFalse: [ indexableEndIndex := indexableSize - ivs size ].
  specialElements := self specialChildNodeNameList: parentNode.
  coll := (ivs , dvs) sorted collect: [ :each | each asString ].
  ^ specialElements , coll
    ,
      ((self indexableStartIndex to: indexableEndIndex)
        collect: [ :each | each asString ])
    , moreElements

Which I think should give you some interesting information about accessing
instvars and indexable slots in an object ...

Dale


On Thu, Sep 4, 2014 at 2:22 PM, Mariano Martinez Peck via Glass <
glass at lists.gemtalksystems.com> wrote:

> Hi guys,
>
> In Pharo, there are "variable" classes that hold pointers. That is,
> besides the named instVars, there is a space for "variables". To create
> these classes in Pharo we use variableSubclass:... etc...Example: Array.
>
> ArrayedCollection variableSubclass: #Array
> instanceVariableNames: ''
> classVariableNames: ''
>  poolDictionaries: ''
> category: 'Collections-Sequenceable'
>
> So...to serialize these instances, what we do, is 2 things: serialize the
> "fixed/named" instVars (none in this example of Array) and iterate and
> serialize the "variable part" using #basicSize and #basicAt:. And then,
> upon materialization, I can send #basicNew: with the desired size and using
> #basicAt:put:
>
> The way to get those classes in Pharo is:
>
> Smalltalk allClasses select: [ :each | ((each isWeak not and: [ each
> isFixed not ])  and: [ each isBytes not ]) and: [ each isPointers ] ]
>
> ->   an OrderedCollection(AbsolutePath AdditionalMethodState Array
> BlockClosure Cubic FaFnSeries FaSeries FileReferenceTest MCMockClassE
> MetacelloMethodSectionPath MetacelloVersionNumber MethodContext
> MethodDictionary Path PathTest RelativePath SixxMockBinaryData
> SixxMockMementoArray SixxMockVariableAlternativeClass
> SixxMockVariableNewFailedClass SparseLargeArray SparseLargeTable
> WAExampleClass WeakActionSequence)
>
> Now I know in GemStone you have indexable classes. I think the equivalent
> are those classes that answer true to #isPointers and #isIndexable
>
>
> Smalltalk allClasses select: [:each | each isPointers and: [ each
> isIndexable ] ]
>
> -> [ anArray( Array, Collection, CompiledMethod, InvariantArray,
> OldRepository, SequenceableCollection, SymbolList, AbstractCollisionBucket,
> KeyValueDictionary, IntegerKeyValueDictionary, StringKeyValueDictionary,
> CharacterCollection, ClusterBucketArray, ClassHistory, RcQueue,
> StackBuffer, BtreeNode, BtreeInteriorNode, BtreeLeafNode,
> BtreeBasicInteriorNode, BtreeBasicLeafNode, RcKeyValueDictionary,
> RcIndexDictionary, RcIndexBucket, IdentityIndex, RangeEqualityIndex,
> PathTerm, IndexList, DependencyList, SetValuedPathTerm, MappingInfo,
> ConstrainedPathTerm, QueryExecuter, IdentityKeyValueDictionary,
> PathEvaluator, OrderedCollection, SortedCollection, SortNode,
> BasicSortNode, RcIndexBucketWithCache, GsMethod, ...)]
>
> So..first question, is this assumption correct?   If true.... then which
> methods can I use for what I need? that is, #basicSize, #basicAt: ,
> #basicAt:put: , #basicNew:
> I tried different combinations of #basicAt: , #_at: etc but it  never
> worked.
>
> What is strange for example, is that if I serialize these objects as FIXED
> pointers...they seem to work. But the fixed part serializes only via
> instVarNames... so I don't understand how this could work since I would be
> missing the variable part.
>
> Any help is appreciated.
>
>
>
>
> --
> Mariano
> http://marianopeck.wordpress.com
>
> _______________________________________________
> Glass mailing list
> Glass at lists.gemtalksystems.com
> http://lists.gemtalksystems.com/mailman/listinfo/glass
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20140904/089c6c6a/attachment.html>


More information about the Glass mailing list