moved some of ExtBytes protocol to here.
--- a/UIBytes.st Wed Jan 21 17:49:02 1998 +0100
+++ b/UIBytes.st Wed Jan 21 17:49:27 1998 +0100
@@ -188,20 +188,32 @@
LSB-first otherwise.
Subclasses may redefine this for better performance."
- |v|
+ |val
+ ival "{ Class: SmallInteger }"
+ i "{ Class: SmallInteger }"
+ b1 "{ Class: SmallInteger }"
+ b2 "{ Class: SmallInteger }"
+ b3 "{ Class: SmallInteger }"
+ b4 "{ Class: SmallInteger }"|
+
+ i := index.
+ b1 := self at:i.
+ b2 := self at:(i+1).
+ b3 := self at:(i+2).
+ b4 := self at:(i+3).
msb ifTrue:[
- v := self at:index.
- 1 to:3 do:[:i |
- v := (v bitShift:8) bitOr:(self at:index+i)
- ].
+ ival := b1.
+ ival := (ival bitShift:8) + b2.
+ ival := (ival bitShift:8) + b3.
+ val := (ival * 256) + b4.
] ifFalse:[
- v := self at:index+3.
- 2 to:0 by:-1 do:[:i |
- v := (v bitShift:8) bitOr:(self at:index+i)
- ]
+ ival := b4.
+ ival := (ival bitShift:8) + b3.
+ ival := (ival bitShift:8) + b2.
+ val := (ival * 256) + b1.
].
- ^ v
+ ^ val
"
|b|
@@ -210,6 +222,8 @@
(b doubleWordAt:1 MSB:true) printStringRadix:16.
(b doubleWordAt:1 MSB:false) printStringRadix:16
"
+
+ "Modified: / 21.1.1998 / 17:42:30 / cg"
!
doubleWordAt:index put:value
@@ -229,30 +243,31 @@
"
!
-doubleWordAt:index put:value MSB:msb
+doubleWordAt:index put:aNumber MSB:msb
"set the 4-bytes starting at index from the (unsigned) Integer value.
The value must be in the range 0 to 16rFFFFFFFF.
The value is stored MSB-first if msb is true; LSB-first otherwise.
Subclasses may redefine this for better performance."
- |v|
+ |i "{ Clas: SmallInteger }" |
- ((value < 0) or:[value > 16rFFFFFFFF]) ifTrue:[
- ^ self elementBoundsError
+ ((aNumber < 0) or:[aNumber > 16rFFFFFFFF]) ifTrue:[
+ ^ self elementBoundsError
].
- v := value.
+
+ i := index.
msb ifTrue:[
- 3 to:0 by:-1 do:[:i |
- self at:index+i put:(v bitAnd:16rFF).
- v := v bitShift:-8
- ].
+ self at:i put:(aNumber digitAt:4).
+ self at:(i+1) put:(aNumber digitAt:3).
+ self at:(i+2) put:(aNumber digitAt:2).
+ self at:(i+3) put:(aNumber digitAt:1).
] ifFalse:[
- 0 to:3 by:-1 do:[:i |
- self at:index+i put:(v bitAnd:16rFF).
- v := v bitShift:-8
- ]
+ self at:i put:(aNumber digitAt:1).
+ self at:(i+1) put:(aNumber digitAt:2).
+ self at:(i+2) put:(aNumber digitAt:3).
+ self at:(i+3) put:(aNumber digitAt:4).
].
- ^ value
+ ^ aNumber
"
|b|
@@ -261,6 +276,56 @@
b doubleWordAt:5 put:16r04030201 MSB:false.
b inspect
"
+
+ "Modified: / 21.1.1998 / 17:43:34 / cg"
+!
+
+doubleWordAtDoubleWordIndex:index
+ "return the unsigned long at index, anInteger.
+ Fetching in the machines natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self doubleWordAtDoubleWordIndex:index MSB:(UninterpretedBytes isBigEndian)
+
+ "Created: / 21.1.1998 / 17:43:53 / cg"
+!
+
+doubleWordAtDoubleWordIndex:index MSB:msb
+ "return the unsigned long at index, anInteger.
+ Fetching is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self doubleWordAt:(index - 1 * 4 + 1) MSB:msb
+
+ "Created: / 21.1.1998 / 17:44:07 / cg"
+!
+
+doubleWordAtDoubleWordIndex:index put:value
+ "set the long at index, anInteger.
+ Storing in the machines natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self doubleWordAtDoubleWordIndex:index put:value MSB:(UninterpretedBytes isBigEndian)
+
+ "Created: / 21.1.1998 / 17:44:13 / cg"
+!
+
+doubleWordAtDoubleWordIndex:index put:value MSB:msb
+ "set the long at index, anInteger.
+ Storing is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self doubleWordAt:(index - 1 * 4 + 1) put:value MSB:msb
+
+ "Created: / 21.1.1998 / 17:44:19 / cg"
!
floatAt:index
@@ -654,13 +719,64 @@
"Modified: 1.7.1996 / 21:12:13 / cg"
!
-stringAt:index size:count
- "extract a string, given initial index and number of characters (bytes)"
+stringAt:index
+ "return a string starting at index up to the 0-byte"
+
+ |stream i "{ Class: SmallInteger }" c|
+
+ stream := WriteStream on:''.
+ i := index.
+ [(c := self basicAt:i) ~~ 0] whileTrue:[
+ stream nextPut:(Character value:c).
+ i := i + 1.
+ ].
+ ^ stream contents
+
+ "Created: / 21.1.1998 / 17:44:50 / cg"
+!
+
+stringAt:index put:aString
+ "copy aString to the externalBytes, starting at index up to
+ (and including) the 0-byte"
+
+ |i "{ Class: SmallInteger }"|
- ^ (self copyFrom:index to:(index + count - 1)) asString
+ i := index.
+ aString do:[:aChar |
+ self basicAt:i put:aChar asciiValue.
+ i := i + 1.
+ ].
+ self basicAt:i put:0.
+ ^ aString
+
+ "
+ |bytes|
+
+ bytes := ExternalBytes new:10.
+ bytes stringAt:1 put:'hello'.
+ 1 to:bytes size do:[:i |
+ Transcript showCR:(bytes at:i)
+ ]
+ "
- "Modified: 9.9.1996 / 15:28:08 / cg"
- "Created: 9.9.1996 / 15:28:48 / cg"
+ "Created: / 21.1.1998 / 17:45:02 / cg"
+!
+
+stringAt:index size:maxSize
+ "return a string starting at index up to maxSize, or a 0-byte"
+
+ |stream c i "{ Class: SmallInteger }"|
+
+ stream := WriteStream on:(String new:maxSize).
+ i := index.
+ [(i <= maxSize)
+ and:[(c := self basicAt:i) ~~ 0]] whileTrue:[
+ stream nextPut:(Character value:c).
+ i := i + 1.
+ ].
+ ^ stream contents
+
+ "Modified: / 21.1.1998 / 17:45:23 / cg"
!
wordAt:index
@@ -677,14 +793,17 @@
LSB-first (i.e. low 8-bits at lower byte index) if its false.
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
- |v|
+ |b1 "{ Class: SmallInteger }"
+ b2 "{ Class: SmallInteger }"|
+ b1 := self at:index.
+ b2 := self at:(index + 1).
msb ifTrue:[
- v := self at:index.
- ^ (v bitShift:8) bitOr:(self at:index+1)
+ ^ (b1 bitShift:8) + b2
].
- v := self at:index+1.
- ^ (v bitShift:8) bitOr:(self at:index)
+ ^ (b2 bitShift:8) + b1
+
+ "Modified: / 21.1.1998 / 17:46:07 / cg"
!
wordAt:index put:value
@@ -711,16 +830,22 @@
lower index) if msb is false, MSB-first otherwise.
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
- ((value < 0) or:[value > 16rFFFF]) ifTrue:[
- ^ self elementBoundsError
+ |b1 b2
+ iVal "{ Class: SmallInteger }"|
+
+ iVal := value.
+ ((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[
+ ^ self elementBoundsError
].
msb ifTrue:[
- self at:index put:((value bitShift:-8) bitAnd:16rFF).
- self at:index+1 put:(value bitAnd:16rFF).
+ b1 := ((iVal bitShift:-8) bitAnd:16rFF).
+ b2 := (iVal bitAnd:16rFF).
] ifFalse:[
- self at:index put:(value bitAnd:16rFF).
- self at:index+1 put:((value bitShift:-8) bitAnd:16rFF).
+ b1 := (iVal bitAnd:16rFF).
+ b2 := ((iVal bitShift:-8) bitAnd:16rFF).
].
+ self at:index put:b1.
+ self at:index+1 put:b2.
^ value
"
@@ -731,6 +856,56 @@
b wordAt:7 put:16r0304 MSB:true.
b inspect
"
+
+ "Modified: / 21.1.1998 / 17:48:15 / cg"
+!
+
+wordAtWordIndex:index
+ "return the unsigned short at index, anInteger.
+ Fetching in the machines natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self wordAtWordIndex:index MSB:(UninterpretedBytes isBigEndian)
+
+ "Created: / 21.1.1998 / 17:48:26 / cg"
+!
+
+wordAtWordIndex:index MSB:msb
+ "return the unsigned short at index, anInteger.
+ Fetching is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self wordAt:(index - 1 * 2 + 1) MSB:msb
+
+ "Created: / 21.1.1998 / 17:48:30 / cg"
+!
+
+wordAtWordIndex:index put:value
+ "set the short at index, anInteger.
+ Storing in the machines natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self wordAtWordIndex:index put:value MSB:(UninterpretedBytes isBigEndian)
+
+ "Created: / 21.1.1998 / 17:48:34 / cg"
+!
+
+wordAtWordIndex:index put:value MSB:msb
+ "set the short at index, anInteger.
+ Storing is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self wordAt:(index - 1 * 2 + 1) put:value MSB:msb
+
+ "Created: / 21.1.1998 / 17:48:38 / cg"
!
zeroByteStringAt:index maximumSize:count
@@ -750,5 +925,5 @@
!UninterpretedBytes class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Attic/UIBytes.st,v 1.18 1998-01-21 16:38:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Attic/UIBytes.st,v 1.19 1998-01-21 16:49:27 cg Exp $'
! !
--- a/UninterpretedBytes.st Wed Jan 21 17:49:02 1998 +0100
+++ b/UninterpretedBytes.st Wed Jan 21 17:49:27 1998 +0100
@@ -188,20 +188,32 @@
LSB-first otherwise.
Subclasses may redefine this for better performance."
- |v|
+ |val
+ ival "{ Class: SmallInteger }"
+ i "{ Class: SmallInteger }"
+ b1 "{ Class: SmallInteger }"
+ b2 "{ Class: SmallInteger }"
+ b3 "{ Class: SmallInteger }"
+ b4 "{ Class: SmallInteger }"|
+
+ i := index.
+ b1 := self at:i.
+ b2 := self at:(i+1).
+ b3 := self at:(i+2).
+ b4 := self at:(i+3).
msb ifTrue:[
- v := self at:index.
- 1 to:3 do:[:i |
- v := (v bitShift:8) bitOr:(self at:index+i)
- ].
+ ival := b1.
+ ival := (ival bitShift:8) + b2.
+ ival := (ival bitShift:8) + b3.
+ val := (ival * 256) + b4.
] ifFalse:[
- v := self at:index+3.
- 2 to:0 by:-1 do:[:i |
- v := (v bitShift:8) bitOr:(self at:index+i)
- ]
+ ival := b4.
+ ival := (ival bitShift:8) + b3.
+ ival := (ival bitShift:8) + b2.
+ val := (ival * 256) + b1.
].
- ^ v
+ ^ val
"
|b|
@@ -210,6 +222,8 @@
(b doubleWordAt:1 MSB:true) printStringRadix:16.
(b doubleWordAt:1 MSB:false) printStringRadix:16
"
+
+ "Modified: / 21.1.1998 / 17:42:30 / cg"
!
doubleWordAt:index put:value
@@ -229,30 +243,31 @@
"
!
-doubleWordAt:index put:value MSB:msb
+doubleWordAt:index put:aNumber MSB:msb
"set the 4-bytes starting at index from the (unsigned) Integer value.
The value must be in the range 0 to 16rFFFFFFFF.
The value is stored MSB-first if msb is true; LSB-first otherwise.
Subclasses may redefine this for better performance."
- |v|
+ |i "{ Clas: SmallInteger }" |
- ((value < 0) or:[value > 16rFFFFFFFF]) ifTrue:[
- ^ self elementBoundsError
+ ((aNumber < 0) or:[aNumber > 16rFFFFFFFF]) ifTrue:[
+ ^ self elementBoundsError
].
- v := value.
+
+ i := index.
msb ifTrue:[
- 3 to:0 by:-1 do:[:i |
- self at:index+i put:(v bitAnd:16rFF).
- v := v bitShift:-8
- ].
+ self at:i put:(aNumber digitAt:4).
+ self at:(i+1) put:(aNumber digitAt:3).
+ self at:(i+2) put:(aNumber digitAt:2).
+ self at:(i+3) put:(aNumber digitAt:1).
] ifFalse:[
- 0 to:3 by:-1 do:[:i |
- self at:index+i put:(v bitAnd:16rFF).
- v := v bitShift:-8
- ]
+ self at:i put:(aNumber digitAt:1).
+ self at:(i+1) put:(aNumber digitAt:2).
+ self at:(i+2) put:(aNumber digitAt:3).
+ self at:(i+3) put:(aNumber digitAt:4).
].
- ^ value
+ ^ aNumber
"
|b|
@@ -261,6 +276,56 @@
b doubleWordAt:5 put:16r04030201 MSB:false.
b inspect
"
+
+ "Modified: / 21.1.1998 / 17:43:34 / cg"
+!
+
+doubleWordAtDoubleWordIndex:index
+ "return the unsigned long at index, anInteger.
+ Fetching in the machines natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self doubleWordAtDoubleWordIndex:index MSB:(UninterpretedBytes isBigEndian)
+
+ "Created: / 21.1.1998 / 17:43:53 / cg"
+!
+
+doubleWordAtDoubleWordIndex:index MSB:msb
+ "return the unsigned long at index, anInteger.
+ Fetching is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self doubleWordAt:(index - 1 * 4 + 1) MSB:msb
+
+ "Created: / 21.1.1998 / 17:44:07 / cg"
+!
+
+doubleWordAtDoubleWordIndex:index put:value
+ "set the long at index, anInteger.
+ Storing in the machines natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self doubleWordAtDoubleWordIndex:index put:value MSB:(UninterpretedBytes isBigEndian)
+
+ "Created: / 21.1.1998 / 17:44:13 / cg"
+!
+
+doubleWordAtDoubleWordIndex:index put:value MSB:msb
+ "set the long at index, anInteger.
+ Storing is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of doubleWord entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self doubleWordAt:(index - 1 * 4 + 1) put:value MSB:msb
+
+ "Created: / 21.1.1998 / 17:44:19 / cg"
!
floatAt:index
@@ -654,13 +719,64 @@
"Modified: 1.7.1996 / 21:12:13 / cg"
!
-stringAt:index size:count
- "extract a string, given initial index and number of characters (bytes)"
+stringAt:index
+ "return a string starting at index up to the 0-byte"
+
+ |stream i "{ Class: SmallInteger }" c|
+
+ stream := WriteStream on:''.
+ i := index.
+ [(c := self basicAt:i) ~~ 0] whileTrue:[
+ stream nextPut:(Character value:c).
+ i := i + 1.
+ ].
+ ^ stream contents
+
+ "Created: / 21.1.1998 / 17:44:50 / cg"
+!
+
+stringAt:index put:aString
+ "copy aString to the externalBytes, starting at index up to
+ (and including) the 0-byte"
+
+ |i "{ Class: SmallInteger }"|
- ^ (self copyFrom:index to:(index + count - 1)) asString
+ i := index.
+ aString do:[:aChar |
+ self basicAt:i put:aChar asciiValue.
+ i := i + 1.
+ ].
+ self basicAt:i put:0.
+ ^ aString
+
+ "
+ |bytes|
+
+ bytes := ExternalBytes new:10.
+ bytes stringAt:1 put:'hello'.
+ 1 to:bytes size do:[:i |
+ Transcript showCR:(bytes at:i)
+ ]
+ "
- "Modified: 9.9.1996 / 15:28:08 / cg"
- "Created: 9.9.1996 / 15:28:48 / cg"
+ "Created: / 21.1.1998 / 17:45:02 / cg"
+!
+
+stringAt:index size:maxSize
+ "return a string starting at index up to maxSize, or a 0-byte"
+
+ |stream c i "{ Class: SmallInteger }"|
+
+ stream := WriteStream on:(String new:maxSize).
+ i := index.
+ [(i <= maxSize)
+ and:[(c := self basicAt:i) ~~ 0]] whileTrue:[
+ stream nextPut:(Character value:c).
+ i := i + 1.
+ ].
+ ^ stream contents
+
+ "Modified: / 21.1.1998 / 17:45:23 / cg"
!
wordAt:index
@@ -677,14 +793,17 @@
LSB-first (i.e. low 8-bits at lower byte index) if its false.
Question: should it be retrieve signed values ? (see ByteArray>>signedWordAt:)"
- |v|
+ |b1 "{ Class: SmallInteger }"
+ b2 "{ Class: SmallInteger }"|
+ b1 := self at:index.
+ b2 := self at:(index + 1).
msb ifTrue:[
- v := self at:index.
- ^ (v bitShift:8) bitOr:(self at:index+1)
+ ^ (b1 bitShift:8) + b2
].
- v := self at:index+1.
- ^ (v bitShift:8) bitOr:(self at:index)
+ ^ (b2 bitShift:8) + b1
+
+ "Modified: / 21.1.1998 / 17:46:07 / cg"
!
wordAt:index put:value
@@ -711,16 +830,22 @@
lower index) if msb is false, MSB-first otherwise.
Question: should it accept signed values ? (see ByteArray>>signedWordAt:put:)"
- ((value < 0) or:[value > 16rFFFF]) ifTrue:[
- ^ self elementBoundsError
+ |b1 b2
+ iVal "{ Class: SmallInteger }"|
+
+ iVal := value.
+ ((iVal < 0) or:[iVal > 16rFFFF]) ifTrue:[
+ ^ self elementBoundsError
].
msb ifTrue:[
- self at:index put:((value bitShift:-8) bitAnd:16rFF).
- self at:index+1 put:(value bitAnd:16rFF).
+ b1 := ((iVal bitShift:-8) bitAnd:16rFF).
+ b2 := (iVal bitAnd:16rFF).
] ifFalse:[
- self at:index put:(value bitAnd:16rFF).
- self at:index+1 put:((value bitShift:-8) bitAnd:16rFF).
+ b1 := (iVal bitAnd:16rFF).
+ b2 := ((iVal bitShift:-8) bitAnd:16rFF).
].
+ self at:index put:b1.
+ self at:index+1 put:b2.
^ value
"
@@ -731,6 +856,56 @@
b wordAt:7 put:16r0304 MSB:true.
b inspect
"
+
+ "Modified: / 21.1.1998 / 17:48:15 / cg"
+!
+
+wordAtWordIndex:index
+ "return the unsigned short at index, anInteger.
+ Fetching in the machines natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self wordAtWordIndex:index MSB:(UninterpretedBytes isBigEndian)
+
+ "Created: / 21.1.1998 / 17:48:26 / cg"
+!
+
+wordAtWordIndex:index MSB:msb
+ "return the unsigned short at index, anInteger.
+ Fetching is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self wordAt:(index - 1 * 2 + 1) MSB:msb
+
+ "Created: / 21.1.1998 / 17:48:30 / cg"
+!
+
+wordAtWordIndex:index put:value
+ "set the short at index, anInteger.
+ Storing in the machines natural byte order.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self wordAtWordIndex:index put:value MSB:(UninterpretedBytes isBigEndian)
+
+ "Created: / 21.1.1998 / 17:48:34 / cg"
+!
+
+wordAtWordIndex:index put:value MSB:msb
+ "set the short at index, anInteger.
+ Storing is MSB if msb is true, LSB otherwise.
+ Indices are 1-based and scaled as appropriate to allow
+ accessing the memory as an array of word entries.
+ (i.e. indices are 1, 2, ...)"
+
+ ^ self wordAt:(index - 1 * 2 + 1) put:value MSB:msb
+
+ "Created: / 21.1.1998 / 17:48:38 / cg"
!
zeroByteStringAt:index maximumSize:count
@@ -750,5 +925,5 @@
!UninterpretedBytes class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.18 1998-01-21 16:38:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/UninterpretedBytes.st,v 1.19 1998-01-21 16:49:27 cg Exp $'
! !