On Jun 27, 2007, at 12:55 AM, SainTiss wrote:
> What would be the way to remove a method from a _vtable?
Here's one way to do it, based on st80/_objects.st (adjust
accordingly if you are using function/objects.a). Clearly, much of
the cruft in here really belongs in a reusable reflection API.
{ import: st80 }
_assoc key [ ^key ]
_vector size [ ^SmallInteger value_: _size ]
_vector at: anInteger
[
{
long index= (long)v_anInteger >> 1;
if (((long)v_anInteger & 1) && (index >= 0) && (index <
(long)self->v__size))
return ((oop *)v_self)[1 + index];
}.
^self primitiveFailed
]
_vector at: anInteger put: anObject
[
{
long index= (long)v_anInteger >> 1;
if (((long)v_anInteger & 1) && (index >= 0) && (index <
(long)self->v__size))
return ((oop *)v_self)[1 + index]= v_anObject;
}.
^self primitiveFailed
]
"----------------------------------------------------------------"
_vtable tally [ ^SmallInteger value_: _tally ]
_vtable tally: anInteger [ _tally := anInteger _integerValue ]
_vtable findIndexOrNil: aSelector
[
0 to: self tally - 1 do: [:index | (bindings at: index) key ==
aSelector ifTrue: [^index]].
^nil
]
_vtable removeMethodAt: aSelector
[
| index |
(index := self findIndexOrNil: aSelector) ifFalse: [^self
errorKeyNotFound: aSelector].
index to: self tally - 1 do: [:i | bindings at: i put: (bindings
at: i + 1)].
self tally: self tally - 1; flush.
]
"----------------------------------------------------------------"
[
'Hello, world\n' put.
String _vtable removeMethodAt: #put asSelector.
'Hello, world\n' put.
]
> A liberal is a person whose interests aren't at stake at the moment
> -- Willis Player
We are grateful to the Washington Post, the New York Times, Time
magazine and other great publications whose directors have attended
our meetings and respected the promises of discretion for almost
forty years. It would have been impossible for us to develop our
plan for the world if we had been subject to the bright lights of
publicity during those years. But the world is now more
sophisticated and prepared to march towards a world-government. The
supranational sovereignty of an intellectual elite and world bankers
is surely preferable to the National auto-determination practised in
past centuries.
-- David Rockefeller, addressing the Trilateral Commission, 1991
_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc