--- a/ByteCodeCompiler.st Wed Aug 09 14:00:27 2006 +0200
+++ b/ByteCodeCompiler.st Wed Aug 09 14:00:53 2006 +0200
@@ -15,7 +15,7 @@
Parser subclass:#ByteCodeCompiler
instanceVariableNames:'codeBytes codeIndex litArray stackDelta extra lineno extraLiteral
maxStackDepth relocList methodTempVars numTemp maxNumTemp
- methodClass extraOP allLiterals'
+ methodClass extraOP allLiterals allIdenticalLiterals'
classVariableNames:'JumpToAbsJump ShareCode ListCompiledMethods NewCodeSet
NewPrimitives'
poolDictionaries:''
@@ -2498,29 +2498,58 @@
"add a literal to the literalArray - watch for and eliminate
duplicates. return the index of the literal in the Array"
- |index "{ Class: SmallInteger }" oldLit class|
+ |index "{ Class: SmallInteger }" oldLit class sharable sharableValue|
litArray isNil ifTrue:[
litArray := OrderedCollection with:anObject.
^ 1
].
- "/ searching a set is *much* faster; the code below starts to
+ sharable := sharableValue := false.
+ class := anObject class.
+ class == Symbol
+ ifTrue:[ sharable := true ]
+ ifFalse:[
+ ((class == String) or:[class == Array or:[class == ByteArray]]) ifTrue:[
+ anObject size == 0 ifTrue:[
+ sharable := true
+ ]
+ ] ifFalse:[
+ ((class == Float) or:[class == Fraction or:[class == LargeInteger]]) ifTrue:[
+ sharableValue := true
+ ]
+ ]
+ ].
+
+ (sharable not and:[sharableValue not]) ifTrue:[
+ litArray add:anObject.
+ index := litArray size.
+ ^ index.
+ ].
+
+ "/ searching a dictionary is *much* faster; the code below starts to
"/ keep track of literals whenever we have collected more than a threshold
allLiterals notNil ifTrue:[
- (allLiterals includes:anObject) ifFalse:[
- litArray add:anObject.
- allLiterals add:anObject.
- ^ litArray size.
+ sharable ifTrue:[
+ index := allLiterals at:anObject ifAbsent:nil.
+ index isNil ifTrue:[
+ litArray add:anObject.
+ index := litArray size.
+ allLiterals at:anObject put:index.
+ ^ index.
+ ].
+ (litArray at:index) class ~~ anObject class ifTrue:[
+ index := nil.
+ ].
].
].
-
- index := litArray identityIndexOf:anObject.
+ index isNil ifTrue:[
+ index := litArray identityIndexOf:anObject.
+ ].
(index == 0) ifTrue:[
"
reuse constants if same value and same class
"
- class := anObject class.
((class == Float)
or:[class == Fraction
or:[class == LargeInteger
@@ -2555,9 +2584,10 @@
index := litArray size.
index > 30 ifTrue:[
allLiterals isNil ifTrue:[
- allLiterals := litArray asSet.
+ allLiterals := Dictionary new.
+ litArray keysAndValuesDo:[:idx :lit | allLiterals at:lit put:idx].
].
- allLiterals add:anObject.
+ allLiterals at:anObject put:index.
].
].
].
@@ -3201,42 +3231,35 @@
^ true
!
-isBuiltIn1ArgSelector:sel forReceiver:receiver
- "return true, if selector sel is built-in.
+isBuiltInSelector:sel forReceiver:receiver
+ "return true, if selector sel is built-in.
(i.e. there is a single bytecode for it)"
- (sel == #at:) ifTrue:[^ true].
- (sel == #value:) ifTrue:[^ true].
- (sel == #bitAnd:) ifTrue:[^ true].
- (sel == #bitOr:) ifTrue:[^ true].
- (sel == #new:) ifTrue:[^ true].
- (sel == #basicNew:) ifTrue:[
- "/ this one is critical - some redefine it
- receiver isGlobal ifTrue:[
- (#('String' 'ByteArray' 'Array'
- 'Point' 'Rectangle' 'Object')
- includes:receiver name) ifTrue:[^ true].
- ].
+ (sel == #value) ifTrue:[^ true].
+ (sel == #value:) ifTrue:[^ true].
+ (sel == #class) ifTrue:[^ true].
+ (sel == #size) ifTrue:[^ true].
+ (sel == #isNil) ifTrue:[^ true].
+ (sel == #notNil) ifTrue:[^ true].
+ (sel == #not) ifTrue:[^ true].
+
+ (sel == #new) ifTrue:[^ true].
+ (sel == #basicNew) ifTrue:[
+ "/ this one is critical - some redefine it
+ receiver isGlobal ifTrue:[
+ (#('String' 'ByteArray' 'Array'
+ 'Point' 'Rectangle' 'Object')
+ includes:receiver name) ifTrue:[^ true].
+ ].
].
- ^ false
-
- "Created: 17.4.1996 / 22:33:13 / cg"
- "Modified: 4.6.1997 / 12:24:18 / cg"
-!
-
-isBuiltIn2ArgSelector:sel forReceiver:receiver
- "return true, if selector sel is built-in.
- (i.e. there is a single bytecode for it)"
-
- (sel == #at:put:) ifTrue:[^ true].
- ^ false
-
- "Created: 17.4.1996 / 22:33:16 / cg"
-!
-
-isBuiltInBinarySelector:sel forReceiver:receiver
- "return true, if binary selector sel is built-in.
- (i.e. there is a single bytecode for it)"
+ (sel == #basicNew:) ifTrue:[
+ "/ this one is critical - some redefine it
+ receiver isGlobal ifTrue:[
+ (#('String' 'ByteArray' 'Array'
+ 'Point' 'Rectangle' 'Object')
+ includes:receiver name) ifTrue:[^ true].
+ ].
+ ].
sel == #== ifTrue:[^ true].
sel == #~~ ifTrue:[^ true].
@@ -3251,32 +3274,13 @@
sel == #* ifTrue:[^ true].
sel == #& ifTrue:[^ true].
sel == #| ifTrue:[^ true].
- ^ false
-
- "Created: 17.4.1996 / 22:34:27 / cg"
- "Modified: 4.6.1997 / 12:24:00 / cg"
-!
-
-isBuiltInUnarySelector:sel forReceiver:receiver
- "return true, if unary selector sel is built-in.
- (i.e. there is a single bytecode for it)"
-
- (sel == #value) ifTrue:[^ true].
- (sel == #class) ifTrue:[^ true].
- (sel == #size) ifTrue:[^ true].
- (sel == #isNil) ifTrue:[^ true].
- (sel == #notNil) ifTrue:[^ true].
- (sel == #not) ifTrue:[^ true].
-
- (sel == #new) ifTrue:[^ true].
- (sel == #basicNew) ifTrue:[
- "/ this one is critical - some redefine it
- receiver isGlobal ifTrue:[
- (#('String' 'ByteArray' 'Array'
- 'Point' 'Rectangle' 'Object')
- includes:receiver name) ifTrue:[^ true].
- ].
- ].
+
+ (sel == #at:) ifTrue:[^ true].
+ (sel == #at:put:) ifTrue:[^ true].
+ (sel == #bitAnd:) ifTrue:[^ true].
+ (sel == #bitOr:) ifTrue:[^ true].
+ (sel == #new:) ifTrue:[^ true].
+
^ false
"Created: 17.4.1996 / 22:32:16 / cg"
@@ -3376,7 +3380,7 @@
!ByteCodeCompiler class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libcomp/ByteCodeCompiler.st,v 1.241 2006-08-08 21:37:08 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libcomp/ByteCodeCompiler.st,v 1.242 2006-08-09 12:00:53 cg Exp $'
! !
ByteCodeCompiler initialize!