From 7074979745e2962d7af43057ab2b11c1732370de Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Fri, 26 Feb 2010 16:01:01 -0500 Subject: [PATCH] Moving new-sets to sets --- basis/bit-sets/bit-sets-tests.factor | 2 +- basis/bit-sets/bit-sets.factor | 2 +- .../cfg/alias-analysis/alias-analysis.factor | 1 + basis/compiler/cfg/dce/dce.factor | 2 +- basis/compiler/cfg/def-use/def-use.factor | 1 + basis/compiler/cfg/dominance/dominance.factor | 3 +- .../linear-scan/assignment/assignment.factor | 1 + .../cfg/linearization/order/order.factor | 2 +- basis/compiler/cfg/liveness/ssa/ssa.factor | 3 +- .../cfg/loop-detection/loop-detection.factor | 1 + .../preferred/preferred.factor | 1 + .../representations/representations.factor | 1 + basis/compiler/cfg/rpo/rpo.factor | 3 +- .../cfg/ssa/construction/construction.factor | 3 +- .../cfg/ssa/construction/tdmsc/tdmsc.factor | 2 +- .../cfg/ssa/destruction/destruction.factor | 1 + .../compiler/cfg/ssa/liveness/liveness.factor | 1 + basis/compiler/cfg/stacks/local/local.factor | 3 +- .../cfg/write-barrier/write-barrier.factor | 1 + basis/compiler/codegen/codegen.factor | 1 + basis/compiler/tree/checker/checker.factor | 1 + .../tree/dead-code/branches/branches.factor | 1 + .../tree/dead-code/liveness/liveness.factor | 1 + basis/compiler/tree/def-use/def-use.factor | 1 + .../tree/def-use/simplified/simplified.factor | 1 + .../allocations/allocations.factor | 1 + .../modular-arithmetic.factor | 1 + .../tree/propagation/propagation-tests.factor | 2 +- .../propagation/transforms/transforms.factor | 6 +- .../compiler/tree/recursive/recursive.factor | 1 + basis/help/markup/markup.factor | 1 + basis/inspector/inspector.factor | 1 + basis/peg/peg.factor | 1 + basis/prettyprint/backend/backend.factor | 2 +- basis/prettyprint/prettyprint.factor | 1 + basis/prettyprint/sections/sections.factor | 1 + basis/regexp/nfa/nfa.factor | 1 + basis/see/see.factor | 2 + basis/stack-checker/backend/backend.factor | 1 + .../dependencies/dependencies.factor | 1 + .../transforms/transforms.factor | 1 + basis/ui/gestures/gestures.factor | 1 + basis/ui/tools/listener/listener.factor | 1 + basis/unicode/data/data.factor | 1 + basis/vocabs/refresh/refresh.factor | 3 +- core/classes/algebra/algebra.factor | 1 + core/classes/classes.factor | 1 + core/classes/tuple/parser/parser.factor | 2 +- core/combinators/combinators.factor | 2 +- core/compiler/units/units.factor | 1 + core/destructors/destructors.factor | 1 + core/generic/generic.factor | 1 + core/hash-sets/hash-sets-tests.factor | 2 +- core/hash-sets/hash-sets.factor | 2 +- core/sets/sets-tests.factor | 51 +++++-- core/sets/sets.factor | 139 ++++++++++++------ 56 files changed, 195 insertions(+), 78 deletions(-) diff --git a/basis/bit-sets/bit-sets-tests.factor b/basis/bit-sets/bit-sets-tests.factor index 26010a3337..4e97e703d0 100644 --- a/basis/bit-sets/bit-sets-tests.factor +++ b/basis/bit-sets/bit-sets-tests.factor @@ -1,4 +1,4 @@ -USING: bit-sets tools.test new-sets kernel bit-arrays ; +USING: bit-sets tools.test sets kernel bit-arrays ; IN: bit-sets.tests [ T{ bit-set f ?{ t f t f t f } } ] [ diff --git a/basis/bit-sets/bit-sets.factor b/basis/bit-sets/bit-sets.factor index a3cac64295..9d3d09ec1b 100644 --- a/basis/bit-sets/bit-sets.factor +++ b/basis/bit-sets/bit-sets.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel accessors sequences byte-arrays bit-arrays math hints new-sets ; +USING: kernel accessors sequences byte-arrays bit-arrays math hints sets ; IN: bit-sets TUPLE: bit-set { table bit-array read-only } ; diff --git a/basis/compiler/cfg/alias-analysis/alias-analysis.factor b/basis/compiler/cfg/alias-analysis/alias-analysis.factor index 9fffa0eed2..810831f776 100644 --- a/basis/compiler/cfg/alias-analysis/alias-analysis.factor +++ b/basis/compiler/cfg/alias-analysis/alias-analysis.factor @@ -12,6 +12,7 @@ compiler.cfg.registers compiler.cfg.comparisons compiler.cfg.instructions compiler.cfg.representations.preferred ; +FROM: namespaces => set ; IN: compiler.cfg.alias-analysis ! We try to eliminate redundant slot operations using some simple heuristics. diff --git a/basis/compiler/cfg/dce/dce.factor b/basis/compiler/cfg/dce/dce.factor index c8010d9aa8..b4fcd018f4 100644 --- a/basis/compiler/cfg/dce/dce.factor +++ b/basis/compiler/cfg/dce/dce.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs kernel namespaces sequences compiler.cfg.instructions compiler.cfg.def-use -compiler.cfg.rpo compiler.cfg.predecessors hash-sets new-sets ; +compiler.cfg.rpo compiler.cfg.predecessors hash-sets sets ; FROM: namespaces => set ; IN: compiler.cfg.dce diff --git a/basis/compiler/cfg/def-use/def-use.factor b/basis/compiler/cfg/def-use/def-use.factor index 54cff2ccaa..3838a0d1b9 100644 --- a/basis/compiler/cfg/def-use/def-use.factor +++ b/basis/compiler/cfg/def-use/def-use.factor @@ -5,6 +5,7 @@ compiler.units fry generalizations generic kernel locals namespaces quotations sequences sets slots words compiler.cfg.instructions compiler.cfg.instructions.syntax compiler.cfg.rpo ; +FROM: namespaces => set ; IN: compiler.cfg.def-use GENERIC: defs-vreg ( insn -- vreg/f ) diff --git a/basis/compiler/cfg/dominance/dominance.factor b/basis/compiler/cfg/dominance/dominance.factor index d21e81526e..71dc12f6a1 100644 --- a/basis/compiler/cfg/dominance/dominance.factor +++ b/basis/compiler/cfg/dominance/dominance.factor @@ -3,6 +3,7 @@ USING: accessors assocs combinators sets math fry kernel math.order dlists deques vectors namespaces sequences sorting locals compiler.cfg.rpo compiler.cfg.predecessors ; +FROM: namespaces => set ; IN: compiler.cfg.dominance ! Reference: @@ -103,4 +104,4 @@ PRIVATE> [ accum push ] [ dom-children work-list push-all-front ] bi ] slurp-deque - accum ; \ No newline at end of file + accum ; diff --git a/basis/compiler/cfg/linear-scan/assignment/assignment.factor b/basis/compiler/cfg/linear-scan/assignment/assignment.factor index f69db1deea..6acb9169ec 100644 --- a/basis/compiler/cfg/linear-scan/assignment/assignment.factor +++ b/basis/compiler/cfg/linear-scan/assignment/assignment.factor @@ -13,6 +13,7 @@ compiler.cfg.linearization.order compiler.cfg.linear-scan.allocation compiler.cfg.linear-scan.allocation.state compiler.cfg.linear-scan.live-intervals ; +FROM: namespaces => set ; IN: compiler.cfg.linear-scan.assignment ! This contains both active and inactive intervals; any interval diff --git a/basis/compiler/cfg/linearization/order/order.factor b/basis/compiler/cfg/linearization/order/order.factor index f48816d1b9..166a0f0d50 100644 --- a/basis/compiler/cfg/linearization/order/order.factor +++ b/basis/compiler/cfg/linearization/order/order.factor @@ -4,7 +4,7 @@ USING: accessors assocs deques dlists kernel make sorting namespaces sequences combinators combinators.short-circuit fry math compiler.cfg.rpo compiler.cfg.utilities compiler.cfg.loop-detection compiler.cfg.predecessors -new-sets hash-sets ; +sets hash-sets ; FROM: namespaces => set ; IN: compiler.cfg.linearization.order diff --git a/basis/compiler/cfg/liveness/ssa/ssa.factor b/basis/compiler/cfg/liveness/ssa/ssa.factor index 81263c8e9a..5215c9c487 100644 --- a/basis/compiler/cfg/liveness/ssa/ssa.factor +++ b/basis/compiler/cfg/liveness/ssa/ssa.factor @@ -4,6 +4,7 @@ USING: kernel namespaces deques accessors sets sequences assocs fry hashtables dlists compiler.cfg.def-use compiler.cfg.instructions compiler.cfg.rpo compiler.cfg.liveness compiler.cfg.utilities compiler.cfg.predecessors ; +FROM: namespaces => set ; IN: compiler.cfg.liveness.ssa ! TODO: merge with compiler.cfg.liveness @@ -59,4 +60,4 @@ SYMBOL: work-list : live-in? ( vreg bb -- ? ) live-in key? ; -: live-out? ( vreg bb -- ? ) live-out key? ; \ No newline at end of file +: live-out? ( vreg bb -- ? ) live-out key? ; diff --git a/basis/compiler/cfg/loop-detection/loop-detection.factor b/basis/compiler/cfg/loop-detection/loop-detection.factor index 73b99ee132..2e2dab00f1 100644 --- a/basis/compiler/cfg/loop-detection/loop-detection.factor +++ b/basis/compiler/cfg/loop-detection/loop-detection.factor @@ -2,6 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs combinators deques dlists fry kernel namespaces sequences sets compiler.cfg compiler.cfg.predecessors ; +FROM: namespaces => set ; IN: compiler.cfg.loop-detection TUPLE: natural-loop header index ends blocks ; diff --git a/basis/compiler/cfg/representations/preferred/preferred.factor b/basis/compiler/cfg/representations/preferred/preferred.factor index 726521cfe1..3be96515de 100644 --- a/basis/compiler/cfg/representations/preferred/preferred.factor +++ b/basis/compiler/cfg/representations/preferred/preferred.factor @@ -5,6 +5,7 @@ words sets combinators generalizations cpu.architecture compiler.units compiler.cfg.utilities compiler.cfg compiler.cfg.rpo compiler.cfg.instructions compiler.cfg.def-use ; FROM: compiler.cfg.instructions.syntax => insn-def-slot insn-use-slots insn-temp-slots scalar-rep ; +FROM: namespaces => set ; IN: compiler.cfg.representations.preferred GENERIC: defs-vreg-rep ( insn -- rep/f ) diff --git a/basis/compiler/cfg/representations/representations.factor b/basis/compiler/cfg/representations/representations.factor index 005fe8c90b..eaea3b94c8 100644 --- a/basis/compiler/cfg/representations/representations.factor +++ b/basis/compiler/cfg/representations/representations.factor @@ -15,6 +15,7 @@ compiler.cfg.utilities compiler.cfg.loop-detection compiler.cfg.renaming.functor compiler.cfg.representations.preferred ; +FROM: namespaces => set ; IN: compiler.cfg.representations ! Virtual register representation selection. diff --git a/basis/compiler/cfg/rpo/rpo.factor b/basis/compiler/cfg/rpo/rpo.factor index b6322730ee..e99b9c6c1e 100644 --- a/basis/compiler/cfg/rpo/rpo.factor +++ b/basis/compiler/cfg/rpo/rpo.factor @@ -2,6 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors namespaces make math sequences sets assocs fry compiler.cfg compiler.cfg.instructions ; +FROM: namespaces => set ; IN: compiler.cfg.rpo SYMBOL: visited @@ -42,4 +43,4 @@ SYMBOL: visited dupd '[ _ optimize-basic-block ] each-basic-block ; inline : needs-post-order ( cfg -- cfg' ) - dup post-order drop ; \ No newline at end of file + dup post-order drop ; diff --git a/basis/compiler/cfg/ssa/construction/construction.factor b/basis/compiler/cfg/ssa/construction/construction.factor index 7662b8ab01..7cd85e5fbe 100644 --- a/basis/compiler/cfg/ssa/construction/construction.factor +++ b/basis/compiler/cfg/ssa/construction/construction.factor @@ -12,6 +12,7 @@ compiler.cfg.instructions compiler.cfg.renaming compiler.cfg.renaming.functor compiler.cfg.ssa.construction.tdmsc ; +FROM: namespaces => set ; IN: compiler.cfg.ssa.construction ! The phi placement algorithm is implemented in @@ -135,4 +136,4 @@ PRIVATE> [ compute-defs compute-phi-nodes insert-phi-nodes ] [ rename ] [ ] - } cleave ; \ No newline at end of file + } cleave ; diff --git a/basis/compiler/cfg/ssa/construction/tdmsc/tdmsc.factor b/basis/compiler/cfg/ssa/construction/tdmsc/tdmsc.factor index 7601ccc9bb..4c2210c493 100644 --- a/basis/compiler/cfg/ssa/construction/tdmsc/tdmsc.factor +++ b/basis/compiler/cfg/ssa/construction/tdmsc/tdmsc.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs bit-arrays bit-sets fry -hashtables hints kernel locals math namespaces sequences new-sets +hashtables hints kernel locals math namespaces sequences sets compiler.cfg compiler.cfg.dominance compiler.cfg.rpo ; FROM: namespaces => set ; IN: compiler.cfg.ssa.construction.tdmsc diff --git a/basis/compiler/cfg/ssa/destruction/destruction.factor b/basis/compiler/cfg/ssa/destruction/destruction.factor index d93045da55..8b766c8114 100644 --- a/basis/compiler/cfg/ssa/destruction/destruction.factor +++ b/basis/compiler/cfg/ssa/destruction/destruction.factor @@ -15,6 +15,7 @@ compiler.cfg.ssa.interference compiler.cfg.ssa.interference.live-ranges compiler.cfg.utilities compiler.utilities ; +FROM: namespaces => set ; IN: compiler.cfg.ssa.destruction ! Maps vregs to leaders. diff --git a/basis/compiler/cfg/ssa/liveness/liveness.factor b/basis/compiler/cfg/ssa/liveness/liveness.factor index 7847de28fc..6e84b8b77d 100644 --- a/basis/compiler/cfg/ssa/liveness/liveness.factor +++ b/basis/compiler/cfg/ssa/liveness/liveness.factor @@ -6,6 +6,7 @@ compiler.cfg.rpo compiler.cfg.dominance compiler.cfg.def-use compiler.cfg.instructions ; +FROM: namespaces => set ; IN: compiler.cfg.ssa.liveness ! Liveness checking on SSA IR, as described in diff --git a/basis/compiler/cfg/stacks/local/local.factor b/basis/compiler/cfg/stacks/local/local.factor index 30a2c4c13f..95feb4c034 100644 --- a/basis/compiler/cfg/stacks/local/local.factor +++ b/basis/compiler/cfg/stacks/local/local.factor @@ -8,6 +8,7 @@ compiler.cfg.instructions compiler.cfg.registers compiler.cfg.stacks.height compiler.cfg.parallel-copy ; +FROM: namespaces => set ; IN: compiler.cfg.stacks.local ! Local stack analysis. We build three sets for every basic block @@ -106,4 +107,4 @@ M: rs-loc translate-local-loc n>> current-height get r>> - ; : peek-set ( bb -- assoc ) peek-sets get at ; : replace-set ( bb -- assoc ) replace-sets get at ; -: kill-set ( bb -- assoc ) kill-sets get at ; \ No newline at end of file +: kill-set ( bb -- assoc ) kill-sets get at ; diff --git a/basis/compiler/cfg/write-barrier/write-barrier.factor b/basis/compiler/cfg/write-barrier/write-barrier.factor index 523f7c6d1c..cecf5f7251 100644 --- a/basis/compiler/cfg/write-barrier/write-barrier.factor +++ b/basis/compiler/cfg/write-barrier/write-barrier.factor @@ -3,6 +3,7 @@ USING: accessors assocs combinators.short-circuit compiler.cfg.instructions compiler.cfg.rpo kernel namespaces sequences sets ; +FROM: namespaces => set ; IN: compiler.cfg.write-barrier SYMBOL: fresh-allocations diff --git a/basis/compiler/codegen/codegen.factor b/basis/compiler/codegen/codegen.factor index 963ed0ab28..3edfcc565b 100755 --- a/basis/compiler/codegen/codegen.factor +++ b/basis/compiler/codegen/codegen.factor @@ -16,6 +16,7 @@ compiler.cfg.registers compiler.cfg.builder compiler.codegen.fixup compiler.utilities ; +FROM: namespaces => set ; IN: compiler.codegen SYMBOL: insn-counts diff --git a/basis/compiler/tree/checker/checker.factor b/basis/compiler/tree/checker/checker.factor index b3f01c8c01..a3a19b8f4d 100644 --- a/basis/compiler/tree/checker/checker.factor +++ b/basis/compiler/tree/checker/checker.factor @@ -7,6 +7,7 @@ compiler.tree compiler.tree.def-use compiler.tree.recursive compiler.tree.combinators ; +FROM: namespaces => set ; IN: compiler.tree.checker ! Check some invariants; this can help catch compiler bugs. diff --git a/basis/compiler/tree/dead-code/branches/branches.factor b/basis/compiler/tree/dead-code/branches/branches.factor index d1fdf6359a..5b5249f8e4 100644 --- a/basis/compiler/tree/dead-code/branches/branches.factor +++ b/basis/compiler/tree/dead-code/branches/branches.factor @@ -4,6 +4,7 @@ USING: sequences namespaces kernel accessors assocs sets fry arrays combinators columns stack-checker.backend stack-checker.branches compiler.tree compiler.tree.combinators compiler.tree.dead-code.liveness compiler.tree.dead-code.simple ; +FROM: namespaces => set ; IN: compiler.tree.dead-code.branches M: #if mark-live-values* look-at-inputs ; diff --git a/basis/compiler/tree/dead-code/liveness/liveness.factor b/basis/compiler/tree/dead-code/liveness/liveness.factor index 9ece5d340b..7e437cbc4e 100644 --- a/basis/compiler/tree/dead-code/liveness/liveness.factor +++ b/basis/compiler/tree/dead-code/liveness/liveness.factor @@ -4,6 +4,7 @@ USING: fry accessors namespaces assocs deques search-deques dlists kernel sequences compiler.utilities words sets stack-checker.branches compiler.tree compiler.tree.def-use compiler.tree.combinators ; +FROM: namespaces => set ; IN: compiler.tree.dead-code.liveness SYMBOL: work-list diff --git a/basis/compiler/tree/def-use/def-use.factor b/basis/compiler/tree/def-use/def-use.factor index 872b6131c9..a1c316140d 100644 --- a/basis/compiler/tree/def-use/def-use.factor +++ b/basis/compiler/tree/def-use/def-use.factor @@ -6,6 +6,7 @@ stack-checker.state stack-checker.branches compiler.tree compiler.tree.combinators ; +FROM: namespaces => set ; IN: compiler.tree.def-use SYMBOL: def-use diff --git a/basis/compiler/tree/def-use/simplified/simplified.factor b/basis/compiler/tree/def-use/simplified/simplified.factor index c2fb74c97e..0061e8cffb 100644 --- a/basis/compiler/tree/def-use/simplified/simplified.factor +++ b/basis/compiler/tree/def-use/simplified/simplified.factor @@ -2,6 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: sequences kernel fry vectors accessors namespaces assocs sets stack-checker.branches compiler.tree compiler.tree.def-use ; +FROM: namespaces => set ; IN: compiler.tree.def-use.simplified ! Simplified def-use follows chains of copies. diff --git a/basis/compiler/tree/escape-analysis/allocations/allocations.factor b/basis/compiler/tree/escape-analysis/allocations/allocations.factor index 5291c5e81f..015b6ad626 100644 --- a/basis/compiler/tree/escape-analysis/allocations/allocations.factor +++ b/basis/compiler/tree/escape-analysis/allocations/allocations.factor @@ -2,6 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs namespaces sequences kernel math combinators sets disjoint-sets fry stack-checker.values ; +FROM: namespaces => set ; IN: compiler.tree.escape-analysis.allocations ! A map from values to classes. Only for #introduce outputs diff --git a/basis/compiler/tree/modular-arithmetic/modular-arithmetic.factor b/basis/compiler/tree/modular-arithmetic/modular-arithmetic.factor index ece2ed80f3..961ce1ecd7 100644 --- a/basis/compiler/tree/modular-arithmetic/modular-arithmetic.factor +++ b/basis/compiler/tree/modular-arithmetic/modular-arithmetic.factor @@ -9,6 +9,7 @@ compiler.tree.propagation.info compiler.tree.def-use compiler.tree.def-use.simplified compiler.tree.late-optimizations ; +FROM: namespaces => set ; IN: compiler.tree.modular-arithmetic ! This is a late-stage optimization. diff --git a/basis/compiler/tree/propagation/propagation-tests.factor b/basis/compiler/tree/propagation/propagation-tests.factor index 8cc91538d6..444a424766 100644 --- a/basis/compiler/tree/propagation/propagation-tests.factor +++ b/basis/compiler/tree/propagation/propagation-tests.factor @@ -8,7 +8,7 @@ layouts compiler.tree.propagation.info compiler.tree.def-use compiler.tree.debugger compiler.tree.checker slots.private words hashtables classes assocs locals specialized-arrays system sorting math.libm math.floats.private math.integers.private -math.intervals quotations effects alien alien.data new-sets ; +math.intervals quotations effects alien alien.data sets ; FROM: math => float ; SPECIALIZED-ARRAY: double SPECIALIZED-ARRAY: void* diff --git a/basis/compiler/tree/propagation/transforms/transforms.factor b/basis/compiler/tree/propagation/transforms/transforms.factor index b6fda4d5b9..4f0eea9cbb 100644 --- a/basis/compiler/tree/propagation/transforms/transforms.factor +++ b/basis/compiler/tree/propagation/transforms/transforms.factor @@ -3,13 +3,13 @@ USING: alien.c-types kernel sequences words fry generic accessors classes.tuple classes classes.algebra definitions stack-checker.dependencies quotations classes.tuple.private math -math.partial-dispatch math.private math.intervals new-sets.private +math.partial-dispatch math.private math.intervals sets.private math.floats.private math.integers.private layouts math.order vectors hashtables combinators effects generalizations assocs -new-sets combinators.short-circuit sequences.private locals growable +sets combinators.short-circuit sequences.private locals growable stack-checker namespaces compiler.tree.propagation.info ; FROM: math => float ; -FROM: new-sets => set ; +FROM: sets => set ; IN: compiler.tree.propagation.transforms \ equal? [ diff --git a/basis/compiler/tree/recursive/recursive.factor b/basis/compiler/tree/recursive/recursive.factor index bc6243e138..0771b978a7 100644 --- a/basis/compiler/tree/recursive/recursive.factor +++ b/basis/compiler/tree/recursive/recursive.factor @@ -2,6 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel assocs arrays namespaces accessors sequences deques fry search-deques dlists combinators.short-circuit make sets compiler.tree ; +FROM: namespaces => set ; IN: compiler.tree.recursive TUPLE: call-site tail? node label ; diff --git a/basis/help/markup/markup.factor b/basis/help/markup/markup.factor index f951f30b2f..dd43c84864 100644 --- a/basis/help/markup/markup.factor +++ b/basis/help/markup/markup.factor @@ -8,6 +8,7 @@ prettyprint.stylesheet quotations see sequences sets slots sorting splitting strings vectors vocabs vocabs.loader words words.symbol ; FROM: prettyprint.sections => with-pprint ; +FROM: namespaces => set ; IN: help.markup PREDICATE: simple-element < array diff --git a/basis/inspector/inspector.factor b/basis/inspector/inspector.factor index 2aa7cd218e..92d61ca7cf 100644 --- a/basis/inspector/inspector.factor +++ b/basis/inspector/inspector.factor @@ -5,6 +5,7 @@ namespaces prettyprint prettyprint.custom prettyprint.sections sequences strings io.styles vectors words quotations mirrors splitting math.parser classes vocabs sets sorting summary debugger continuations fry combinators ; +FROM: namespaces => set ; IN: inspector SYMBOL: +number-rows+ diff --git a/basis/peg/peg.factor b/basis/peg/peg.factor index a180713ccf..cc480c30b2 100644 --- a/basis/peg/peg.factor +++ b/basis/peg/peg.factor @@ -5,6 +5,7 @@ io vectors arrays math.parser math.order combinators classes sets unicode.categories compiler.units parser effects.parser words quotations memoize accessors locals splitting combinators.short-circuit generalizations ; +FROM: namespaces => set ; IN: peg TUPLE: parse-result remaining ast ; diff --git a/basis/prettyprint/backend/backend.factor b/basis/prettyprint/backend/backend.factor index aead51a4e3..7d0cb40576 100644 --- a/basis/prettyprint/backend/backend.factor +++ b/basis/prettyprint/backend/backend.factor @@ -7,7 +7,7 @@ io.pathnames io.styles kernel make math math.order math.parser namespaces prettyprint.config prettyprint.custom prettyprint.sections prettyprint.stylesheet quotations sbufs sequences strings vectors words words.symbol hash-sets ; -FROM: new-sets => members ; +FROM: sets => members ; IN: prettyprint.backend M: effect pprint* effect>string "(" ")" surround text ; diff --git a/basis/prettyprint/prettyprint.factor b/basis/prettyprint/prettyprint.factor index 23cf956a1d..249a6e0a57 100644 --- a/basis/prettyprint/prettyprint.factor +++ b/basis/prettyprint/prettyprint.factor @@ -5,6 +5,7 @@ io.streams.string io.styles kernel make math math.parser namespaces parser prettyprint.backend prettyprint.config prettyprint.custom prettyprint.sections quotations sequences sorting strings vocabs vocabs.prettyprint words sets generic ; +FROM: namespaces => set ; IN: prettyprint : with-use ( obj quot -- ) diff --git a/basis/prettyprint/sections/sections.factor b/basis/prettyprint/sections/sections.factor index 6f5f61f688..cd606667fd 100644 --- a/basis/prettyprint/sections/sections.factor +++ b/basis/prettyprint/sections/sections.factor @@ -4,6 +4,7 @@ USING: arrays generic hashtables io kernel math assocs namespaces make sequences strings io.styles vectors words prettyprint.config splitting classes continuations accessors sets vocabs.parser combinators vocabs ; +FROM: namespaces => set ; IN: prettyprint.sections ! State diff --git a/basis/regexp/nfa/nfa.factor b/basis/regexp/nfa/nfa.factor index 35edcf328a..cc430f2de1 100644 --- a/basis/regexp/nfa/nfa.factor +++ b/basis/regexp/nfa/nfa.factor @@ -5,6 +5,7 @@ sequences fry quotations math.order math.ranges vectors unicode.categories regexp.transition-tables words sets hashtables combinators.short-circuit unicode.data regexp.ast regexp.classes memoize ; +FROM: namespaces => set ; IN: regexp.nfa ! This uses unicode.data for ch>upper and ch>lower diff --git a/basis/see/see.factor b/basis/see/see.factor index 326e051219..bb6ae5cf2d 100644 --- a/basis/see/see.factor +++ b/basis/see/see.factor @@ -8,6 +8,8 @@ io.streams.string io.styles kernel make namespaces prettyprint prettyprint.backend prettyprint.config prettyprint.custom prettyprint.sections sequences sets sorting strings summary words words.symbol words.constant words.alias vocabs slots ; +FROM: namespaces => set ; +FROM: classes => members ; IN: see GENERIC: synopsis* ( defspec -- ) diff --git a/basis/stack-checker/backend/backend.factor b/basis/stack-checker/backend/backend.factor index 8de930a6cd..ddb1fd0021 100644 --- a/basis/stack-checker/backend/backend.factor +++ b/basis/stack-checker/backend/backend.factor @@ -6,6 +6,7 @@ continuations assocs combinators compiler.errors accessors math.order definitions sets hints macros stack-checker.state stack-checker.visitor stack-checker.errors stack-checker.values stack-checker.recursive-state stack-checker.dependencies summary ; +FROM: namespaces => set ; IN: stack-checker.backend : push-d ( obj -- ) meta-d push ; diff --git a/basis/stack-checker/dependencies/dependencies.factor b/basis/stack-checker/dependencies/dependencies.factor index e2f7c57593..dcfb3db6bf 100644 --- a/basis/stack-checker/dependencies/dependencies.factor +++ b/basis/stack-checker/dependencies/dependencies.factor @@ -5,6 +5,7 @@ generic kernel math namespaces sequences words sets combinators.short-circuit classes.tuple alien.c-types ; FROM: classes.tuple.private => tuple-layout ; FROM: assocs => change-at ; +FROM: namespaces => set ; IN: stack-checker.dependencies ! Words that the current quotation depends on diff --git a/basis/stack-checker/transforms/transforms.factor b/basis/stack-checker/transforms/transforms.factor index cf32792a2e..9f966bd8b8 100644 --- a/basis/stack-checker/transforms/transforms.factor +++ b/basis/stack-checker/transforms/transforms.factor @@ -9,6 +9,7 @@ sequences.private generalizations stack-checker.backend stack-checker.state stack-checker.visitor stack-checker.errors stack-checker.values stack-checker.recursive-state stack-checker.dependencies ; +FROM: namespaces => set ; IN: stack-checker.transforms : call-transformer ( stack quot -- newquot ) diff --git a/basis/ui/gestures/gestures.factor b/basis/ui/gestures/gestures.factor index f33b6ec6da..30c96335cc 100644 --- a/basis/ui/gestures/gestures.factor +++ b/basis/ui/gestures/gestures.factor @@ -5,6 +5,7 @@ namespaces make sequences words strings system hashtables math.parser math.vectors classes.tuple classes boxes calendar alarms combinators sets columns fry deques ui.gadgets ui.gadgets.private ascii combinators.short-circuit ; +FROM: namespaces => set ; IN: ui.gestures : get-gesture-handler ( gesture gadget -- quot ) diff --git a/basis/ui/tools/listener/listener.factor b/basis/ui/tools/listener/listener.factor index 2a948fddc0..53d3bec56e 100644 --- a/basis/ui/tools/listener/listener.factor +++ b/basis/ui/tools/listener/listener.factor @@ -16,6 +16,7 @@ ui.tools.listener.completion ui.tools.listener.popups ui.tools.listener.history ui.images ui.tools.error-list tools.errors.model ; FROM: source-files.errors => all-errors ; +FROM: namespaces => set ; IN: ui.tools.listener ! If waiting is t, we're waiting for user input, and invoking diff --git a/basis/unicode/data/data.factor b/basis/unicode/data/data.factor index 24dfba6be0..85b59de750 100644 --- a/basis/unicode/data/data.factor +++ b/basis/unicode/data/data.factor @@ -6,6 +6,7 @@ math.parser hash2 math.order byte-arrays namespaces compiler.units parser io.encodings.ascii values interval-maps ascii sets combinators locals math.ranges sorting make strings.parser io.encodings.utf8 memoize simple-flat-file ; +FROM: namespaces => set ; IN: unicode.data set ; IN: vocabs.refresh : source-modified? ( path -- ? ) @@ -88,4 +89,4 @@ SYMBOL: modified-docs : refresh ( prefix -- ) to-refresh do-refresh ; -: refresh-all ( -- ) "" refresh ; \ No newline at end of file +: refresh-all ( -- ) "" refresh ; diff --git a/core/classes/algebra/algebra.factor b/core/classes/algebra/algebra.factor index f9aaf3eaa5..96fa34314e 100644 --- a/core/classes/algebra/algebra.factor +++ b/core/classes/algebra/algebra.factor @@ -3,6 +3,7 @@ USING: kernel classes classes.private combinators accessors sequences arrays vectors assocs namespaces words sorting layouts math hashtables kernel.private sets math.order ; +FROM: classes => members ; IN: classes.algebra set ; IN: classes ERROR: bad-inheritance class superclass ; diff --git a/core/classes/tuple/parser/parser.factor b/core/classes/tuple/parser/parser.factor index 8527275667..7482cce048 100644 --- a/core/classes/tuple/parser/parser.factor +++ b/core/classes/tuple/parser/parser.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2008, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel new-sets namespaces make sequences parser +USING: accessors kernel sets namespaces make sequences parser lexer combinators words classes.parser classes.tuple arrays slots math assocs parser.notes classes classes.algebra ; IN: classes.tuple.parser diff --git a/core/combinators/combinators.factor b/core/combinators/combinators.factor index 7b9481825b..ce0d04c73c 100644 --- a/core/combinators/combinators.factor +++ b/core/combinators/combinators.factor @@ -147,7 +147,7 @@ ERROR: no-case object ; : contiguous-range? ( keys -- ? ) dup [ fixnum? ] all? [ dup all-unique? [ - [ prune length ] + [ length ] [ [ supremum ] [ infimum ] bi - ] bi - 1 = ] [ drop f ] if diff --git a/core/compiler/units/units.factor b/core/compiler/units/units.factor index b024ed2c65..ffbdbefbf2 100644 --- a/core/compiler/units/units.factor +++ b/core/compiler/units/units.factor @@ -4,6 +4,7 @@ USING: accessors arrays kernel continuations assocs namespaces sequences words vocabs definitions hashtables init sets math math.order classes classes.private classes.algebra classes.tuple classes.tuple.private generic source-files.errors kernel.private ; +FROM: namespaces => set ; IN: compiler.units SYMBOL: old-definitions diff --git a/core/destructors/destructors.factor b/core/destructors/destructors.factor index ac3751e32e..e6d78fa03e 100644 --- a/core/destructors/destructors.factor +++ b/core/destructors/destructors.factor @@ -2,6 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors continuations kernel namespaces make sequences vectors sets assocs init math ; +FROM: namespaces => set ; IN: destructors SYMBOL: disposables diff --git a/core/generic/generic.factor b/core/generic/generic.factor index 0c626ac1d6..a733ac90fa 100644 --- a/core/generic/generic.factor +++ b/core/generic/generic.factor @@ -4,6 +4,7 @@ USING: accessors words kernel sequences namespaces make assocs hashtables definitions kernel.private classes classes.private classes.algebra quotations arrays vocabs effects combinators sets ; +FROM: namespaces => set ; IN: generic ! Method combination protocol diff --git a/core/hash-sets/hash-sets-tests.factor b/core/hash-sets/hash-sets-tests.factor index 2eef2bd309..5b7ffafc8b 100644 --- a/core/hash-sets/hash-sets-tests.factor +++ b/core/hash-sets/hash-sets-tests.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2010 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. -USING: new-sets tools.test kernel sorting prettyprint hash-sets ; +USING: sets tools.test kernel sorting prettyprint hash-sets ; IN: hash-sets.tests [ { 1 2 3 } ] [ HS{ 1 2 3 } members natural-sort ] unit-test diff --git a/core/hash-sets/hash-sets.factor b/core/hash-sets/hash-sets.factor index 52b883195e..bdef9a6ff9 100644 --- a/core/hash-sets/hash-sets.factor +++ b/core/hash-sets/hash-sets.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2010 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. -USING: accessors assocs hashtables kernel new-sets +USING: accessors assocs hashtables kernel sets sequences parser ; QUALIFIED: sets IN: hash-sets diff --git a/core/sets/sets-tests.factor b/core/sets/sets-tests.factor index f9f8ba9e65..aa76a4f02e 100644 --- a/core/sets/sets-tests.factor +++ b/core/sets/sets-tests.factor @@ -1,26 +1,16 @@ -USING: kernel sets tools.test ; +! Copyright (C) 2010 Daniel Ehrenberg +! See http://factorcode.org/license.txt for BSD license. +USING: sets tools.test kernel prettyprint hash-sets sorting ; IN: sets.tests -[ f ] [ { 0 1 1 2 3 5 } all-unique? ] unit-test -[ t ] [ { 0 1 2 3 4 5 } all-unique? ] unit-test - -[ V{ 1 2 3 } ] [ { 1 2 2 3 3 } prune ] unit-test -[ V{ 3 2 1 } ] [ { 3 3 2 2 1 } prune ] unit-test - [ { } ] [ { } { } intersect ] unit-test [ { 2 3 } ] [ { 1 2 3 } { 2 3 4 } intersect ] unit-test [ { } ] [ { } { } diff ] unit-test [ { 1 } ] [ { 1 2 3 } { 2 3 4 } diff ] unit-test -[ V{ } ] [ { } { } union ] unit-test -[ V{ 1 2 3 4 } ] [ { 1 2 3 } { 2 3 4 } union ] unit-test - -[ V{ 1 2 3 } ] -[ 3 V{ 1 2 } clone [ adjoin ] keep ] unit-test - -[ V{ 1 2 3 } ] -[ 3 V{ 1 3 2 } clone [ adjoin ] keep ] unit-test +[ { } ] [ { } { } union ] unit-test +[ { 1 2 3 4 } ] [ { 1 2 3 } { 2 3 4 } union ] unit-test [ t ] [ { 1 2 } { 1 3 } intersects? ] unit-test @@ -30,3 +20,34 @@ IN: sets.tests [ f ] [ { 1 } { } intersects? ] unit-test +[ t ] [ 4 { 2 4 5 } in? ] unit-test +[ f ] [ 1 { 2 4 5 } in? ] unit-test + +[ V{ 1 2 3 } ] [ 3 V{ 1 2 } clone [ adjoin ] keep ] unit-test +[ V{ 1 2 } ] [ 2 V{ 1 2 } clone [ adjoin ] keep ] unit-test +[ V{ 1 2 } ] [ 3 V{ 1 2 } clone [ delete ] keep ] unit-test +[ V{ 2 } ] [ 1 V{ 1 2 } clone [ delete ] keep ] unit-test + +[ t ] [ { 1 2 3 } { 2 1 3 } set= ] unit-test +[ f ] [ { 2 3 } { 1 2 3 } set= ] unit-test +[ f ] [ { 1 2 3 } { 2 3 } set= ] unit-test + +[ { 1 } ] [ { 1 } members ] unit-test + +[ { 1 2 3 } ] [ { 1 1 1 2 2 3 3 3 3 3 } dup set-like natural-sort ] unit-test +[ { 1 2 3 } ] [ HS{ 1 2 3 } { } set-like natural-sort ] unit-test + +[ HS{ 1 2 3 } ] [ { 1 2 3 } fast-set ] unit-test + +[ { 1 2 3 } ] [ { { 1 } { 2 } { 1 3 } } combine ] unit-test + +[ f ] [ { 0 1 1 2 3 5 } all-unique? ] unit-test +[ t ] [ { 0 1 2 3 4 5 } all-unique? ] unit-test + +[ { 1 2 3 } ] [ { 1 2 2 3 3 } { } set-like ] unit-test +[ { 3 2 1 } ] [ { 3 3 2 2 1 } { } set-like ] unit-test + +[ { 2 1 2 1 } ] [ { 1 2 3 2 1 2 1 } duplicates ] unit-test +[ f ] [ HS{ 1 2 3 1 2 1 } duplicates ] unit-test + +[ H{ { 3 HS{ 1 2 } } } ] [ H{ } clone 1 3 pick adjoin-at 2 3 pick adjoin-at ] unit-test diff --git a/core/sets/sets.factor b/core/sets/sets.factor index 38c1f73bb3..550b906b55 100644 --- a/core/sets/sets.factor +++ b/core/sets/sets.factor @@ -1,59 +1,112 @@ -! Copyright (C) 2008, 2009 Slava Pestov, Doug Coleman. +! Copyright (C) 2010 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. -USING: assocs hashtables kernel sequences vectors ; +USING: accessors assocs hashtables kernel vectors +math sequences ; IN: sets -: adjoin ( elt seq -- ) [ remove! drop ] [ push ] 2bi ; +! Set protocol +MIXIN: set +GENERIC: adjoin ( elt set -- ) +GENERIC: in? ( elt set -- ? ) +GENERIC: delete ( elt set -- ) +GENERIC: set-like ( set exemplar -- set' ) +GENERIC: fast-set ( set -- set' ) +GENERIC: members ( set -- sequence ) +GENERIC: union ( set1 set2 -- set ) +GENERIC: intersect ( set1 set2 -- set ) +GENERIC: intersects? ( set1 set2 -- ? ) +GENERIC: diff ( set1 set2 -- set ) +GENERIC: subset? ( set1 set2 -- ? ) +GENERIC: set= ( set1 set2 -- ? ) +GENERIC: duplicates ( set -- sequence ) +GENERIC: all-unique? ( set -- ? ) -: conjoin ( elt assoc -- ) dupd set-at ; +! Defaults for some methods. +! Override them for efficiency -: conjoin-at ( value key assoc -- ) - [ dupd ?set-at ] change-at ; - -: (prune) ( elt hash vec -- ) - 3dup drop key? [ 3drop ] [ - [ drop conjoin ] [ nip push ] 3bi - ] if ; inline - -: prune ( seq -- newseq ) - [ ] [ length ] [ length ] tri - [ [ (prune) ] 2curry each ] keep ; - -: duplicates ( seq -- newseq ) - H{ } clone [ [ key? ] [ conjoin ] 2bi ] curry filter ; - -: gather ( seq quot -- newseq ) - map concat prune ; inline - -: unique ( seq -- assoc ) - [ dup ] H{ } map>assoc ; - -: (all-unique?) ( elt hash -- ? ) - 2dup key? [ 2drop f ] [ conjoin t ] if ; - -: all-unique? ( seq -- ? ) - dup length [ (all-unique?) ] curry all? ; +M: set union + [ [ members ] bi@ append ] keep set-like ; -: intersect ( seq1 seq2 -- newseq ) - tester filter ; +M: set intersect + [ sequence/tester filter ] keep set-like ; -: intersects? ( seq1 seq2 -- ? ) - tester any? ; +M: set diff + [ sequence/tester [ not ] compose filter ] keep set-like ; -: diff ( seq1 seq2 -- newseq ) - tester [ not ] compose filter ; +M: set intersects? + sequence/tester any? ; -: union ( seq1 seq2 -- newseq ) - append prune ; +M: set subset? + sequence/tester all? ; + +M: set set= + 2dup subset? [ swap subset? ] [ 2drop f ] if ; -: subset? ( seq1 seq2 -- ? ) - tester all? ; +M: set fast-set ; -: set= ( seq1 seq2 -- ? ) - [ unique ] bi@ = ; +M: set duplicates drop f ; + +M: set all-unique? drop t ; + + ] bi + [ [ (pruned) ] 2curry each ] keep ; + +PRIVATE> + +! Sequences are sets +INSTANCE: sequence set + +M: sequence in? + member? ; inline + +M: sequence adjoin + [ delete ] [ push ] 2bi ; + +M: sequence delete + remove! drop ; inline + +M: sequence set-like + [ members ] dip like ; + +M: sequence members + [ pruned ] keep like ; + +M: sequence all-unique? + dup pruned sequence= ; + +: combine ( sets -- set ) + f [ union ] reduce ; + +: gather ( seq quot -- newseq ) + map concat members ; inline + +: adjoin-at ( value key assoc -- ) + [ [ f fast-set ] unless* [ adjoin ] keep ] change-at ; + +! Temporarily for compatibility + +ALIAS: prune members +: unique ( seq -- assoc ) + [ dup ] H{ } map>assoc ; +: conjoin ( elt assoc -- ) + dupd set-at ; +: conjoin-at ( value key assoc -- ) + [ dupd ?set-at ] change-at ;