math.bitwise: change bitfield to reduce from first argument rather than zero.

db4
John Benediktsson 2015-05-30 21:55:27 -07:00
parent 040e61cbe7
commit f24bbffb2a
1 changed files with 11 additions and 6 deletions

View File

@ -51,8 +51,7 @@ ERROR: bit-range-error x high low ;
: W* ( x y -- z ) * 64 bits ; inline
: symbols>flags ( symbols assoc -- flag-bits )
[ at ] curry map
0 [ bitor ] reduce ;
'[ _ at ] map 0 [ bitor ] reduce ;
! bitfield
<PRIVATE
@ -60,16 +59,22 @@ ERROR: bit-range-error x high low ;
GENERIC: (bitfield-quot) ( spec -- quot )
M: integer (bitfield-quot) ( spec -- quot )
[ swapd shift bitor ] curry ;
'[ _ shift ] ;
M: pair (bitfield-quot) ( spec -- quot )
first2-unsafe over word? [ [ swapd execute ] dip ] [ ] ?
[ shift bitor ] append 2curry ;
first2-unsafe over word? [
'[ _ execute _ shift ]
] [
'[ _ _ shift ]
] if ;
PRIVATE>
MACRO: bitfield ( bitspec -- )
[ 0 ] [ (bitfield-quot) compose ] reduce ;
[ [ 0 ] ] [
[ (bitfield-quot) ] map unclip
[ '[ @ _ dip bitor ] ] reduce
] if-empty ;
! bit-count
<PRIVATE