factor/core/layouts/layouts.factor

79 lines
1.6 KiB
Factor
Raw Normal View History

! Copyright (C) 2007, 2008 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-03-12 02:54:29 -04:00
USING: namespaces math words kernel assocs classes
math.order kernel.private ;
2007-09-20 18:09:08 -04:00
IN: layouts
SYMBOL: tag-mask
SYMBOL: num-tags
SYMBOL: tag-bits
SYMBOL: num-types
SYMBOL: tag-numbers
SYMBOL: type-numbers
: tag-number ( class -- n )
tag-numbers get at [ object tag-number ] unless* ;
: type-number ( class -- n )
type-numbers get at ;
2008-01-02 19:36:36 -05:00
: tag-fixnum ( n -- tagged )
2007-09-20 18:09:08 -04:00
tag-bits get shift ;
2008-03-12 02:54:29 -04:00
: cell ( -- n ) 7 getenv ; foldable
: cells ( m -- n ) cell * ; inline
: cell-bits ( -- n ) 8 cells ; inline
: bootstrap-cell \ cell get cell or ; inline
: bootstrap-cells bootstrap-cell * ; inline
: bootstrap-cell-bits 8 bootstrap-cells ; inline
: (first-bignum) ( m -- n )
tag-bits get - 1 - 2^ ;
2007-09-20 18:09:08 -04:00
: first-bignum ( -- n )
2008-03-12 02:54:29 -04:00
cell-bits (first-bignum) ;
2007-09-20 18:09:08 -04:00
: most-positive-fixnum ( -- n )
first-bignum 1- ;
: most-negative-fixnum ( -- n )
first-bignum neg ;
: (max-array-capacity) ( b -- n )
5 - 2^ 1- ;
: max-array-capacity ( -- n )
cell-bits (max-array-capacity) ;
2008-03-12 02:54:29 -04:00
: bootstrap-first-bignum ( -- n )
bootstrap-cell-bits (first-bignum) ;
: bootstrap-most-positive-fixnum ( -- n )
bootstrap-first-bignum 1- ;
: bootstrap-most-negative-fixnum ( -- n )
bootstrap-first-bignum neg ;
: bootstrap-max-array-capacity ( -- n )
bootstrap-cell-bits (max-array-capacity) ;
2008-03-08 03:51:26 -05:00
M: bignum >integer
dup most-negative-fixnum most-positive-fixnum between?
[ >fixnum ] when ;
M: real >integer
dup most-negative-fixnum most-positive-fixnum between?
[ >fixnum ] [ >bignum ] if ;
UNION: immediate fixnum POSTPONE: f ;