vocabs.parser: use hash-sets in search-vocab-names.

db4
John Benediktsson 2013-03-08 10:09:41 -08:00
parent 66165f3660
commit f2d0752403
1 changed files with 10 additions and 9 deletions

View File

@ -2,8 +2,9 @@
! Slava Pestov. ! Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs combinators compiler.units USING: accessors arrays assocs combinators compiler.units
continuations hashtables kernel math namespaces parser.notes continuations hash-sets hashtables kernel math namespaces
sequences sets sorting splitting vectors vocabs words ; parser.notes sequences sets sorting splitting vectors vocabs
words ;
IN: vocabs.parser IN: vocabs.parser
ERROR: no-word-error name ; ERROR: no-word-error name ;
@ -22,14 +23,14 @@ ERROR: no-word-error name ;
TUPLE: manifest TUPLE: manifest
current-vocab current-vocab
{ search-vocab-names hashtable } { search-vocab-names hash-set }
{ search-vocabs vector } { search-vocabs vector }
{ qualified-vocabs vector } { qualified-vocabs vector }
{ auto-used vector } ; { auto-used vector } ;
: <manifest> ( -- manifest ) : <manifest> ( -- manifest )
manifest new manifest new
H{ } clone >>search-vocab-names HS{ } clone >>search-vocab-names
V{ } clone >>search-vocabs V{ } clone >>search-vocabs
V{ } clone >>qualified-vocabs V{ } clone >>qualified-vocabs
V{ } clone >>auto-used ; V{ } clone >>auto-used ;
@ -104,14 +105,14 @@ TUPLE: no-current-vocab-error ;
[ set-current-vocab ] [ drop ] if ; [ set-current-vocab ] [ drop ] if ;
: using-vocab? ( vocab -- ? ) : using-vocab? ( vocab -- ? )
vocab-name manifest get search-vocab-names>> key? ; vocab-name manifest get search-vocab-names>> in? ;
: use-vocab ( vocab -- ) : use-vocab ( vocab -- )
dup using-vocab? dup using-vocab?
[ vocab-name "Already using ``" "'' vocabulary" surround note. ] [ [ vocab-name "Already using ``" "'' vocabulary" surround note. ] [
manifest get manifest get
[ [ load-vocab ] dip search-vocabs>> push ] [ [ load-vocab ] dip search-vocabs>> push ]
[ [ vocab-name ] dip search-vocab-names>> conjoin ] [ [ vocab-name ] dip search-vocab-names>> adjoin ]
2bi 2bi
] if ; ] if ;
@ -124,7 +125,7 @@ TUPLE: no-current-vocab-error ;
dup using-vocab? [ dup using-vocab? [
manifest get manifest get
[ [ load-vocab ] dip search-vocabs>> remove-eq! drop ] [ [ load-vocab ] dip search-vocabs>> remove-eq! drop ]
[ [ vocab-name ] dip search-vocab-names>> delete-at ] [ [ vocab-name ] dip search-vocab-names>> delete ]
2bi 2bi
] [ drop ] if ; ] [ drop ] if ;
@ -222,8 +223,8 @@ M: vocab update dup name>> lookup-vocab eq? ;
: update-manifest ( manifest -- ) : update-manifest ( manifest -- )
[ dup [ name>> lookup-vocab ] when ] change-current-vocab [ dup [ name>> lookup-vocab ] when ] change-current-vocab
[ [ drop lookup-vocab ] assoc-filter ] change-search-vocab-names [ members [ lookup-vocab ] filter dup fast-set ] change-search-vocab-names
dup search-vocab-names>> keys [ lookup-vocab ] V{ } map-as >>search-vocabs swap [ lookup-vocab ] V{ } map-as >>search-vocabs
qualified-vocabs>> [ update ] filter! drop ; qualified-vocabs>> [ update ] filter! drop ;
M: manifest definitions-changed ( assoc manifest -- ) M: manifest definitions-changed ( assoc manifest -- )