DependentsArray size how does it work ?

nicolas cellier ncellier at ifrance.com
Wed Feb 8 03:38:52 UTC 2006


DependentsArray>>size
 ^self inject: 0 into: [ :count :dep | dep ifNotNil: [ count := count + 1 ]]

Byte Code:
9 <70> self
10 <75> pushConstant: 0
11 <89> pushThisContext: 
12 <77> pushConstant: 2
13 <C8> send: blockCopy:
14 <A4 0E> jumpTo: 30
16 <69> popIntoTemp: 1
17 <68> popIntoTemp: 0
18 <11> pushTemp: 1
19 <73> pushConstant: nil
20 <C6> send: ==
21 <99> jumpFalse: 24
22 <73> pushConstant: nil
23 <94> jumpTo: 29
24 <10> pushTemp: 0
25 <76> pushConstant: 1
26 <B0> send: +
27 <81 40> storeIntoTemp: 0
29 <7D> blockReturn
30 <F0> send: inject:into:
31 <7C> returnTop

inject: thisValue into: binaryBlock 
 | nextValue |
 nextValue := thisValue.
 self do: [:each | nextValue := binaryBlock value: nextValue value: each].
 ^nextValue

"This one works..."
| obj  |
obj := Object new.
obj addDependent: nil.
obj addDependent: $0.
obj addDependent: nil.
^obj dependents size


It seems that i can learn something with this one:

1) in squeak you can overwrite block arguments (storeIntoTemp: 0), in not many 
Smalltalk you can do that i guess (not in VW anyway).
In my opinion this is never something to do.

2) there must be a trick somewhere...

On first pass, inject:into: should evaluate with count:0 dep:nil
We will go through:
22 <73> pushConstant: nil
23 <94> jumpTo: 29
...
29 <7D> blockReturn

Then the block should answer nil, shouldn't it ?

Then, on second pass, shouldn't the block evaluate with: count:nil dep:$0 ?
Then, we would have count := nil+1 that would fail, that's what i imagined...

Not at all, all is going fine. Can anybody teach me ?




More information about the Squeak-dev mailing list