Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20979-Introducing-DoubleWord-and-DoubleByte-arrays #689

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Collections-Native/DoubleByteArray.class.st
@@ -0,0 +1,33 @@
"
DoubleByteArrays store 16-bit unsigned Integer values.
"
Class {
#name : #DoubleByteArray,
#superclass : #ArrayedCollection,
#type : #words,
#category : #'Collections-Native'
}

{ #category : #accessing }
DoubleByteArray >> byteSize [
^self size * 2
]

{ #category : #accessing }
DoubleByteArray >> bytesPerElement [
"Number of bytes in each item. This multiplied by (self size)*8 gives the number of bits stored."
^ 2
]

{ #category : #accessing }
DoubleByteArray >> defaultElement [
"Return the default element of the receiver"
^0
]

{ #category : #private }
DoubleByteArray >> replaceFrom: start to: stop with: replacement startingAt: repStart [
"Primitive. This destructively replaces elements from start to stop in the receiver starting at index, repStart, in the collection, replacement. Answer the receiver. Range checks are performed in the primitive only. Optional. See Object documentation whatIsAPrimitive."
<primitive: 105>
super replaceFrom: start to: stop with: replacement startingAt: repStart
]
33 changes: 33 additions & 0 deletions src/Collections-Native/DoubleWordArray.class.st
@@ -0,0 +1,33 @@
"
DoubleWordArrays store 64-bit unsigned Integer values.
"
Class {
#name : #DoubleWordArray,
#superclass : #ArrayedCollection,
#type : #words,
#category : #'Collections-Native'
}

{ #category : #accessing }
DoubleWordArray >> byteSize [
^self size * 8
]

{ #category : #accessing }
DoubleWordArray >> bytesPerElement [
"Number of bytes in each item. This multiplied by (self size)*8 gives the number of bits stored."
^ 8
]

{ #category : #accessing }
DoubleWordArray >> defaultElement [
"Return the default element of the receiver"
^0
]

{ #category : #private }
DoubleWordArray >> replaceFrom: start to: stop with: replacement startingAt: repStart [
"Primitive. This destructively replaces elements from start to stop in the receiver starting at index, repStart, in the collection, replacement. Answer the receiver. Range checks are performed in the primitive only. Optional. See Object documentation whatIsAPrimitive."
<primitive: 105>
super replaceFrom: start to: stop with: replacement startingAt: repStart
]
222 changes: 221 additions & 1 deletion src/Kernel/Class.class.st
Expand Up @@ -1648,6 +1648,226 @@ Class >> variableByteSubclass: aName uses: aTraitComposition instanceVariableNam
category: aCategory ]
]

{ #category : #'subclass creation - variableDoubleByte' }
Class >> variableDoubleByteSubclass: className instanceVariableNames: instVarNames
classVariableNames: classVarNames category: cat [
"Added to allow for a simplified subclass creation experience. "

^ self variableDoubleByteSubclass: className
instanceVariableNames: instVarNames
classVariableNames: classVarNames
poolDictionaries: ''
package: cat
]

{ #category : #'subclass creation - variableDoubleByte' }
Class >> variableDoubleByteSubclass: className instanceVariableNames: instVarNames
classVariableNames: classVarNames package: cat [
"
Variable double byte is like variable byte (ByteArray), variable size, with indices instead of named instance variables, but each index points to a double byte (16bit).

Objects on the heap are either pointers or bits. For example instances of Point, Array, BlockClosure etc are pointer objects. But Bitmap, ByteString, WideString etc are bits objects. In v3 bits objects are either a sequence of bytes (ByteArray, ByteString, ByteSymbol etc) or 32-bit words (WideString, Float, Bitmap etc). Spur supports byte, short, word and double-word bits objects even though currently only byte and word classes exist. 16-bit strings will be useful on Windows, for example.
"

^ self variableDoubleByteSubclass: className
instanceVariableNames: instVarNames
classVariableNames: classVarNames
poolDictionaries: ''
package: cat
]

{ #category : #'subclass creation - variableDoubleByte' }
Class >> variableDoubleByteSubclass: t instanceVariableNames: f classVariableNames: d poolDictionaries: s category: cat [
^ self
variableDoubleByteSubclass: t
instanceVariableNames: f
classVariableNames: d
poolDictionaries: s
package: cat
]

{ #category : #'subclass creation - variableDoubleByte' }
Class >> variableDoubleByteSubclass: t instanceVariableNames: f
classVariableNames: d poolDictionaries: s package: cat [
"This is the standard initialization message for creating a new class as a
subclass of an existing class (the receiver) in which the subclass is to
have indexable word-sized nonpointer variables."
^ self classInstaller make: [ :builder |
builder
superclass: self;
name: t;
layoutClass: DoubleByteLayout;
slots: f asSlotCollection;
sharedVariablesFromString: d;
sharedPools: s;
category: cat;
environment: self environment;
copyClassSlotsFromExistingClass ].
]

{ #category : #'subclass creation - variableDoubleByte' }
Class >> variableDoubleByteSubclass: className uses: aTraitCompositionOrArray instanceVariableNames: instVarNames classVariableNames: classVarNames category: cat [
"Added to allow for a simplified subclass creation experience. "

^ self
variableDoubleByteSubclass: className
uses: aTraitCompositionOrArray
instanceVariableNames: instVarNames
classVariableNames: classVarNames
package: cat
]

{ #category : #'subclass creation - variableDoubleByte' }
Class >> variableDoubleByteSubclass: className uses: aTraitCompositionOrArray instanceVariableNames: instVarNames
classVariableNames: classVarNames package: cat [
"Added to allow for a simplified subclass creation experience. "

^ self variableDoubleByteSubclass: className
uses: aTraitCompositionOrArray
instanceVariableNames: instVarNames
classVariableNames: classVarNames
poolDictionaries: ''
package: cat
]

{ #category : #'subclass creation - variableDoubleByte' }
Class >> variableDoubleByteSubclass: aName uses: aTraitComposition instanceVariableNames: someInstanceVariableNames classVariableNames: someClassVariableNames poolDictionaries: someSharedPoolNames category: aCategory [
^ self
variableDoubleByteSubclass: aName
uses: aTraitComposition
instanceVariableNames: someInstanceVariableNames
classVariableNames: someClassVariableNames
poolDictionaries: someSharedPoolNames
package: aCategory
]

{ #category : #'subclass creation - variableDoubleByte' }
Class >> variableDoubleByteSubclass: aName uses: aTraitComposition instanceVariableNames: someInstanceVariableNames classVariableNames: someClassVariableNames poolDictionaries: someSharedPoolNames package: aCategory [
"Creates a new class as a subclass of an existing class (the receiver)
in which the subclass is to have indexable word-sized nonpointer variables."

^ self
subclass: aName
uses: aTraitComposition
with: [
self
variableDoubleByteSubclass: aName
instanceVariableNames: someInstanceVariableNames
classVariableNames: someClassVariableNames
poolDictionaries: someSharedPoolNames
package: aCategory ]
]

{ #category : #'subclass creation - variableDoubleWord' }
Class >> variableDoubleWordSubclass: className instanceVariableNames: instVarNames
classVariableNames: classVarNames category: cat [
"Added to allow for a simplified subclass creation experience. "

^ self variableDoubleWordSubclass: className
instanceVariableNames: instVarNames
classVariableNames: classVarNames
poolDictionaries: ''
package: cat
]

{ #category : #'subclass creation - variableDoubleWord' }
Class >> variableDoubleWordSubclass: className instanceVariableNames: instVarNames
classVariableNames: classVarNames package: cat [
"
Variable double word is like variable byte (ByteArray), variable size, with indices instead of named instance variables, but each index points to a double word (64bit).

Objects on the heap are either pointers or bits. For example instances of Point, Array, BlockClosure etc are pointer objects. But Bitmap, ByteString, WideString etc are bits objects. In v3 bits objects are either a sequence of bytes (ByteArray, ByteString, ByteSymbol etc) or 32-bit words (WideString, Float, Bitmap etc). Spur supports byte, short, word and double-word bits objects even though currently only byte and word classes exist. 16-bit strings will be useful on Windows, for example.
"

^ self variableDoubleWordSubclass: className
instanceVariableNames: instVarNames
classVariableNames: classVarNames
poolDictionaries: ''
package: cat
]

{ #category : #'subclass creation - variableDoubleWord' }
Class >> variableDoubleWordSubclass: t instanceVariableNames: f classVariableNames: d poolDictionaries: s category: cat [
^ self
variableDoubleWordSubclass: t
instanceVariableNames: f
classVariableNames: d
poolDictionaries: s
package: cat
]

{ #category : #'subclass creation - variableDoubleWord' }
Class >> variableDoubleWordSubclass: t instanceVariableNames: f
classVariableNames: d poolDictionaries: s package: cat [
"This is the standard initialization message for creating a new class as a
subclass of an existing class (the receiver) in which the subclass is to
have indexable word-sized nonpointer variables."
^ self classInstaller make: [ :builder |
builder
superclass: self;
name: t;
layoutClass: DoubleWordLayout;
slots: f asSlotCollection;
sharedVariablesFromString: d;
sharedPools: s;
category: cat;
environment: self environment;
copyClassSlotsFromExistingClass ].
]

{ #category : #'subclass creation - variableDoubleWord' }
Class >> variableDoubleWordSubclass: className uses: aTraitCompositionOrArray instanceVariableNames: instVarNames classVariableNames: classVarNames category: cat [
"Added to allow for a simplified subclass creation experience. "

^ self
variableDoubleWordSubclass: className
uses: aTraitCompositionOrArray
instanceVariableNames: instVarNames
classVariableNames: classVarNames
package: cat
]

{ #category : #'subclass creation - variableDoubleWord' }
Class >> variableDoubleWordSubclass: className uses: aTraitCompositionOrArray instanceVariableNames: instVarNames
classVariableNames: classVarNames package: cat [
"Added to allow for a simplified subclass creation experience. "

^ self variableDoubleWordSubclass: className
uses: aTraitCompositionOrArray
instanceVariableNames: instVarNames
classVariableNames: classVarNames
poolDictionaries: ''
package: cat
]

{ #category : #'subclass creation - variableDoubleWord' }
Class >> variableDoubleWordSubclass: aName uses: aTraitComposition instanceVariableNames: someInstanceVariableNames classVariableNames: someClassVariableNames poolDictionaries: someSharedPoolNames category: aCategory [
^ self
variableDoubleWordSubclass: aName
uses: aTraitComposition
instanceVariableNames: someInstanceVariableNames
classVariableNames: someClassVariableNames
poolDictionaries: someSharedPoolNames
package: aCategory
]

{ #category : #'subclass creation - variableDoubleWord' }
Class >> variableDoubleWordSubclass: aName uses: aTraitComposition instanceVariableNames: someInstanceVariableNames classVariableNames: someClassVariableNames poolDictionaries: someSharedPoolNames package: aCategory [
"Creates a new class as a subclass of an existing class (the receiver)
in which the subclass is to have indexable word-sized nonpointer variables."

^ self
subclass: aName
uses: aTraitComposition
with: [
self
variableDoubleWordSubclass: aName
instanceVariableNames: someInstanceVariableNames
classVariableNames: someClassVariableNames
poolDictionaries: someSharedPoolNames
package: aCategory ]
]

{ #category : #'subclass creation - variable' }
Class >> variableSubclass: className instanceVariableNames: instVarNames classVariableNames: classVarNames category: cat [
"Added to allow for a simplified subclass creation experience. "
Expand Down Expand Up @@ -1747,7 +1967,7 @@ Class >> variableWordSubclass: className instanceVariableNames: instVarNames
Class >> variableWordSubclass: className instanceVariableNames: instVarNames
classVariableNames: classVarNames package: cat [
"
Variable word is like variable byte (ByteArray), variable size, with indices instead of named instance variables, but each index points to a full word (either 32 or 64bit depending on the VM).
Variable word is like variable byte (ByteArray), variable size, with indices instead of named instance variables, but each index points to a full word (32 bits).

Objects on the heap are either pointers or bits. For example instances of Point, Array, BlockClosure etc are pointer objects. But Bitmap, ByteString, WideString etc are bits objects. In v3 bits objects are either a sequence of bytes (ByteArray, ByteString, ByteSymbol etc) or 32-bit words (WideString, Float, Bitmap etc). Spur supports byte, short, word and double-word bits objects even though currently only byte and word classes exist. 16-bit strings will be useful on Windows, for example.
"
Expand Down
46 changes: 44 additions & 2 deletions src/Slot/BitsLayout.class.st
Expand Up @@ -23,6 +23,30 @@ BitsLayout >> extendAgain: aLayout with: aScope [
yourself
]

{ #category : #extending }
BitsLayout >> extendByte [
IncompatibleLayoutConflict new
layout: self;
subType: #byte;
signal
]

{ #category : #extending }
BitsLayout >> extendDoubleByte [
IncompatibleLayoutConflict new
layout: self;
subType: #doubleByte;
signal
]

{ #category : #extending }
BitsLayout >> extendDoubleWord [
IncompatibleLayoutConflict new
layout: self;
subType: #doubleWord;
signal
]

{ #category : #extending }
BitsLayout >> extendWeak: aLayoutClassScope [
IncompatibleLayoutConflict new
Expand All @@ -31,6 +55,14 @@ BitsLayout >> extendWeak: aLayoutClassScope [
signal
]

{ #category : #extending }
BitsLayout >> extendWord [
IncompatibleLayoutConflict new
layout: self;
subType: #word;
signal
]

{ #category : #'initialize-release' }
BitsLayout >> initializeInstance: anInstance [
]
Expand All @@ -42,7 +74,17 @@ BitsLayout >> isBits [

{ #category : #testing }
BitsLayout >> isBytes [
^ self subclassResponsibility
^ false
]

{ #category : #testing }
BitsLayout >> isDoubleBytes [
^ false
]

{ #category : #testing }
BitsLayout >> isDoubleWords [
^ false
]

{ #category : #testing }
Expand All @@ -52,7 +94,7 @@ BitsLayout >> isVariable [

{ #category : #testing }
BitsLayout >> isWords [
^ self isBytes not
^ false
]

{ #category : #reshaping }
Expand Down
9 changes: 3 additions & 6 deletions src/Slot/ByteLayout.class.st
@@ -1,5 +1,5 @@
"
I am a raw data layout that holds bytes (8 bit).
I am a raw data layout that holds bytes (8 bits).
"
Class {
#name : #ByteLayout,
Expand All @@ -15,11 +15,8 @@ ByteLayout class >> extending: superLayout scope: aScope host: aClass [
]

{ #category : #extending }
ByteLayout >> extendWord [
IncompatibleLayoutConflict new
layout: self;
subType: #word;
signal
ByteLayout >> extendByte [
^ ByteLayout new
]

{ #category : #format }
Expand Down