--- a/UninterpretedBytes.st Sat Mar 12 19:04:53 2016 +0100
+++ b/UninterpretedBytes.st Sun Mar 13 01:11:32 2016 +0100
@@ -469,7 +469,6 @@
"Modified: / 5.3.1998 / 14:56:22 / stefan"
! !
-
!UninterpretedBytes methodsFor:'Compatibility'!
doubleWordAt:index
@@ -1602,12 +1601,12 @@
bigEndian ifTrue:[
highByte := (self at:index).
index to:index+n-1 do:[:i |
- val := (val<<8) + (self at:i)
+ val := (val<<8) + (self byteAt:i)
]
] ifFalse:[
highByte := (self at:index+n-1).
index+n-1 to:index by:-1 do:[:i |
- val := (val<<8) + (self at:i)
+ val := (val<<8) + (self byteAt:i)
]
].
(highByte bitTest:16r80) ifTrue:[
@@ -1656,13 +1655,13 @@
val := 0.
bigEndian ifTrue:[
- index to:index+n-1 do:[:i |
- val := (val<<8) + (self at:i)
- ]
+ index to:index+n-1 do:[:i |
+ val := (val<<8) + (self byteAt:i)
+ ]
] ifFalse:[
- index+n-1 to:index by:-1 do:[:i |
- val := (val<<8) + (self at:i)
- ]
+ index+n-1 to:index by:-1 do:[:i |
+ val := (val<<8) + (self byteAt:i)
+ ]
].
^ val
@@ -1685,12 +1684,12 @@
val := newValue.
bigEndian ifTrue:[
index to:index+n-1 do:[:i |
- self at:i put:(val bitAnd:16rFF).
+ self byteAt:i put:(val bitAnd:16rFF).
val := val bitShift:-8.
]
] ifFalse:[
index+n-1 to:index by:-1 do:[:i |
- self at:i put:(val bitAnd:16rFF).
+ self byteAt:i put:(val bitAnd:16rFF).
val := val bitShift:-8.
]
].
@@ -1741,19 +1740,126 @@
"Modified (comment): / 26-09-2011 / 11:57:36 / cg"
!
-signedByteAt:index
- "return the byte at index as a signed 8 bit value in the range -128..+127.
- The index is a smalltalk index (i.e. 1-based).
- This may be worth a primitive."
-
- ^ (self at:index) signExtendedByteValue
+byteAt:byteIndex
+ "return the byte at byteIndex as an unsigned 8 bit value in the range 0..255.
+ The index is a smalltalk index (i.e. 1-based)."
+
+%{
+ if (__isSmallInteger(byteIndex)) {
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
+ char ch;
+
+ if (idx < sz) {
+ ch = cp[idx] & 0xFF;
+ RETURN (__mkSmallInteger( ch ));
+ }
+ }
+ }
+%}.
+
+ ^ self at:byteIndex
"
|b|
- b := ByteArray new:2.
+ b := ByteArray new:3.
b at:1 put:16rFF.
b at:2 put:16r7F.
- b signedByteAt:1
+ b at:3 put:16r80.
+ b byteAt:1.
+ b byteAt:2.
+ b byteAt:3.
+ "
+
+ "Modified: / 01-07-1996 / 21:13:53 / cg"
+ "Modified (comment): / 26-09-2011 / 11:57:14 / cg"
+!
+
+byteAt:byteIndex put:anInteger
+ "set the byte at byteIndex as an unsigned 8 bit value in the range 0..255.
+ The index is a smalltalk index (i.e. 1-based)."
+
+%{
+ if (__isSmallInteger(byteIndex) && __isSmallInteger(anInteger)) {
+ unsigned char *cp;
+ INT sz;
+ INT val = __intVal(anInteger);
+
+ if ( ((unsigned INT)val) <= 0xFF ) {
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
+
+ if (idx < sz) {
+ cp[idx] = val & 0xFF;
+ RETURN (anInteger);
+ }
+ }
+ }
+ }
+%}.
+
+ ^ self at:byteIndex put:anInteger
+
+ "
+ |b|
+ b := ByteArray new:3.
+ b byteAt:1 put:16rFF.
+ b byteAt:2 put:16r7F.
+ b byteAt:3 put:16r80.
+ b signedByteAt:1.
+ b signedByteAt:2.
+ b signedByteAt:3.
+ "
+!
+
+signedByteAt:byteIndex
+ "return the byte at byteIndex as a signed 8 bit value in the range -128..+127.
+ The index is a smalltalk index (i.e. 1-based).
+ This may be worth a primitive."
+
+%{
+ /*
+ * handle the most common cases fast ...
+ */
+ if (__isSmallInteger(byteIndex)) {
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(byteIndex)) - 1;
+ char ch;
+
+ if (idx < sz) {
+ cp += idx;
+ ch = cp[0];
+# ifndef HAS_SIGNED_CHAR
+ if ( (unsigned int)ch >= 0x80 ) {
+ ch = ch - 0x100;
+ }
+#endif
+ RETURN (__mkSmallInteger( ch ));
+ }
+ }
+ }
+%}.
+
+ ^ (self byteAt:byteIndex) signExtendedByteValue
+
+ "
+ |b|
+ b := ByteArray new:3.
+ b at:1 put:16rFF.
+ b at:2 put:16r7F.
+ b at:3 put:16r80.
+ b byteAt:1.
+ b byteAt:2.
+ b byteAt:3.
"
"Modified: / 01-07-1996 / 21:13:53 / cg"
@@ -1769,11 +1875,11 @@
|b "{ Class: SmallInteger }"|
aSignedByteValue >= 0 ifTrue:[
- b := aSignedByteValue
+ b := aSignedByteValue
] ifFalse:[
- b := 16r100 + aSignedByteValue
+ b := 16r100 + aSignedByteValue
].
- self at:index put:b.
+ self byteAt:index put:b.
^ aSignedByteValue
"
@@ -1804,33 +1910,33 @@
* handle the most common cases fast ...
*/
if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(double)-1)) < sz) {
- cp += idx;
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(double)-1)) == 0) {
- double dVal = ((double *)cp)[0];
- OBJ f;
-
- __qMKFLOAT(f, dVal);
- RETURN (f);
- }
- }
- }
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+
+ if ((idx+(sizeof(double)-1)) < sz) {
+ cp += idx;
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(double)-1)) == 0) {
+ double dVal = ((double *)cp)[0];
+ OBJ f;
+
+ __qMKFLOAT(f, dVal);
+ RETURN (f);
+ }
+ }
+ }
}
%}.
newFloat := Float basicNew.
1 to:8 do:[:destIndex|
- newFloat basicAt:destIndex put:(self at:index - 1 + destIndex)
+ newFloat basicAt:destIndex put:(self byteAt:(index - 1 + destIndex))
].
^ newFloat.
@@ -1855,12 +1961,12 @@
|newFloat|
msb == IsBigEndian ifTrue:[
- ^ self doubleAt:index.
+ ^ self doubleAt:index.
].
newFloat := Float basicNew.
1 to:8 do:[:destIndex|
- newFloat basicAt:(9-destIndex) put:(self at:index - 1 + destIndex)
+ newFloat basicAt:(9-destIndex) put:(self byteAt:(index - 1 + destIndex))
].
^ newFloat.
@@ -1883,40 +1989,40 @@
* handle the most common cases fast ...
*/
if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(double)-1)) < sz) {
- cp += idx;
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(double)-1)) == 0) {
- if (__isFloat(aFloat)) {
- ((double *)cp)[0] = __floatVal(aFloat);
- RETURN (aFloat);
- }
- if (__isShortFloat(aFloat)) {
- ((double *)cp)[0] = (double)(__shortFloatVal(aFloat));
- RETURN (aFloat);
- }
- if (__isSmallInteger(aFloat)) {
- ((double *)cp)[0] = (double)(__intVal(aFloat));
- RETURN (aFloat);
- }
- }
- }
- }
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+
+ if ((idx+(sizeof(double)-1)) < sz) {
+ cp += idx;
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(double)-1)) == 0) {
+ if (__isFloat(aFloat)) {
+ ((double *)cp)[0] = __floatVal(aFloat);
+ RETURN (aFloat);
+ }
+ if (__isShortFloat(aFloat)) {
+ ((double *)cp)[0] = (double)(__shortFloatVal(aFloat));
+ RETURN (aFloat);
+ }
+ if (__isSmallInteger(aFloat)) {
+ ((double *)cp)[0] = (double)(__intVal(aFloat));
+ RETURN (aFloat);
+ }
+ }
+ }
+ }
}
%}.
flt := aFloat asFloat.
1 to:8 do:[:srcIndex|
- self at:index - 1 + srcIndex put:(flt basicAt:srcIndex)
+ self byteAt:(index - 1 + srcIndex) put:(flt basicAt:srcIndex)
].
^ aFloat
!
@@ -1933,12 +2039,12 @@
|flt|
msb == IsBigEndian ifTrue:[
- ^ self doubleAt:index put:aFloat.
+ ^ self doubleAt:index put:aFloat.
].
flt := aFloat asFloat.
1 to:8 do:[:srcIndex|
- self at:index - 1 + srcIndex put:(flt basicAt:(9-srcIndex))
+ self byteAt:(index - 1 + srcIndex) put:(flt basicAt:(9-srcIndex))
].
^ aFloat
@@ -1963,33 +2069,33 @@
* handle the most common cases fast ...
*/
if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(float)-1)) < sz) {
- cp += idx;
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(float)-1)) == 0) {
- float fVal = ((float *)cp)[0];
- OBJ f;
-
- __qMKSFLOAT(f, fVal);
- RETURN (f);
- }
- }
- }
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+
+ if ((idx+(sizeof(float)-1)) < sz) {
+ cp += idx;
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(float)-1)) == 0) {
+ float fVal = ((float *)cp)[0];
+ OBJ f;
+
+ __qMKSFLOAT(f, fVal);
+ RETURN (f);
+ }
+ }
+ }
}
%}.
newFloat := ShortFloat basicNew.
1 to:4 do:[:destIndex|
- newFloat basicAt:destIndex put:(self at:index - 1 + destIndex)
+ newFloat basicAt:destIndex put:(self byteAt:(index - 1 + destIndex))
].
^ newFloat.
!
@@ -2007,12 +2113,12 @@
|newFloat|
msb == IsBigEndian ifTrue:[
- ^ self floatAt:index
+ ^ self floatAt:index
].
newFloat := ShortFloat basicNew.
1 to:4 do:[:destIndex|
- newFloat basicAt:(5-destIndex) put:(self at:index - 1 + destIndex)
+ newFloat basicAt:(5-destIndex) put:(self byteAt:(index - 1 + destIndex))
].
^ newFloat.
@@ -2036,41 +2142,41 @@
* handle the most common cases fast ...
*/
if (__isSmallInteger(index)) {
- unsigned char *cp;
- INT sz;
-
- __fetchBytePointerAndSize__(self, &cp, &sz);
- if (cp) {
- unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
-
- if ((idx+(sizeof(float)-1)) < sz) {
- cp += idx;
- /*
- * aligned
- */
- if (((INT)cp & (sizeof(float)-1)) == 0) {
- if (__isShortFloat(aFloat)) {
- ((float *)cp)[0] = __shortFloatVal(aFloat);
- RETURN (self);
- }
- if (__isFloat(aFloat)) {
- ((float *)cp)[0] = (float)__floatVal(aFloat);
- RETURN (self);
- }
- if (__isSmallInteger(aFloat)) {
- ((float *)cp)[0] = (float)__intVal(aFloat);
- RETURN (self);
- }
- // bail out to smalltalk code
- }
- }
- }
+ unsigned char *cp;
+ INT sz;
+
+ __fetchBytePointerAndSize__(self, &cp, &sz);
+ if (cp) {
+ unsigned INT idx = ((unsigned INT)__intVal(index)) - 1;
+
+ if ((idx+(sizeof(float)-1)) < sz) {
+ cp += idx;
+ /*
+ * aligned
+ */
+ if (((INT)cp & (sizeof(float)-1)) == 0) {
+ if (__isShortFloat(aFloat)) {
+ ((float *)cp)[0] = __shortFloatVal(aFloat);
+ RETURN (self);
+ }
+ if (__isFloat(aFloat)) {
+ ((float *)cp)[0] = (float)__floatVal(aFloat);
+ RETURN (self);
+ }
+ if (__isSmallInteger(aFloat)) {
+ ((float *)cp)[0] = (float)__intVal(aFloat);
+ RETURN (self);
+ }
+ // bail out to smalltalk code
+ }
+ }
+ }
}
%}.
sflt := aFloat asShortFloat.
1 to:4 do:[:srcIndex|
- self at:index - 1 + srcIndex put:(sflt basicAt:srcIndex)
+ self byteAt:index - 1 + srcIndex put:(sflt basicAt:srcIndex)
].
!
@@ -2086,13 +2192,13 @@
|sflt|
msb == IsBigEndian ifTrue:[
- self floatAt:index put:aFloat.
- ^ self.
+ self floatAt:index put:aFloat.
+ ^ self.
].
sflt := aFloat asShortFloat.
1 to:4 do:[:srcIndex|
- self at:index - 1 + srcIndex put:(sflt basicAt:(5-srcIndex))
+ self byteAt:(index - 1 + srcIndex) put:(sflt basicAt:(5-srcIndex))
].
"Created: / 15.5.1998 / 17:20:41 / cg"
@@ -2295,7 +2401,7 @@
delta := 1
].
1 to:8 do:[:i |
- l digitAt:i put:(self basicAt:bIdx).
+ l digitAt:i put:(self byteAt:bIdx).
bIdx := bIdx + delta
].
^ l compressed
@@ -2351,7 +2457,7 @@
delta := 1
].
1 to:8 do:[:i |
- self basicAt:bIdx put:(anInteger digitAt:i).
+ self byteAt:bIdx put:(anInteger digitAt:i).
bIdx := bIdx + delta.
].
^ anInteger