diff --git a/basis/classes/struct/bit-accessors/bit-accessors.factor b/basis/classes/struct/bit-accessors/bit-accessors.factor index 30620b46c1..7a2fdb0cac 100644 --- a/basis/classes/struct/bit-accessors/bit-accessors.factor +++ b/basis/classes/struct/bit-accessors/bit-accessors.factor @@ -15,13 +15,13 @@ IN: classes.struct.bit-accessors start-bit end-bit ones-between :> mask end-bit start-bit - :> used-bits - start-bit i end-bit mask step-quot call( a b c d -- quot ) + i mask start-bit step-quot call( i mask start-bit -- quot ) used-bits i 1 + 8 * bits used-bits - ; inline :: bit-manipulator ( offset bits - step-quot: ( start-bit i end-bit mask -- quot ) + step-quot: ( i mask start-bit -- quot ) combine-quot: ( prev-quot shift-amount next-quot -- quot ) -- quot ) offset bits step-quot manipulate-bits @@ -31,21 +31,16 @@ IN: classes.struct.bit-accessors ] if ; inline recursive : bit-reader ( offset bits -- quot: ( alien -- n ) ) - [| start-bit i end-bit mask | - [ i alien-unsigned-1 mask bitand start-bit neg shift ] - ] + [ neg '[ _ alien-unsigned-1 _ bitand _ shift ] ] [ swap '[ _ _ bi _ shift bitor ] ] bit-manipulator ; +:: write-bits ( n alien i mask start-bit -- ) + n start-bit shift mask bitand + alien i alien-unsigned-1 mask bitnot bitand + bitor alien i set-alien-unsigned-1 ; inline + : bit-writer ( offset bits -- quot: ( n alien -- ) ) - [| start-bit i end-bit mask | - [ - [ - [ start-bit shift mask bitand ] - [ i alien-unsigned-1 mask bitnot bitand ] - bi* bitor - ] keep i set-alien-unsigned-1 - ] - ] + [ '[ _ _ _ write-bits ] ] [ '[ _ [ [ _ neg shift ] dip @ ] 2bi ] ] bit-manipulator ;