should fix in 0.82:
-- callback segv
-- generate-push should not do anything without sse2
-- get literals working
-- get loads from stack working
-- get boxing working
-- straighten out "fp-scratch"
- clean up/rewrite register allocation
- amd64 %box-struct
--- /dev/null
+USING: image kernel-internals namespaces ;
+
+! Do not load this file into a running image, ever.
+
+4 \ cell set
+big-endian off
! #push
UNION: immediate fixnum POSTPONE: f ;
-: alloc-literal-reg ( literal -- vreg )
- float? T{ float-regs f 8 } T{ int-regs } ? alloc-reg ;
-
: generate-push ( node -- )
>#push< dup literal-template
dup requested-vregs ensure-vregs
: take-reg ( vreg -- ) dup delegate free-vregs delete ;
+: reg-spec>class ( spec -- class )
+ float eq? T{ float-regs f 8 } T{ int-regs } ? ;
+
: alloc-vregs ( template -- template )
[
- dup
- H{ { f T{ int-regs } } { float T{ float-regs f 8 } } }
- hash [ alloc-reg ] [ <int-vreg> dup take-reg ] ?if
+ dup integer? [
+ <int-vreg> dup take-reg
+ ] [
+ reg-spec>class alloc-reg
+ ] if
] map ;
! A data stack location.
: finalize-heights ( -- )
phantoms [ finalize-height ] 2apply ;
-: stack>new-vreg ( loc -- vreg )
- T{ int-regs } alloc-reg [ swap %peek ] keep ;
+: stack>new-vreg ( loc spec -- vreg )
+ reg-spec>class alloc-reg [ swap %peek ] keep ;
: vreg>stack ( value loc -- )
over loc? [
: live-locs ( phantom phantom -- hash )
[ (live-locs) ] 2apply append prune
- [ dup stack>new-vreg ] map>hash ;
+ [ dup f stack>new-vreg ] map>hash ;
: lazy-store ( value loc -- )
over loc? [
compute-free-vregs free-vregs* swapd <= >r <= r> and
[ finalize-contents compute-free-vregs ] unless ;
-: lazy-load ( value loc -- value )
- over loc?
- [ dupd = [ drop f ] [ stack>new-vreg ] if ] [ drop ] if ;
-
-: phantom-vregs ( values template -- )
- [ >r f lazy-load r> second set ] 2each ;
+: lazy-load ( values template -- template )
+ [
+ first2 >r over loc? [
+ over integer? [
+ >r <int-vreg> dup r> %peek
+ ] [
+ stack>new-vreg
+ ] if
+ ] [
+ drop
+ ] if r> 2array
+ ] 2map ;
: stack>vregs ( phantom template -- values )
[
phantom-d get
over length neg over adjust-phantom
over length swap cut-phantom
- swap phantom-vregs ;
+ swap lazy-load [ first2 set ] each ;
: phantom-push ( obj stack -- )
1 over adjust-phantom push ;
output-vregs append phantoms append
[ swap member? ] contains-with? ;
+: phantom-vregs ( values template -- ) [ second set ] 2each ;
+
: slow-input ( template -- )
! Are we loading stuff from the stack? Then flush out
! remaining vregs, not slurped in by fast-input.
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: compiler
-USING: arrays generic hashtables kernel math namespaces
-sequences vectors words ;
+USING: arrays generic hashtables kernel kernel-internals math
+namespaces sequences vectors words ;
-: make-specializer ( quot class picker -- quot )
+: make-standard-specializer ( quot class picker -- quot )
over \ object eq? [
2drop
] [
] [ ] make
] if ;
+: make-math-specializer ( quot picker -- quot )
+ [
+ , \ tag , num-tags swap <array> , \ dispatch ,
+ ] [ ] make ;
+
+: make-specializer ( quot class picker -- quot )
+ over number eq? [
+ nip make-math-specializer
+ ] [
+ make-standard-specializer
+ ] if ;
+
: specialized-def ( word -- quot )
dup word-def swap "specializer" word-prop [
reverse-slice { dup over pick } [
] 2each
] when* ;
+{ 1+ 1- sq neg recip sgn truncate } [
+ { number } "specializer" set-word-prop
+] each
+
{ vneg norm-sq norm normalize } [
{ array } "specializer" set-word-prop
] each
! Math combination for generic dyadic upgrading arithmetic.
-: first/last ( seq -- pair ) dup first swap peek 2array ;
+: last/first ( seq -- pair ) dup peek swap first 2array ;
: math-class? ( object -- ? )
dup word? [ number bootstrap-word class< ] [ drop f ] if ;
: math-class-compare ( class class -- n )
[
dup math-class?
- [ types first/last ] [ drop { 100 100 } ] if
+ [ types last/first ] [ drop { 100 100 } ] if
] 2apply <=> ;
: math-class-max ( class class -- class )
r> 2drop
] if ;
-: delegate-slots { { 3 delegate set-delegate } } ;
+: delegate-slots { { 3 object delegate set-delegate } } ;
: tuple-slots ( tuple slots -- )
2dup "slot-names" set-word-prop
: cell 17 getenv ; foldable
-: tag-address ( x tag -- tagged ) swap tag-bits shift bitor ;
-: tag-header ( id -- tagged ) object-tag tag-address ;
-
IN: kernel
: win32? windows? cell 4 = and ; inline
IN: memory
: generations ( -- n ) 15 getenv ;
-
: image ( -- path ) 16 getenv ;
-
: save ( -- ) image save-image ;
M: complex / ( x y -- x/y ) complex/ tuck / >r / r> (rect>) ;
M: complex /f ( x y -- x/y ) complex/ tuck /f >r /f r> (rect>) ;
-M: complex 1+ >rect >r 1+ r> (rect>) ;
-M: complex 1- >rect >r 1- r> (rect>) ;
-
M: complex abs ( z -- |z| ) absq fsqrt ;
M: complex hashcode ( n -- n )
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: kernel-internals
-USING: namespaces math ;
+USING: kernel namespaces math ;
: bootstrap-cell \ cell get ; inline
: cells cell * ; inline
: cell-bits 8 cells ; inline
: bootstrap-cell-bits 8 bootstrap-cells ; inline
+: tag-address ( x tag -- tagged ) swap tag-bits shift bitor ;
+: tag-header ( id -- tagged ) object-tag tag-address ;
+
IN: math
: i C{ 0 1 } ; inline
: fp-nan? ( float -- ? )
double>bits -51 shift BIN: 111111111111 [ bitand ] keep = ;
-M: float zero?
- double>bits HEX: 8000000000000000 [ bitor ] keep number= ;
+M: float zero? ( float -- ? ) dup 0.0 = swap -0.0 = or ;
M: float < float< ;
M: float <= float<= ;
M: float / float/f ;
M: float /f float/f ;
M: float mod float-mod ;
-
-M: float 1+ 1.0 float+ ;
-M: float 1- 1.0 float- ;
M: fixnum /mod fixnum/mod ;
-M: fixnum 1+ 1 fixnum+ ;
-M: fixnum 1- 1 fixnum- ;
-
M: fixnum bitand fixnum-bitand ;
M: fixnum bitor fixnum-bitor ;
M: fixnum bitxor fixnum-bitxor ;
M: fixnum bitnot fixnum-bitnot ;
-M: fixnum zero? 0 eq? ;
-
M: bignum number= bignum= ;
M: bignum < bignum< ;
M: bignum <= bignum<= ;
M: bignum /mod bignum/mod ;
-M: bignum 1+ 1 >bignum bignum+ ;
-M: bignum 1- 1 >bignum bignum- ;
-
M: bignum bitand bignum-bitand ;
M: bignum bitor bignum-bitor ;
M: bignum bitxor bignum-bitxor ;
M: bignum bitnot bignum-bitnot ;
-M: bignum zero? 0 >bignum bignum= ;
+M: integer zero? 0 number= ;
GENERIC: bitnot ( n -- n ) foldable
-GENERIC: 1+ ( x -- x+1 ) foldable
-GENERIC: 1- ( x -- x-1 ) foldable
GENERIC: abs ( z -- |z| ) foldable
GENERIC: absq ( n -- |n|^2 ) foldable
GENERIC: zero? ( x -- ? ) foldable
M: object zero? drop f ;
+: 1+ 1 + ; foldable
+: 1- 1 - ; foldable
: sq dup * ; foldable
: neg 0 swap - ; foldable
: recip 1 swap / ; foldable
M: ratio /i scale /i ;
M: ratio mod 2dup >r >r /i r> r> rot * - ;
M: ratio /f scale /f ;
-
-M: ratio 1+ >fraction [ + ] keep fraction> ;
-M: ratio 1- >fraction [ - ] keep fraction> ;
-IN: temporary
USING: arrays assembler compiler generic
hashtables inference kernel kernel-internals lists math
optimizer prettyprint sequences strings test vectors words
sequences-internals ;
+IN: temporary
: kill-1
[ 1 2 3 ] [ + ] over drop drop ; compiled
: set= 2dup subset? >r swap subset? r> and ;
+USE: optimizer
+
: kill-set dup live-values swap literals hash-diff ;
: kill-set=
-IN: temporary
USE: compiler
USE: test
USE: math
USE: kernel
USE: math-internals
USE: memory
+IN: temporary
: no-op ; compiled
! Black box testing of templater optimization
-IN: temporary
USING: arrays compiler kernel kernel-internals math
math-internals namespaces sequences sequences-internals test ;
+IN: temporary
! Oops!
[ 5000 ] [ [ 5000 ] compile-1 ] unit-test