--- a/UninterpretedBytes.st Sat May 16 03:46:30 2015 +0000
+++ b/UninterpretedBytes.st Sat May 16 11:46:43 2015 +0200
@@ -83,28 +83,28 @@
"
UninterpretedBytes provides the common protocol for byte-storage
containers; concrete subclasses are
- ByteArray (which store the bytes within the Smalltalk object memory)
- String (which is a subclass of ByteArray) knows that the bytes represent characters
+ ByteArray (which store the bytes within the Smalltalk object memory)
+ String (which is a subclass of ByteArray) knows that the bytes represent characters
and
- ExternalBytes (which store the bytes in the malloc-heap).
+ ExternalBytes (which store the bytes in the malloc-heap).
UninterpretedBytes itself is abstract, so no instances of it can be created.
[See also:]
- ByteArray String ExternalBytes
+ ByteArray String ExternalBytes
[author:]
- Claus Gittinger
+ Claus Gittinger
[Notice:]
- Notice the confusion due to multiple methods with the same
- functionality (i.e. 'xxxx:MSB:' vs. 'xxxx:bigEndian:').
- The reason is that at the time this class was written,
- ST80 sid not offer protocol to specify the byteOrder, and
- ST/X provided methods ending in 'MSB:' for this.
- In the meanwhile, VW added protocol ending in 'bigEndian:',
- which has been added here for compatibility.
- (certainly a point, where an ansi-standard will help)
+ Notice the confusion due to multiple methods with the same
+ functionality (i.e. 'xxxx:MSB:' vs. 'xxxx:bigEndian:').
+ The reason is that at the time this class was written,
+ ST80 sid not offer protocol to specify the byteOrder, and
+ ST/X provided methods ending in 'MSB:' for this.
+ In the meanwhile, VW added protocol ending in 'bigEndian:',
+ which has been added here for compatibility.
+ (certainly a point, where an ansi-standard will help)
"
! !
@@ -144,9 +144,9 @@
bytes := self new: sz // 2.
s := aString readStream.
1 to: sz // 2 do: [ :idx |
- hi := s next digitValue.
- lo := s next digitValue.
- bytes at:idx put: ((hi bitShift:4) bitOr: lo)
+ hi := s next digitValue.
+ lo := s next digitValue.
+ bytes at:idx put: ((hi bitShift:4) bitOr: lo)
].
^ bytes
@@ -161,7 +161,7 @@
"
"
Time millisecondsToRun:[
- 1000000 timesRepeat:[ ByteArray fromHexString:'1234FEFF1234FEFF1234FEFF1234FEFF' ]
+ 1000000 timesRepeat:[ ByteArray fromHexString:'1234FEFF1234FEFF1234FEFF1234FEFF' ]
].
"
@@ -200,7 +200,7 @@
the radix-encoding used in good old PDP11 times ;-)
ST-80 uses this encoding for Images ...
This is a base64 encoding, very similar (but not equal) to the algorithm used in RFC1421.
- PS: It took a while to figure that one out ...
+ PS: It took a while to figure that one out ...
I don't like it ;-)"
|index "{ Class: SmallInteger }"
@@ -221,47 +221,47 @@
last := aString last codePoint.
last > 96 ifTrue:[
- stop := stop - 3 + (last - 96)
+ stop := stop - 3 + (last - 96)
].
bytes := self new:stop.
index := 1. dstIndex := 1.
[dstIndex <= stop] whileTrue:[
- "/ take 4 characters ...
- "/ allow a line break before each group of 4
- sixBits := (aString at:index) codePoint.
- [sixBits < 32] whileTrue:[
- index := index + 1.
- sixBits := (aString at:index) codePoint.
- ].
- sixBits := sixBits bitAnd:16r3F.
- n := sixBits.
-
- "/ self assert:(aString at:index+1) codePoint >= 32.
- sixBits := (aString at:index+1) codePoint bitAnd:16r3F.
- n := (n bitShift:6) + sixBits.
-
- "/ self assert:(aString at:index+2) codePoint >= 32.
- sixBits := (aString at:index+2) codePoint bitAnd:16r3F.
- n := (n bitShift:6) + sixBits.
-
- "/ self assert:(aString at:index+3) codePoint >= 32.
- sixBits := (aString at:index+3) codePoint bitAnd:16r3F.
- n := (n bitShift:6) + sixBits.
-
- index := index + 4.
-
- "/ now have 24 bits in n
-
- bytes at:dstIndex put:(n bitShift:-16).
-
- dstIndex < stop ifTrue:[
- bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF).
- dstIndex+2 <= stop ifTrue:[
- bytes at:dstIndex+2 put:(n bitAnd:16rFF).
- ]
- ].
- dstIndex := dstIndex + 3.
+ "/ take 4 characters ...
+ "/ allow a line break before each group of 4
+ sixBits := (aString at:index) codePoint.
+ [sixBits < 32] whileTrue:[
+ index := index + 1.
+ sixBits := (aString at:index) codePoint.
+ ].
+ sixBits := sixBits bitAnd:16r3F.
+ n := sixBits.
+
+ "/ self assert:(aString at:index+1) codePoint >= 32.
+ sixBits := (aString at:index+1) codePoint bitAnd:16r3F.
+ n := (n bitShift:6) + sixBits.
+
+ "/ self assert:(aString at:index+2) codePoint >= 32.
+ sixBits := (aString at:index+2) codePoint bitAnd:16r3F.
+ n := (n bitShift:6) + sixBits.
+
+ "/ self assert:(aString at:index+3) codePoint >= 32.
+ sixBits := (aString at:index+3) codePoint bitAnd:16r3F.
+ n := (n bitShift:6) + sixBits.
+
+ index := index + 4.
+
+ "/ now have 24 bits in n
+
+ bytes at:dstIndex put:(n bitShift:-16).
+
+ dstIndex < stop ifTrue:[
+ bytes at:dstIndex+1 put:((n bitShift:-8) bitAnd:16rFF).
+ dstIndex+2 <= stop ifTrue:[
+ bytes at:dstIndex+2 put:(n bitAnd:16rFF).
+ ]
+ ].
+ dstIndex := dstIndex + 3.
].
^ bytes
@@ -296,72 +296,72 @@
REGISTER OBJ *op;
if (__isSmallInteger(anInteger)) {
- nindexedinstvars = __intVal(anInteger);
- if (nindexedinstvars >= 0) {
- if (self == ByteArray) {
- /*
- * the most common case
- */
- instsize = OHDR_SIZE + nindexedinstvars;
- if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */
- __qCheckedNew(newobj, instsize);
- __InstPtr(newobj)->o_class = self;
- __qSTORE(newobj, self);
- RETURN (newobj );
- }
- } else {
- /*
- * Take care for subclasses like TwoByteString
- */
- switch (__smallIntegerVal(__ClassInstPtr(self)->c_flags) & ARRAYMASK) {
- case BYTEARRAY:
- break;
-
- case WORDARRAY:
- case SWORDARRAY:
- nindexedinstvars *= 2;
- break;
-
- case LONGARRAY:
- case SLONGARRAY:
- nindexedinstvars *= 4;
- break;
-
- default:
- /* don't know about this array type, delegate to super */
- goto out;
- }
- }
- nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
- instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars;
- __PROTECT_CONTEXT__
- __qNew(newobj, instsize); /* OBJECT ALLOCATION */
- __UNPROTECT_CONTEXT__
- if (newobj != nil) {
- __InstPtr(newobj)->o_class = self;
- __qSTORE(newobj, self);
- if (nInstVars) {
- /*
- * still have to nil out named instvars ...
- */
+ nindexedinstvars = __intVal(anInteger);
+ if (nindexedinstvars >= 0) {
+ if (self == ByteArray) {
+ /*
+ * the most common case
+ */
+ instsize = OHDR_SIZE + nindexedinstvars;
+ if (__CanDoQuickNew(instsize)) { /* OBJECT ALLOCATION */
+ __qCheckedNew(newobj, instsize);
+ __InstPtr(newobj)->o_class = self;
+ __qSTORE(newobj, self);
+ RETURN (newobj );
+ }
+ } else {
+ /*
+ * Take care for subclasses like TwoByteString
+ */
+ switch (__smallIntegerVal(__ClassInstPtr(self)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ break;
+
+ case WORDARRAY:
+ case SWORDARRAY:
+ nindexedinstvars *= 2;
+ break;
+
+ case LONGARRAY:
+ case SLONGARRAY:
+ nindexedinstvars *= 4;
+ break;
+
+ default:
+ /* don't know about this array type, delegate to super */
+ goto out;
+ }
+ }
+ nInstVars = __intVal(__ClassInstPtr(self)->c_ninstvars);
+ instsize = OHDR_SIZE + __OBJS2BYTES__(nInstVars) + nindexedinstvars;
+ __PROTECT_CONTEXT__
+ __qNew(newobj, instsize); /* OBJECT ALLOCATION */
+ __UNPROTECT_CONTEXT__
+ if (newobj != nil) {
+ __InstPtr(newobj)->o_class = self;
+ __qSTORE(newobj, self);
+ if (nInstVars) {
+ /*
+ * still have to nil out named instvars ...
+ */
#if defined(memset4) && defined(FAST_OBJECT_MEMSET4)
- memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars);
+ memset4(__InstPtr(newobj)->i_instvars, nil, nInstVars);
#else
# if defined(FAST_MEMSET) && !defined(NEGATIVE_ADDRESSES)
- /*
- * knowing that nil is 0
- */
- memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
+ /*
+ * knowing that nil is 0
+ */
+ memset(__InstPtr(newobj)->i_instvars, 0, instsize - OHDR_SIZE);
# else
- op = __InstPtr(newobj)->i_instvars;
- while (nInstVars--)
- *op++ = nil;
+ op = __InstPtr(newobj)->i_instvars;
+ while (nInstVars--)
+ *op++ = nil;
# endif
#endif
- }
- RETURN ( newobj );
- }
- }
+ }
+ RETURN ( newobj );
+ }
+ }
}
out:;
%}.
@@ -430,7 +430,9 @@
RETURN (true);
# endif
#endif
-%}
+%}.
+ ^ false "/ an arbitrary default
+
"
UninterpretedBytes isBigEndian
"
@@ -538,22 +540,22 @@
|val|
val := 0.
- bigEndian ifTrue:[
- index to:index+n-1 do:[:i |
- val := (val<<8) + (self at:i)
- ]
- ] ifFalse:[
- index+n-1 to:index by:-1 do:[:i |
- val := (val<<8) + (self at:i)
- ]
+ bigEndian ifTrue:[
+ index to:index+n-1 do:[:i |
+ val := (val<<8) + (self at:i)
+ ]
+ ] ifFalse:[
+ index+n-1 to:index by:-1 do:[:i |
+ val := (val<<8) + (self at:i)
+ ]
].
^ val
"
|b|
b := #[ 16r01 16r02 16r03 16r04 16r05 ].
- (b unsignedIntegerAt:2 length:4 bigEndian:false).
- (b unsignedIntegerAt:2 length:4 bigEndian:true).
+ (b unsignedIntegerAt:2 length:4 bigEndian:false).
+ (b unsignedIntegerAt:2 length:4 bigEndian:true).
"
! !
@@ -709,12 +711,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 at:index - 1 + destIndex)
].
^ newFloat.
@@ -737,40 +739,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 at:index - 1 + srcIndex put:(flt basicAt:srcIndex)
].
^ aFloat
!
@@ -787,12 +789,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 at:index - 1 + srcIndex put:(flt basicAt:(9-srcIndex))
].
^ aFloat
@@ -861,12 +863,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 at:index - 1 + destIndex)
].
^ newFloat.
@@ -890,41 +892,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 at:index - 1 + srcIndex put:(sflt basicAt:srcIndex)
].
!
@@ -940,13 +942,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 at:index - 1 + srcIndex put:(sflt basicAt:(5-srcIndex))
].
"Created: / 15.5.1998 / 17:20:41 / cg"
@@ -1045,7 +1047,7 @@
w := self unsignedLongLongAt:index bigEndian:IsBigEndian.
(w > (16r7FFFFFFFFFFFFFFF)) ifTrue:[
- ^ w - (16r10000000000000000)
+ ^ w - (16r10000000000000000)
].
^ w
@@ -2127,9 +2129,9 @@
|v|
value >= 0 ifTrue:[
- v := value
+ v := value
] ifFalse:[
- v := 16r10000 + value
+ v := 16r10000 + value
].
self unsignedShortAt:index put:v bigEndian:IsBigEndian.
^ value
@@ -3174,11 +3176,11 @@
!UninterpretedBytes class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.101 2015-04-24 12:17:11 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.102 2015-05-16 09:46:43 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.101 2015-04-24 12:17:11 stefan Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.102 2015-05-16 09:46:43 cg Exp $'
! !