2004-07-22 19:48:50 -04:00
|
|
|
! :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-09-27 23:01:04 -04:00
|
|
|
DEFER: vector-hashcode
|
2004-08-20 18:48:08 -04:00
|
|
|
|
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
|
|
|
|
2004-10-09 15:14:49 -04:00
|
|
|
: cpu ( -- arch )
|
|
|
|
#! Returns one of "x86" or "unknown".
|
|
|
|
11 getenv ;
|
|
|
|
|
2004-08-30 02:30:55 -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-30 21:49:49 -04:00
|
|
|
>r dup type r> vector-nth execute ;
|
2004-08-30 02:30:55 -04:00
|
|
|
|
2004-09-30 21:49:49 -04:00
|
|
|
: 2generic ( n n vtable -- )
|
2004-09-19 00:33:40 -04:00
|
|
|
>r 2dup arithmetic-type r> vector-nth execute ;
|
|
|
|
|
2004-09-30 21:49:49 -04:00
|
|
|
: default-hashcode drop 0 ;
|
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
: hashcode ( obj -- hash )
|
|
|
|
#! If two objects are =, they must have equal hashcodes.
|
2004-08-30 02:30:55 -04:00
|
|
|
{
|
2004-09-30 21:49:49 -04:00
|
|
|
nop
|
|
|
|
word-hashcode
|
|
|
|
cons-hashcode
|
|
|
|
default-hashcode
|
|
|
|
>fixnum
|
|
|
|
>fixnum
|
|
|
|
default-hashcode
|
|
|
|
default-hashcode
|
|
|
|
default-hashcode
|
|
|
|
vector-hashcode
|
|
|
|
str-hashcode
|
|
|
|
sbuf-hashcode
|
|
|
|
default-hashcode
|
|
|
|
>fixnum
|
|
|
|
>fixnum
|
|
|
|
default-hashcode
|
|
|
|
default-hashcode
|
2004-08-30 02:30:55 -04:00
|
|
|
} generic ;
|
|
|
|
|
2004-09-19 17:39:28 -04:00
|
|
|
IN: math DEFER: number= ( defined later... )
|
|
|
|
IN: kernel
|
2004-09-27 23:01:04 -04:00
|
|
|
: = ( obj obj -- ? )
|
|
|
|
#! Push t if a is isomorphic to b.
|
2004-08-30 02:30:55 -04:00
|
|
|
{
|
2004-09-30 21:49:49 -04:00
|
|
|
number=
|
|
|
|
eq?
|
|
|
|
cons=
|
|
|
|
eq?
|
|
|
|
number=
|
|
|
|
number=
|
|
|
|
eq?
|
|
|
|
eq?
|
|
|
|
eq?
|
|
|
|
vector=
|
|
|
|
str=
|
|
|
|
sbuf=
|
|
|
|
eq?
|
|
|
|
number=
|
|
|
|
number=
|
|
|
|
eq?
|
|
|
|
eq?
|
2004-08-30 02:30:55 -04:00
|
|
|
} generic ;
|
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-10-09 15:14:49 -04:00
|
|
|
: set-boot ( quot -- )
|
|
|
|
#! Set the boot quotation.
|
|
|
|
8 setenv ;
|
|
|
|
|
2004-07-17 19:33:35 -04:00
|
|
|
: java? f ;
|
|
|
|
: native? t ;
|
|
|
|
|
2004-07-19 00:34:03 -04:00
|
|
|
! No compiler...
|
|
|
|
: inline ;
|
|
|
|
: interpret-only ;
|
|
|
|
|
2004-07-22 19:48:50 -04:00
|
|
|
! HACKS
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
IN: strings
|
2004-07-22 19:48:50 -04:00
|
|
|
: char? drop f ;
|
|
|
|
: >char ;
|
2004-07-16 02:26:21 -04:00
|
|
|
: >upper ;
|
|
|
|
: >lower ;
|