Skip to content

Commit

Permalink
Merge pull request #161 from theseion/add-integer-greaseasbytearray
Browse files Browse the repository at this point in the history
Add #greaseAsByteArray and implementation for Squeak
  • Loading branch information
jbrichau authored Nov 4, 2023
2 parents 05a6c4e + f7d9822 commit 3a4e4bc
Show file tree
Hide file tree
Showing 138 changed files with 722 additions and 276 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Core
greaseAsByteArray
^ self asByteArray
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "Collection"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
encoding
integerAsByteArray: anInteger
^ anInteger asByteArray
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Core
greaseAsByteArray
^ GRPlatform current integerAsByteArray: self
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Core
greaseByteAt: index
^ self subclassResponsibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Core
greaseBytesCount
^ self subclassResponsibility
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*grease-gemstone-core
greaseByteAt: index

^ self digitAt: index
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*grease-gemstone-core
greaseBytesCount

^ self digitLength
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "LargeInteger" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*grease-gemstone-core
greaseByteAt: index

^ self digitAt: index
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*grease-gemstone-core
greaseBytesCount

^ self digitLength
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
"name" : "SmallInteger" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Pharo100-Core
greaseByteAt: index
^ self byteAt: index
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Pharo100-Core
greaseBytesCount
^ self bytesCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "LargeInteger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Pharo100-Core
greaseByteAt: index
^ self byteAt: index
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Pharo100-Core
greaseBytesCount
^ self bytesCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "SmallInteger"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
A WASqueakPlatform is the Squeak implementation of SeasidePlatformSupport, the Seaside class that provides functionality that can not be implemented in a platform independent way.
A GRPharoPlatform is the Pharo implementation of GRPlatform, the Grease class that provides functionality that can not be implemented in a platform independent way.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
encoding
integerAsByteArray: anInteger
| stream |
stream := ByteArray new writeStream.
anInteger greaseBytesCount to: 1 by: -1 do: [:digitIndex |
stream nextPut: (anInteger greaseByteAt: digitIndex)].
^ stream contents
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"commentStamp" : "pmm 6/1/2008 01:03",
"commentStamp" : "pmm 2/1/2014 13:28",
"super" : "GRPlatform",
"category" : "Grease-Pharo60-Core",
"classinstvars" : [ ],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*Grease-Pharo60-Core
greaseByteAt: index
"Primitive. Answer the value of an indexable field in the receiver. LargePositiveInteger uses bytes of base two number, and each is a 'digit' base 256. Fail if the argument (the index) is not an Integer or is out of bounds. Essential. See Object documentation whatIsAPrimitive."

<primitive: 60>
self greaseBytesCount < index
ifTrue: [^0]
ifFalse: [^super at: index]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*Grease-Pharo60-Core
greaseBytesCount
"Primitive. Answer the number of indexable fields in the receiver. This
value is the same as the largest legal subscript. Essential. See Object
documentation whatIsAPrimitive."

<primitive: 62>
self primitiveFailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "LargeInteger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*Grease-Pharo60-Core
greaseByteAt: n
"Answer the value of an apparent byte-indexable field in the receiver,
analogous to the large integers, which are organized as bytes."

