added #byteAt: / #byteAt:put: to access any non-pointer objects
bytes (needed for binaryStorage)
--- a/Object.st Mon Apr 21 15:02:48 1997 +0200
+++ b/Object.st Tue Apr 22 09:20:54 1997 +0200
@@ -746,6 +746,113 @@
"Modified: 19.4.1996 / 11:14:10 / cg"
!
+byteAt:index
+ "return the byte at index.
+ This is only allowed for non-pointer indexed objects
+ (i.e. byteArrays, wordArrays, floatArrays etc.).
+ The receivers indexed instvars are treated as an uninterpreted
+ collection of bytes.
+ Only useful with binary storage."
+
+%{ /* NOCONTEXT */
+
+ REGISTER int indx;
+ int nIndex;
+ REGISTER OBJ slf;
+ REGISTER OBJ cls;
+
+ if (__isSmallInteger(index)) {
+ slf = self;
+ if (__isNonNilObject(slf)) {
+ cls = __qClass(slf);
+
+ switch (__intVal(__ClassInstPtr(cls)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ case WORDARRAY:
+ case LONGARRAY:
+ case SWORDARRAY:
+ case SLONGARRAY:
+ case FLOATARRAY:
+ case DOUBLEARRAY:
+ indx = __intVal(index) - 1;
+ indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ nIndex = __byteArraySize(slf);
+ if ((unsigned)indx < (unsigned)nIndex) {
+ RETURN ( __MKSMALLINT(__ByteArrayInstPtr(slf)->ba_element[indx]) );
+ }
+ break;
+ }
+ }
+ }
+%}.
+ "/ index not integer or index out of range
+ "/ or non-byte indexable receiver
+
+ ^ self primitiveFailed
+
+ "
+ Point new byteAt:1
+ (ByteArray with:1 with:2) byteAt:2
+ (WordArray with:1) byteAt:1
+ (FloatArray with:1.0) byteAt:2
+ 'hello' byteAt:1
+ "
+!
+
+byteAt:index put:byteValue
+ "set the byte at index.
+ This is only allowed for non-pointer indexed objects
+ (i.e. byteArrays, wordArrays, floatArrays etc.).
+ The receivers indexed instvars are treated as an uninterpreted
+ collection of bytes.
+ Only useful with binary storage."
+
+%{ /* NOCONTEXT */
+
+ REGISTER int indx;
+ int val, nIndex;
+ REGISTER OBJ slf;
+ REGISTER OBJ cls;
+
+ if (__bothSmallInteger(index, byteValue)) {
+ val = __intVal(byteValue);
+ if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) {
+ slf = self;
+ if (__isNonNilObject(slf)) {
+ cls = __qClass(slf);
+
+ switch (__intVal(__ClassInstPtr(cls)->c_flags) & ARRAYMASK) {
+ case BYTEARRAY:
+ case WORDARRAY:
+ case LONGARRAY:
+ case SWORDARRAY:
+ case SLONGARRAY:
+ case FLOATARRAY:
+ case DOUBLEARRAY:
+ indx = __intVal(index) - 1;
+ indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars));
+ nIndex = __byteArraySize(slf);
+ if ((unsigned)indx < (unsigned)nIndex) {
+ __ByteArrayInstPtr(slf)->ba_element[indx] = val;
+ RETURN ( byteValue );
+ }
+ break;
+ }
+ }
+ }
+ }
+%}.
+ "/ index not integer or index out of range
+ "/ or non-byte indexable receiver
+
+ ^ self primitiveFailed
+
+ "
+ (ByteArray with:1 with:2) byteAt:2 put:3; yourself
+ 'hello' copy byteAt:1 put:105; yourself
+ "
+!
+
instVarAt:index
"return a non-indexed instance variable;
peeking into an object this way is not very object oriented
@@ -5761,6 +5868,6 @@
!Object class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.188 1997-03-27 17:22:41 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.189 1997-04-22 07:20:54 cg Exp $'
! !
Object initialize!