]> gitweb.factorcode.org Git - factor.git/blob - library/platform/native/kernel.factor
complex numbers
[factor.git] / library / platform / native / kernel.factor
1 ! :folding=none:collapseFolds=1:
2
3 ! $Id$
4 !
5 ! Copyright (C) 2004 Slava Pestov.
6
7 ! Redistribution and use in source and binary forms, with or without
8 ! modification, are permitted provided that the following conditions are met:
9
10 ! 1. Redistributions of source code must retain the above copyright notice,
11 !    this list of conditions and the following disclaimer.
12
13 ! 2. Redistributions in binary form must reproduce the above copyright notice,
14 !    this list of conditions and the following disclaimer in the documentation
15 !    and/or other materials provided with the distribution.
16
17 ! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 ! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 ! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 ! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 ! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 ! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 ! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 IN: namespaces
29 DEFER: init-namespaces
30
31 IN: kernel
32 USE: arithmetic
33 USE: combinators
34 USE: errors
35 USE: lists
36 USE: logic
37 USE: namespaces
38 USE: stack
39 USE: stdio
40 USE: strings
41 USE: vectors
42 USE: words
43 USE: unparser
44
45 : hashcode ( obj -- hash )
46     #! If two objects are =, they must have equal hashcodes.
47     [
48         [ cons? ] [ 4 cons-hashcode ]
49         [ string? ] [ str-hashcode ]
50         [ number? ] [ >fixnum ]
51         [ drop t ] [ drop 0 ]
52     ] cond ;
53
54 : = ( obj obj -- ? )
55     #! Push t if a is isomorphic to b.
56     2dup eq? [
57         2drop t
58     ] [
59         [
60             [ number? ] [ number= ]
61             [ cons? ] [ cons= ]
62             [ string? ] [ str= ]
63             [ drop t ] [ 2drop f ]
64         ] cond
65     ] ifte ;
66
67 : clone ( obj -- obj )
68     [
69         [ cons? ] [ clone-list ]
70         [ vector? ] [ clone-vector ]
71         [ drop t ] [ ( return the object ) ]
72     ] cond ;
73
74 : class-of ( obj -- name )
75     [
76         [ fixnum?  ] [ drop "fixnum" ]
77         [ bignum?  ] [ drop "bignum" ]
78         [ ratio?   ] [ drop "ratio" ]
79         [ float?   ] [ drop "float" ]
80         [ complex? ] [ drop "complex" ]
81         [ cons?    ] [ drop "cons" ]
82         [ word?    ] [ drop "word" ]
83         [ f =      ] [ drop "f" ]
84         [ t =      ] [ drop "t" ]
85         [ vector?  ] [ drop "vector" ]
86         [ string?  ] [ drop "string" ]
87         [ sbuf?    ] [ drop "sbuf" ]
88         [ handle?  ] [ drop "handle" ]
89         [ drop t   ] [ drop "unknown" ]
90     ] cond ;
91
92 : toplevel ( -- )
93     init-namespaces
94     init-errors
95     0 <vector> set-datastack
96     0 <vector> set-callstack ;
97
98 : java? f ;
99 : native? t ;
100
101 ! No compiler...
102 : inline ;
103 : interpret-only ;
104
105 ! HACKS
106
107 IN: strings
108 : char? drop f ;
109 : >char ;
110 : >upper ;
111 : >lower ;