2008-02-02 07:58:28 -05:00
|
|
|
! Copyright (C) 2007, 2008 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: arrays kernel math sequences words ;
|
|
|
|
IN: math.bitfields
|
|
|
|
|
|
|
|
GENERIC: (bitfield) inline
|
|
|
|
|
|
|
|
M: integer (bitfield) ( value accum shift -- newaccum )
|
|
|
|
swapd shift bitor ;
|
|
|
|
|
|
|
|
M: pair (bitfield) ( value accum pair -- newaccum )
|
|
|
|
first2 >r dup word? [ swapd execute ] when r> shift bitor ;
|
|
|
|
|
|
|
|
: bitfield ( values... bitspec -- n )
|
|
|
|
0 [ (bitfield) ] reduce ;
|
2008-02-02 07:58:28 -05:00
|
|
|
|
|
|
|
: flags ( values -- n )
|
|
|
|
0 [ execute bitor ] reduce ;
|