X Tutup
Skip to content

Commit 845a2c1

Browse files
committed
Fix implementation of #greaseByteAt:, #greaseBytesCount in Pharo 7
1 parent f67408f commit 845a2c1

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
*Grease-Pharo70-Core
22
greaseByteAt: index
3-
^ self byteAt: index
3+
"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."
4+
5+
<primitive: 60>
6+
self greaseBytesCount < index
7+
ifTrue: [^0]
8+
ifFalse: [^super at: index]
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
*Grease-Pharo70-Core
22
greaseBytesCount
3-
^ self bytesCount
3+
"Primitive. Answer the number of indexable fields in the receiver. This
4+
value is the same as the largest legal subscript. Essential. See Object
5+
documentation whatIsAPrimitive."
6+
7+
<primitive: 62>
8+
self primitiveFailed
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
*Grease-Pharo70-Core
2-
greaseByteAt: index
3-
^ self byteAt: index
2+
greaseByteAt: n
3+
"Answer the value of an apparent byte-indexable field in the receiver,
4+
analogous to the large integers, which are organized as bytes."
5+
6+
n = 1
7+
ifTrue: [
8+
"Negate carefully in case the receiver is SmallInteger minVal"
9+
^ self < 0
10+
ifTrue: [ -256 - self bitAnd: 255 ]
11+
ifFalse: [ self bitAnd: 255 ] ].
12+
^ self < 0
13+
ifTrue: [ (-256 - self bitShift: -8) + 1 byteAt: n - 1 ]
14+
ifFalse: [ (self bitShift: 8 - (n bitShift: 3)) bitAnd: 255 ]
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
11
*Grease-Pharo70-Core
22
greaseBytesCount
3-
^ self bytesCount
3+
"Answer the number of indexable fields in the receiver. This value is the
4+
same as the largest legal subscript. Included so that a SmallInteger can
5+
behave like a LargePositiveInteger or LargeNegativeInteger."
6+
7+
"32768 == (1 bitShift: 15)"
8+
"32768 bytesCount >>> 2"
9+
10+
"65536 == (1 bitShift: 16)"
11+
"65536 bytesCount >>> 3"
12+
13+
| value length |
14+
length := 1.
15+
value := self.
16+
value >= 0
17+
ifTrue:
18+
[[value > 255] whileTrue:
19+
[value := value bitShift: -8.
20+
length := length + 1]]
21+
ifFalse:
22+
[[value < -255] whileTrue:
23+
[value := value bitShift: -8.
24+
length := length + 1]].
25+
^length

0 commit comments

Comments
 (0)
X Tutup