[contents]
[contents]
[contents]
ゴミ処理問題や産業廃棄物問題をほったらかしにしていると、必然的に滅亡します。
直接指さない
直接アドレッシング (direct addressing) | 間接アドレッシング (indirect addressing) |
---|---|
リンクリストに直接ヒープ内のアドレスのポインタを格納する。 | テーブルを用意し、要素のリンクリストにはテーブルの相対アドレスを格納する。 |
例えば、セミラティス (ループがあるのでツリーではない) 内の要素の一つのアドレスが変わったとする。 また、ある要素と別の要素を交換したいとする。 |
|
後始末がたいへん。何かするたびにセミラティス内の要素を全部廻って調査しなければならない。 | テーブル内の相対アドレスを書き換えるだけで済む。 |
[contents]
aBlock value.
[ 4 [ 5 [ ] value] value].
aBoolean ifTrue: trueBlock ifFalse: falseBlock.
anInteger timesRepeat: repeatBlock.
anArray do: repeatBlock.
doBlock ensure: (valueNowOrOnUnwindDo) rewindBlock.
Object errorSignal handle: exceptionBlock do: doBlock.
aBlock fork.
p := [... p send: v ....] promise.
...
p receive
aBlock newProcess.
aProcess resume.
aProcess terminate.
aProcess priority: Processor userInterruptPriority.
aSemaphore := Semaphore new.
aSemaphore wait.
aSemaphore signal.
Q: なぜ型変換なしに計算ができるのか? (実はやってくれている)
SmallInteger>>- aNumber
"Answer the result of subtracting the argument from the receiver.
Fail if the argument or the result is not a SmallInteger.
No Lookup."
<primitive: 2>
^aNumber differenceFromInteger: self
ちなみに、原始メソッド 1 番は加算 (Blue Book, p.612)。
+ aNumber
"Answer the result of adding the receiver to the argument.
Fail if the argument or the result is not a SmallInteger.
No Lookup."
<primitive: 1>
^aNumber sumFromInteger: self
大きさを持つものの具象クラスの一般性 | |
---|---|
Jun3dPoint | 220 |
Jun2dPoint | 200 |
Point | 180 |
JunPenLocation | 170 |
Complex | 150 |
JunAngle | 120 |
MetaNumeric | 120 |
JunPenAngle | 110 |
Double | 90 |
Float | 80 |
FixedPoint | 70 |
Fraction | 60 |
Integer | 40 |
SmallInteger | 20 |
generality が異なるもの同志を演算する場合、generality が小さいものは大きいものの generality と一致するまで、強制 (coerce:) 的に変換されていく。
ArithmeticValue>>retry: aSymbol coercing: aNumber
"Arithmetic represented by the symbol, aSymbol, could not be
performed with the receiver and the argument, aNumber, because
of the differences in representation. Coerce either the receiver or the
argument, depending on which has higher generality, and try again.
If the generalities are the same, then this message
should not have been sent so an error notification is provided."
self generality < aNumber generality
ifTrue: [^(aNumber coerce: self) perform: aSymbol with: aNumber].
self generality > aNumber generality
ifTrue: [^self perform: aSymbol with: (self coerce: aNumber)].
self error: 'coercion attempt failed'
[contents]
(JunSystem compiledMethodAt: #update:) symbolic
'normal CompiledMethod numArgs=1 numTemps=0 frameSize=12
literals: (#finishedSnapshot #returnFromSnapshot #login #prologue
#aboutToQuit #aboutToSnapshot #epilogue #logout #condenseChanges
''no operation'' #yourself )
1 <10> push local 0
2 <1C> push #finishedSnapshot
3 <A6> send =
4 <C1> jump false 7
5 <47> push true
6 <6D> jump 10
7 <10> push local 0
8 <1D> push #returnFromSnapshot
9 <A6> send =
10 <E8 12> jump false 30
12 <10> push local 0
13 <1D> push #returnFromSnapshot
14 <A6> send =
15 <C4> jump false 21
16 <44> push self
17 <CE 17> non-immediate send class
19 <72> send login
20 <66> pop
21 <10> push local 0
22 <1C> push #finishedSnapshot
23 <A6> send =
24 <C4> jump false 30
25 <44> push self
26 <CE 17> non-immediate send class
28 <73> send prologue
29 <66> pop
30 <10> push local 0
31 <20> push #aboutToQuit
32 <A6> send =
33 <C1> jump false 36
34 <47> push true
35 <6D> jump 39
36 <10> push local 0
37 <21> push #aboutToSnapshot
38 <A6> send =
39 <E8 12> jump false 59
41 <10> push local 0
42 <21> push #aboutToSnapshot
43 <A6> send =
44 <C4> jump false 50
45 <44> push self
46 <CE 17> non-immediate send class
48 <76> send epilogue
49 <66> pop
50 <10> push local 0
51 <20> push #aboutToQuit
52 <A6> send =
53 <C4> jump false 59
54 <44> push self
55 <CE 17> non-immediate send class
57 <77> send logout
58 <66> pop
59 <10> push local 0
60 <24> push #condenseChanges
61 <A6> send =
62 <C3> jump false 67
63 <25> push ''no operation''
64 <CC 0A> no-check send yourself
66 <66> pop
67 <60> push self; return
'
"任意のオブジェクトの大きさをバイト単位で計算します。"
| byteSizeOfObject |
byteSizeOfObject :=
[:anObject |
| bytesInOTE bytesInOOP aClass indexableFieldSize instVarFieldSize byteSize |
bytesInOTE := ObjectMemory current bytesPerOTE.
bytesInOOP := ObjectMemory current bytesPerOOP.
aClass := anObject class.
aClass isPointers
ifTrue:
[instVarFieldSize := aClass instSize * bytesInOOP.
aClass isVariable
ifTrue: [indexableFieldSize := anObject basicSize * bytesInOOP]
ifFalse: [indexableFieldSize := 0]]
ifFalse:
[instVarFieldSize := 0.
aClass isVariable
ifTrue: [indexableFieldSize := anObject basicSize +
(bytesInOOP - 1) bitAnd: bytesInOOP negated]
ifFalse:
[indexableFieldSize := 0.
aClass hasImmediateInstances ifTrue: [bytesInOTE := 0]]].
byteSize := bytesInOTE + instVarFieldSize + indexableFieldSize.
byteSize yourself].
^byteSizeOfObject value: (OrderedCollection new: 10)
Squeak での 例
| aClass baseHeaderSize objectHeadersSize bytesInOOP
instVarFieldSize indexableFieldSize byteSize |
aClass := anObject class.
((aClass == SmallInteger) or: [aClass == Character]) ifTrue: [^0].
baseHeaderSize := self baseHeaderSize.
objectHeadersSize := aClass indexIfCompact > 0
ifTrue: [baseHeaderSize]
ifFalse:
[((self sizeInWordsOf: anObject) + 1 ) > 16r3F
ifTrue: [baseHeaderSize * 3]
ifFalse: [baseHeaderSize * 2]].
bytesInOOP := aClass isBytes ifTrue: [1] ifFalse: [4].
aClass isPointers
ifTrue:
[instVarFieldSize := aClass instSize * bytesInOOP.
aClass isVariable
ifTrue:
[indexableFieldSize := anObject basicSize * bytesInOOP]
ifFalse:
[indexableFieldSize := 0]]
ifFalse:
[instVarFieldSize := 0.
aClass isVariable
ifTrue: [indexableFieldSize := (anObject basicSize + 3) bitAnd: 16r1FFFFFFC]
ifFalse: [indexableFieldSize := 0]].
byteSize := objectHeadersSize + instVarFieldSize + indexableFieldSize.
^byteSize
Context, BlockClosure, CompiledCode, -> ContextStory
[contents]
message pattern signature
anAssertion requireThat: [anObject isKindOf: Foo].
ex)
anObject assert: assertBlock do: doBlock ensure: ensureBlock
^assertBlock value = true ifTrue: [[doBlock value]
valueNowOrOnUnwindDo: [ensureBlock value]]
または
assertBlock value.
^[doBlock value]
valueNowOrOnUnwindDo: [ensureBlock value]
[contents]
SmalltalkLecture18.pdf
Memory Observer: 一定時間間隔で,オブジェクトメモリの中を調べて,現在,存在しているオブジェクトの数と,使用されているメモリ領域の大きさをモニタするオブジェクト; ソース
[contents]
[contents]
see Smalltalk Idioms.
Mask | VisualWorks |
Halftone | BitBlt |
Stipple | OpenGL |
[contents]