X Tutup
Skip to content

Commit 7049682

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

File tree

7 files changed

+57
-7
lines changed

7 files changed

+57
-7
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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.
1+
A GRPharoPlatform is the Pharo implementation of GRPlatform, the Grease class that provides functionality that can not be implemented in a platform independent way.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
encoding
2+
integerAsByteArray: anInteger
3+
| stream |
4+
stream := ByteArray new writeStream.
5+
anInteger greaseBytesCount to: 1 by: -1 do: [:digitIndex |
6+
stream nextPut: (anInteger greaseByteAt: digitIndex)].
7+
^ stream contents

repository/Grease-Pharo60-Core.package/GRPharoPlatform.class/properties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"commentStamp" : "pmm 6/1/2008 01:03",
2+
"commentStamp" : "pmm 2/1/2014 13:28",
33
"super" : "GRPlatform",
44
"category" : "Grease-Pharo60-Core",
55
"classinstvars" : [ ],
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
*Grease-Pharo60-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-Pharo60-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-Pharo60-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-Pharo60-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