factor/core/kernel.factor

102 lines
2.5 KiB
Factor
Raw Normal View History

! Copyright (C) 2004, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
2004-12-24 02:52:02 -05:00
IN: kernel
USING: generic kernel-internals math math-internals ;
2004-12-24 02:52:02 -05:00
2005-08-07 00:00:57 -04:00
: 2swap ( x y z t -- z t x y ) rot >r rot r> ; inline
: roll ( x y z t -- y z t x ) >r rot r> swap ; inline
: -roll ( x y z t -- t x y z ) swap >r -rot r> ; inline
2006-08-15 21:23:05 -04:00
: clear ( -- ) V{ } set-datastack ;
2005-08-07 00:00:57 -04:00
GENERIC: hashcode* ( n obj -- code )
M: object hashcode* 2drop 0 ;
: hashcode ( obj -- code ) 3 swap hashcode* ; inline
2004-12-18 23:35:20 -05:00
GENERIC: equal? ( obj1 obj2 -- ? )
M: object equal? 2drop f ;
2006-08-07 15:41:31 -04:00
2006-08-15 21:23:05 -04:00
: = ( obj1 obj2 -- ? )
2006-08-07 15:41:31 -04:00
2dup eq? [ 2drop t ] [ equal? ] if ; inline
2004-12-18 23:35:20 -05:00
GENERIC: <=> ( obj1 obj2 -- n )
2006-01-09 01:34:23 -05:00
2006-08-15 21:23:05 -04:00
GENERIC: clone ( obj -- cloned )
2005-01-28 23:55:22 -05:00
M: object clone ;
2006-01-06 22:42:07 -05:00
: set-boot ( quot -- ) 8 setenv ;
2006-08-15 21:23:05 -04:00
: ? ( cond true false -- true/false )
rot [ drop ] [ nip ] if ; inline
2004-12-18 23:35:20 -05:00
2006-08-15 21:23:05 -04:00
: slip ( quot x -- x ) >r call r> ; inline
2005-08-07 00:00:57 -04:00
2006-08-15 21:23:05 -04:00
: 2slip ( quot x y -- x y ) >r >r call r> r> ; inline
2005-08-07 00:00:57 -04:00
: 3slip ( quot x y -- x y ) >r >r >r call r> r> r> ; inline
: keep ( x quot -- x ) over slip ; inline
2005-08-07 00:00:57 -04:00
: 2keep ( x y quot -- x y ) pick pick 2slip ; inline
2005-08-07 00:00:57 -04:00
2006-08-15 21:23:05 -04:00
: 3keep ( x y z quot -- x y z )
>r 3dup r> -roll 3slip ; inline
2005-08-07 00:00:57 -04:00
2006-08-15 21:23:05 -04:00
: 2apply ( x y quot -- ) tuck 2slip call ; inline
2006-08-15 21:23:05 -04:00
: if* ( cond true false -- )
pick [ drop call ] [ 2nip call ] if ; inline
2005-08-07 00:00:57 -04:00
2006-08-15 21:23:05 -04:00
: ?if ( default cond true false -- )
pick [ roll 2drop call ] [ 2nip call ] if ; inline
2005-08-07 00:00:57 -04:00
2006-08-15 21:23:05 -04:00
: unless ( cond false -- ) [ ] swap if ; inline
2005-08-07 00:00:57 -04:00
2006-08-15 21:23:05 -04:00
: unless* ( cond false -- )
over [ drop ] [ nip call ] if ; inline
2005-08-07 00:00:57 -04:00
2006-08-15 21:23:05 -04:00
: when ( cond true -- ) [ ] if ; inline
2005-08-07 00:00:57 -04:00
2006-08-15 21:23:05 -04:00
: when* ( cond true -- ) dupd [ drop ] if ; inline
2006-07-22 17:17:21 -04:00
2006-08-15 21:23:05 -04:00
: >boolean ( obj -- ? ) t f ? ; inline
2006-08-15 21:23:05 -04:00
: and ( obj1 obj2 -- ? ) f ? ; inline
: or ( obj1 obj2 -- ? ) dupd ? ; inline
2006-08-15 21:23:05 -04:00
: xor ( obj1 obj2 -- ? ) [ not ] when ; inline
2005-08-07 00:00:57 -04:00
: both? ( x y quot -- ? ) 2apply and ; inline
: either? ( x y quot -- ? ) 2apply or ; inline
: compare ( obj1 obj2 quot -- n ) 2apply <=> ; inline
2005-08-07 00:00:57 -04:00
: with ( obj quot elt -- obj quot )
[ swap call ] 3keep drop ; inline
2005-08-07 00:00:57 -04:00
: cell ( -- n ) 1 getenv ; foldable
: cpu ( -- cpu ) 7 getenv ; foldable
: os ( -- os ) 11 getenv ; foldable
: image ( -- path ) 16 getenv ;
: vm ( -- path ) 17 getenv ;
: windows? ( -- ? ) os [ "windows" = ] keep "wince" = or ; foldable
: wince? ( -- ? ) os "wince" = ; foldable
: win32? ( -- ? ) wince? not windows? cell 4 = and f ? ; foldable
: win64? ( -- ? ) windows? cell 8 = and ; foldable
: winnt? windows? wince? not and ; foldable
: macosx? ( -- ? ) os "macosx" = ; foldable
: embedded? ( -- ? ) 19 getenv ;
2006-03-27 23:03:25 -05:00
IN: kernel-internals
! These words are unsafe. Don't use them.
: declare ( spec -- ) drop ;