diff --git a/contrib/units/dimensioned.factor b/contrib/units/dimensioned.factor index 31687f02c7..7472a70b0d 100644 --- a/contrib/units/dimensioned.factor +++ b/contrib/units/dimensioned.factor @@ -3,9 +3,6 @@ USING: kernel prettyprint io sequences words lists vectors inspector math errors IN: units-internal -: seq-diff ( seq1 seq2 -- seq2-seq1 ) - [ swap member? not ] subset-with ; flushable - : seq-intersect ( seq1 seq2 -- seq1/\seq2 ) [ swap member? ] subset-with ; flushable diff --git a/library/collections/sequences-epilogue.factor b/library/collections/sequences-epilogue.factor index 6cf51c4a71..bd229be18c 100644 --- a/library/collections/sequences-epilogue.factor +++ b/library/collections/sequences-epilogue.factor @@ -103,6 +103,9 @@ M: object >list ( seq -- list ) dup length 0 rot (>list) ; #! Remove duplicates. dup dup length swap [ over adjoin ] each swap like ; +: diff ( seq1 seq2 -- seq2-seq1 ) + [ swap member? not ] subset-with ; flushable + : append3 ( s1 s2 s3 -- s1+s2+s3 ) #! Return a new sequence of the same type as s1. rot [ [ rot nappend ] keep swap nappend ] immutable ; flushable diff --git a/library/compiler/amd64/architecture.factor b/library/compiler/amd64/architecture.factor index 9c08ed0d94..0a5b7e5335 100644 --- a/library/compiler/amd64/architecture.factor +++ b/library/compiler/amd64/architecture.factor @@ -13,12 +13,7 @@ USING: assembler compiler-backend kernel sequences ; #! Can fixnum operations take immediate operands? f ; inline -: vregs ( -- n ) - #! Number of vregs - 3 ; inline - -M: vreg v>operand ( vreg -- reg ) - vreg-n { RAX RCX RDX RSI RDI R8 R9 R10 R11 } nth ; +: vregs { RAX RCX RDX RSI RDI R8 R9 R10 R11 } ; inline ! FIXME M: int-regs fastcall-regs drop 0 ; diff --git a/library/compiler/amd64/load.factor b/library/compiler/amd64/load.factor index 87cd300a94..33d622f51d 100644 --- a/library/compiler/amd64/load.factor +++ b/library/compiler/amd64/load.factor @@ -4,7 +4,10 @@ USING: io kernel parser sequences ; "/library/compiler/x86/assembler.factor" "/library/compiler/amd64/assembler.factor" "/library/compiler/amd64/architecture.factor" + "/library/compiler/x86/generator.factor" + "/library/compiler/x86/slots.factor" "/library/compiler/x86/stack.factor" + "/library/compiler/amd64/stack.factor" ] [ dup print run-resource ] each diff --git a/library/compiler/amd64/stack.factor b/library/compiler/amd64/stack.factor new file mode 100644 index 0000000000..97b944a7ab --- /dev/null +++ b/library/compiler/amd64/stack.factor @@ -0,0 +1,9 @@ +! Copyright (C) 2005 Slava Pestov. +! See http://factor.sf.net/license.txt for BSD license. +IN: compiler-backend +USING: arrays assembler compiler kernel ; + +: load-indirect ( dest literal -- ) + #! We cannot use the x86 definition here. + 0 scratch swap add-literal MOV 0 0 rel-address + 0 scratch swap 1array MOV ; diff --git a/library/compiler/architecture.factor b/library/compiler/architecture.factor index 73274318f8..f481809bb5 100644 --- a/library/compiler/architecture.factor +++ b/library/compiler/architecture.factor @@ -5,8 +5,7 @@ IN: compiler-backend DEFER: fixnum-imm? ( -- ? ) #! Can fixnum operations take immediate operands? -DEFER: vregs ( -- n ) -#! Number of vregs +DEFER: vregs ( -- regs ) DEFER: dual-fp/int-regs? ( -- ? ) #! Should fp parameters to fastcalls be loaded in integer diff --git a/library/compiler/ppc/architecture.factor b/library/compiler/ppc/architecture.factor index 1aecfc1d8e..88a83d7734 100644 --- a/library/compiler/ppc/architecture.factor +++ b/library/compiler/ppc/architecture.factor @@ -10,11 +10,7 @@ USING: assembler compiler-backend kernel math ; #! Can fixnum operations take immediate operands? f ; inline -: vregs ( -- n ) - #! Number of vregs - 8 ; inline - -M: vreg v>operand vreg-n 3 + ; +: vregs { 3 4 5 6 7 8 9 10 } ; inline M: int-regs fastcall-regs drop 8 ; M: int-regs reg-class-size drop 4 ; diff --git a/library/compiler/vops.factor b/library/compiler/vops.factor index 7cbcebb1fb..6ff0767d0f 100644 --- a/library/compiler/vops.factor +++ b/library/compiler/vops.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2004, 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: compiler-backend -USING: arrays errors generic hashtables kernel lists math -namespaces parser sequences words ; +USING: arrays errors generic hashtables kernel kernel-internals +lists math memory namespaces parser sequences words ; ! The linear IR is the second of the two intermediate ! representations used by Factor. It is basically a high-level @@ -47,6 +47,8 @@ GENERIC: v>operand M: integer v>operand tag-bits shift ; +M: vreg v>operand vreg-n vregs nth ; + M: f v>operand address ; ! A virtual operation @@ -56,7 +58,20 @@ TUPLE: vop inputs outputs label ; : set-vop-in ( input vop n -- ) swap vop-inputs set-nth ; : vop-out ( vop n -- input ) swap vop-outputs nth ; -: with-vop ( vop quot -- ) [ vop set call ] with-scope ; inline +: (scratch) + vop get dup vop-inputs swap vop-outputs append + [ vreg? ] subset [ v>operand ] map vregs diff ; + +: scratch ( n -- reg ) + #! Output a scratch register that is not used by the + #! current VOP. + \ scratch get nth ; + +: with-vop ( vop quot -- ) + [ + swap vop set (scratch) \ scratch set call + ] with-scope ; inline + : input ( n -- obj ) vop get vop-inputs nth ; : input-operand ( n -- n ) input v>operand ; : output ( n -- obj ) vop get vop-outputs nth ; diff --git a/library/compiler/x86/architecture.factor b/library/compiler/x86/architecture.factor index a2fc821fd3..52f1e7db4b 100644 --- a/library/compiler/x86/architecture.factor +++ b/library/compiler/x86/architecture.factor @@ -13,11 +13,7 @@ USING: assembler compiler-backend kernel sequences ; #! Can fixnum operations take immediate operands? t ; inline -: vregs ( -- n ) - #! Number of vregs - 3 ; inline - -M: vreg v>operand vreg-n { EAX ECX EDX } nth ; +: vregs { EAX ECX EDX } ; inline ! On x86, parameters are never passed in registers. M: int-regs fastcall-regs drop 0 ; diff --git a/library/compiler/x86/generator.factor b/library/compiler/x86/generator.factor index a02f90a5ba..a94afdfc29 100644 --- a/library/compiler/x86/generator.factor +++ b/library/compiler/x86/generator.factor @@ -61,7 +61,7 @@ M: %type generate-node ( vop -- )