factor/library/platform/native/kernel.factor

135 lines
3.2 KiB
Factor
Raw Normal View History

! :folding=none:collapseFolds=1:
2004-07-17 18:35:09 -04:00
! $Id$
!
! Copyright (C) 2004 Slava Pestov.
!
! Redistribution and use in source and binary forms, with or without
! modification, are permitted provided that the following conditions are met:
!
! 1. Redistributions of source code must retain the above copyright notice,
! this list of conditions and the following disclaimer.
!
! 2. Redistributions in binary form must reproduce the above copyright notice,
! this list of conditions and the following disclaimer in the documentation
! and/or other materials provided with the distribution.
!
! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2004-08-20 18:48:08 -04:00
IN: vectors
DEFER: vector=
2004-07-16 02:26:21 -04:00
IN: kernel
2004-09-18 18:15:01 -04:00
2004-07-16 02:26:21 -04:00
USE: combinators
2004-07-17 18:35:09 -04:00
USE: errors
2004-08-13 18:43:03 -04:00
USE: io-internals
2004-07-16 02:26:21 -04:00
USE: lists
USE: logic
2004-08-26 22:21:17 -04:00
USE: math
2004-07-16 02:26:21 -04:00
USE: namespaces
USE: stack
2004-07-24 00:54:57 -04:00
USE: stdio
2004-07-16 02:26:21 -04:00
USE: strings
USE: vectors
USE: words
2004-07-24 00:54:57 -04:00
USE: unparser
2004-08-20 18:48:08 -04:00
USE: vectors
2004-07-16 02:26:21 -04:00
! The 'fake vtable' used here speeds things up a lot.
! It is quite clumsy, however. A higher-level CLOS-style
! 'generic words' system will be built later.
: generic ( obj vtable -- )
2004-09-26 20:16:02 -04:00
over type swap vector-nth call ;
2004-09-19 00:33:40 -04:00
: 2generic ( n n map -- )
>r 2dup arithmetic-type r> vector-nth execute ;
2004-07-16 02:26:21 -04:00
: hashcode ( obj -- hash )
#! If two objects are =, they must have equal hashcodes.
{
[ ]
[ word-hashcode ]
[ 4 cons-hashcode ]
[ drop 0 ]
[ >fixnum ]
[ >fixnum ]
[ drop 0 ]
[ drop 0 ]
[ drop 0 ]
2004-09-26 21:34:25 -04:00
[ vector-hashcode ]
[ str-hashcode ]
2004-09-26 21:34:25 -04:00
[ sbuf-hashcode ]
[ drop 0 ]
[ >fixnum ]
[ >fixnum ]
2004-09-18 18:15:01 -04:00
[ drop 0 ]
2004-09-19 17:39:28 -04:00
[ drop 0 ]
} generic ;
2004-09-19 17:39:28 -04:00
IN: math DEFER: number= ( defined later... )
IN: kernel
: equal? ( obj obj -- ? )
#! Use = instead.
{
[ number= ]
[ eq? ]
[ cons= ]
[ eq? ]
[ number= ]
[ number= ]
[ eq? ]
[ eq? ]
[ eq? ]
[ vector= ]
[ str= ]
[ sbuf= ]
[ eq? ]
[ number= ]
[ number= ]
2004-09-18 18:15:01 -04:00
[ eq? ]
2004-09-19 17:39:28 -04:00
[ eq? ]
} generic ;
2004-07-16 02:26:21 -04:00
: = ( obj obj -- ? )
#! Push t if a is isomorphic to b.
2dup eq? [ 2drop t ] [ equal? ] ifte ;
2004-07-16 02:26:21 -04:00
2004-09-19 00:33:40 -04:00
: 2= ( a b c d -- ? )
#! Test if a = c, b = d.
swapd = [ = ] [ 2drop f ] ifte ;
2004-07-16 02:26:21 -04:00
: clone ( obj -- obj )
[
[ cons? ] [ clone-list ]
2004-08-25 20:51:19 -04:00
[ vector? ] [ vector-clone ]
[ sbuf? ] [ sbuf-clone ]
2004-07-16 02:26:21 -04:00
[ drop t ] [ ( return the object ) ]
] cond ;
2004-07-17 19:33:35 -04:00
: java? f ;
: native? t ;
! No compiler...
: inline ;
: interpret-only ;
! HACKS
2004-07-16 02:26:21 -04:00
IN: strings
: char? drop f ;
: >char ;
2004-07-16 02:26:21 -04:00
: >upper ;
: >lower ;