1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: namespaces math words kernel assocs classes
4 math.order kernel.private ;
19 : tag-number ( class -- n )
20 tag-numbers get at [ object tag-number ] unless* ;
22 : type-number ( class -- n )
25 : tag-fixnum ( n -- tagged )
28 ! We do this in its own compilation unit so that they can be
31 : cell ( -- n ) 7 getenv ; foldable
33 : (first-bignum) ( m -- n ) tag-bits get - 1 - 2^ ; foldable
36 : cells ( m -- n ) cell * ; inline
38 : cell-bits ( -- n ) 8 cells ; inline
40 : bootstrap-cell ( -- n ) \ cell get cell or ; inline
42 : bootstrap-cells ( m -- n ) bootstrap-cell * ; inline
44 : bootstrap-cell-bits ( -- n ) 8 bootstrap-cells ; inline
46 : first-bignum ( -- n )
47 cell-bits (first-bignum) ; inline
49 : most-positive-fixnum ( -- n )
50 first-bignum 1- ; inline
52 : most-negative-fixnum ( -- n )
53 first-bignum neg ; inline
55 : (max-array-capacity) ( b -- n )
58 : max-array-capacity ( -- n )
59 cell-bits (max-array-capacity) ; inline
61 : bootstrap-first-bignum ( -- n )
62 bootstrap-cell-bits (first-bignum) ;
64 : bootstrap-most-positive-fixnum ( -- n )
65 bootstrap-first-bignum 1- ;
67 : bootstrap-most-negative-fixnum ( -- n )
68 bootstrap-first-bignum neg ;
70 : bootstrap-max-array-capacity ( -- n )
71 bootstrap-cell-bits (max-array-capacity) ;
74 dup most-negative-fixnum most-positive-fixnum between?
78 dup most-negative-fixnum most-positive-fixnum between?
79 [ >fixnum ] [ >bignum ] if ;
81 UNION: immediate fixnum POSTPONE: f ;