n = 1
ifTrue: [
"Negate carefully in case the receiver is SmallInteger minVal"
^ self < 0
ifTrue: [ -256 - self bitAnd: 255 ]
ifFalse: [ self bitAnd: 255 ] ].
^ self < 0
ifTrue: [ (-256 - self bitShift: -8) + 1 byteAt: n - 1 ]
ifFalse: [ (self bitShift: 8 - (n bitShift: 3)) bitAnd: 255 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*Grease-Pharo60-Core
greaseBytesCount
"Answer the number of indexable fields in the receiver. This value is the
same as the largest legal subscript. Included so that a SmallInteger can
behave like a LargePositiveInteger or LargeNegativeInteger."

"32768 == (1 bitShift: 15)"
"32768 bytesCount >>> 2"

"65536 == (1 bitShift: 16)"
"65536 bytesCount >>> 3"

| value length |
length := 1.
value := self.
value >= 0
ifTrue:
[[value > 255] whileTrue:
[value := value bitShift: -8.
length := length + 1]]
ifFalse:
[[value < -255] whileTrue:
[value := value bitShift: -8.
length := length + 1]].
^length
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "SmallInteger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*Grease-Pharo70-Core
greaseByteAt: index
"Primitive. Answer the value of an indexable field in the receiver. LargePositiveInteger uses bytes of base two number, and each is a 'digit' base 256. Fail if the argument (the index) is not an Integer or is out of bounds. Essential. See Object documentation whatIsAPrimitive."

<primitive: 60>
self greaseBytesCount < index
ifTrue: [^0]
ifFalse: [^super at: index]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*Grease-Pharo70-Core
greaseBytesCount
"Primitive. Answer the number of indexable fields in the receiver. This
value is the same as the largest legal subscript. Essential. See Object
documentation whatIsAPrimitive."

<primitive: 62>
self primitiveFailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "LargeInteger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*Grease-Pharo70-Core
greaseByteAt: n
"Answer the value of an apparent byte-indexable field in the receiver,
analogous to the large integers, which are organized as bytes."

n = 1
ifTrue: [
"Negate carefully in case the receiver is SmallInteger minVal"
^ self < 0
ifTrue: [ -256 - self bitAnd: 255 ]
ifFalse: [ self bitAnd: 255 ] ].
^ self < 0
ifTrue: [ (-256 - self bitShift: -8) + 1 byteAt: n - 1 ]
ifFalse: [ (self bitShift: 8 - (n bitShift: 3)) bitAnd: 255 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*Grease-Pharo70-Core
greaseBytesCount
"Answer the number of indexable fields in the receiver. This value is the
same as the largest legal subscript. Included so that a SmallInteger can
behave like a LargePositiveInteger or LargeNegativeInteger."

"32768 == (1 bitShift: 15)"
"32768 bytesCount >>> 2"

"65536 == (1 bitShift: 16)"
"65536 bytesCount >>> 3"

| value length |
length := 1.
value := self.
value >= 0
ifTrue:
[[value > 255] whileTrue:
[value := value bitShift: -8.
length := length + 1]]
ifFalse:
[[value < -255] whileTrue:
[value := value bitShift: -8.
length := length + 1]].
^length
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "SmallInteger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Pharo90-Core
greaseByteAt: index
^ self byteAt: index
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Pharo90-Core
greaseBytesCount
^ self bytesCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "LargeInteger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Pharo90-Core
greaseByteAt: index
^ self byteAt: index
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Grease-Pharo90-Core
greaseBytesCount
^ self bytesCount
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "SmallInteger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
encoding
integerAsByteArray: anInteger
| stream |
stream := ByteArray new writeStream.
anInteger greaseBytesCount to: 1 by: -1 do: [:digitIndex |
stream nextPut: (anInteger greaseByteAt: digitIndex)].
^ stream contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*Grease-Squeak-Core
greaseByteAt: index
"Primitive. Answer the value of an indexable field in the receiver. LargePositiveInteger uses bytes of base two number, and each is a 'digit' base 256. Fail if the argument (the index) is not an Integer or is out of bounds. Essential. See Object documentation whatIsAPrimitive."

<primitive: 60>
self greaseBytesCount < index
ifTrue: [^0]
ifFalse: [^super at: index]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*Grease-Squeak-Core
greaseBytesCount
"Primitive. Answer the number of indexable fields in the receiver. This
value is the same as the largest legal subscript. Essential. See Object
documentation whatIsAPrimitive."

<primitive: 62>
self primitiveFailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name" : "LargeInteger"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Please describe the package using the class comment of the included manifest class. The manifest class also includes other additional metadata for the package. These meta data are used by other tools such as the SmalllintManifestChecker and the critics Browser
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
code-critics
ruleLiteralArrayContainsSuspiciousTrueFalseOrNilRuleV1FalsePositive
^ #(#(#(#RGMetaclassDefinition #(#'ManifestGreaseSqueakCore class' #ManifestGreaseSqueakCore)) #'2023-10-29T14:22:04.342701+01:00') )
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
code-critics
ruleSendsDifferentSuperRuleV1FalsePositive
^ #(#(#(#RGMethodDefinition #(#LargeInteger #greaseByteAt: #false)) #'2023-10-29T14:21:20.47823+01:00') )
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
code-critics
ruleSuperSendsRuleV1FalsePositive
^ #(#(#(#RGMethodDefinition #(#LargeInteger #greaseByteAt: #false)) #'2023-10-29T14:20:58.840268+01:00') )
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "<historical>",
"super" : "PackageManifest",
"category" : "Grease-Squeak-Core-Manifest",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "ManifestGreaseSqueakCore",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*Grease-Squeak-Core
greaseByteAt: n
"Answer the value of an apparent byte-indexable field in the receiver,
analogous to the large integers, which are organized as bytes."

n = 1
ifTrue: [
"Negate carefully in case the receiver is SmallInteger minVal"
^ self < 0
ifTrue: [ -256 - self bitAnd: 255 ]
ifFalse: [ self bitAnd: 255 ] ].
^ self < 0
ifTrue: [ (-256 - self bitShift: -8) + 1 byteAt: n - 1 ]
ifFalse: [ (self bitShift: 8 - (n bitShift: 3)) bitAnd: 255 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*Grease-Squeak-Core
greaseBytesCount
"Answer the number of indexable fields in the receiver. This value is the
same as the largest legal subscript. Included so that a SmallInteger can
behave like a LargePositiveInteger or LargeNegativeInteger."

"32768 == (1 bitShift: 15)"
"32768 bytesCount >>> 2"

"65536 == (1 bitShift: 16)"
"65536 bytesCount >>> 3"

| value length |
length := 1.
value := self.
value >= 0
ifTrue:
[[value > 255] whileTrue:
[value := value bitShift: -8.
length := length + 1]]
ifFalse:
[[value < -255] whileTrue:
[value := value bitShift: -8.
length := length + 1]].
^length
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SystemOrganization addCategory: #'Grease-Squeak-Core'!
SystemOrganization addCategory: #'Grease-Squeak-Core-Manifest'!
Loading

0 comments on commit 3a4e4bc

Please sign in to comment.