factor/library/kernel.factor

104 lines
2.4 KiB
Factor
Raw Normal View History

2006-01-09 01:34:23 -05:00
! Copyright (C) 2004, 2006 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
2006-01-06 22:42:07 -05:00
: clear V{ } set-datastack ;
2005-08-07 00:00:57 -04:00
GENERIC: hashcode ( obj -- n ) flushable
2004-12-18 23:35:20 -05:00
M: object hashcode drop 0 ;
GENERIC: hashcode* ( n obj -- n ) flushable
M: object hashcode* nip hashcode ;
GENERIC: = ( obj obj -- ? ) flushable
2004-12-18 23:35:20 -05:00
M: object = eq? ;
2006-01-09 01:34:23 -05:00
GENERIC: <=> ( obj1 obj2 -- n ) flushable
GENERIC: clone ( obj -- obj ) flushable
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-01-06 22:42:07 -05:00
: ? ( cond t f -- t/f ) rot [ drop ] [ nip ] if ; inline
2004-12-18 23:35:20 -05:00
: >boolean t f ? ; inline
2004-12-18 23:35:20 -05:00
: and ( a b -- a&b ) f ? ; inline
2005-01-13 14:41:08 -05:00
: or ( a b -- a|b ) t swap ? ; inline
2005-04-27 01:47:57 -04:00
2006-03-26 21:07:23 -05:00
: cpu ( -- arch ) 7 getenv ; foldable
: os ( -- os ) 11 getenv ; foldable
: windows? ( -- ? ) os "windows" = ; inline
: macosx? os "macosx" = ; inline
2006-01-06 22:42:07 -05:00
: slip >r call r> ; inline
2005-08-07 00:00:57 -04:00
2006-01-06 22:42:07 -05:00
: 2slip >r >r call r> r> ; inline
2005-08-07 00:00:57 -04:00
2006-01-06 22:42:07 -05:00
: keep over >r call r> ; inline
2005-08-07 00:00:57 -04:00
2006-01-06 22:42:07 -05:00
: 2keep over >r pick >r call r> r> ; inline
2005-08-07 00:00:57 -04:00
2006-01-06 22:42:07 -05:00
: 3keep >r 3dup r> swap >r swap >r swap >r call r> r> r> ;
inline
2005-08-07 00:00:57 -04:00
2006-01-06 22:42:07 -05:00
: 2apply tuck 2slip call ; inline
2006-01-06 22:42:07 -05:00
: if* pick [ drop call ] [ 2nip call ] if ; inline
2005-08-07 00:00:57 -04:00
2006-01-06 22:42:07 -05:00
: ?if >r >r [ nip r> r> drop call ] [ r> drop r> call ] if* ;
inline
2005-08-07 00:00:57 -04:00
2006-01-06 22:42:07 -05:00
: unless [ ] swap if ; inline
2005-08-07 00:00:57 -04:00
2006-01-06 22:42:07 -05:00
: unless* over [ drop ] [ nip call ] if ; inline
2005-08-07 00:00:57 -04:00
2006-01-06 22:42:07 -05:00
: when [ ] if ; inline
2005-08-07 00:00:57 -04:00
2006-01-06 22:42:07 -05:00
: when* dupd [ drop ] if ; inline
2005-08-07 00:00:57 -04:00
: with ( obj quot elt -- obj quot )
pick pick >r >r swap call r> r> ; inline
2006-01-06 22:42:07 -05:00
: keep-datastack datastack slip set-datastack drop ; inline
IN: kernel-internals
! These words are unsafe. Don't use them.
: declare ( types -- ) drop ;
: array-capacity 1 slot { fixnum } declare ; inline
: array-nth swap 2 fixnum+fast slot ; inline
: set-array-nth swap 2 fixnum+fast set-slot ; inline
2005-12-02 02:25:44 -05:00
! Some runtime implementation details
2006-05-18 01:08:09 -04:00
: num-types 19 ; inline
2005-12-02 02:25:44 -05:00
: tag-mask BIN: 111 ; inline
: num-tags 8 ; inline
: tag-bits 3 ; inline
: fixnum-tag BIN: 000 ; inline
: bignum-tag BIN: 001 ; inline
2006-05-18 01:08:09 -04:00
: word-tag BIN: 010 ; inline
2005-12-02 02:25:44 -05:00
: object-tag BIN: 011 ; inline
: ratio-tag BIN: 100 ; inline
: float-tag BIN: 101 ; inline
: complex-tag BIN: 110 ; inline
2006-05-18 01:08:09 -04:00
: wrapper-tag BIN: 111 ; inline
2005-12-02 02:25:44 -05:00
: cell 17 getenv ; foldable
2006-03-26 21:07:23 -05:00
IN: kernel
: win32? windows? cell 4 = and ; inline
: win64? windows? cell 8 = and ; inline
2006-03-27 23:03:25 -05:00
IN: memory
: generations ( -- n ) 15 getenv ;
: image ( -- path ) 16 getenv ;
: save ( -- ) image save-image ;