X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix implementation of #greaseByteAt:, #greaseBytesCount in Pharo 7
  • Loading branch information
theseion committed Oct 29, 2023
commit 845a2c13d8bcbcb30ff87fcb42195db29d8d7544
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
*Grease-Pharo70-Core
greaseByteAt: index
^ self byteAt: 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
@@ -1,3 +1,8 @@
*Grease-Pharo70-Core
greaseBytesCount
^ self bytesCount
"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
@@ -1,3 +1,14 @@
*Grease-Pharo70-Core
greaseByteAt: index
^ self byteAt: index
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
@@ -1,3 +1,25 @@
*Grease-Pharo70-Core
greaseBytesCount
^ self bytesCount
"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
X Tutup