: *T ( alien -- z )
[ T-real ] [ T-imaginary ] bi rect> ; inline
-T in get
+T current-vocab
{ { N "real" } { N "imaginary" } }
define-struct
scan scan typedef ;
SYNTAX: C-STRUCT:
- scan in get parse-definition define-struct ;
+ scan current-vocab parse-definition define-struct ;
SYNTAX: C-UNION:
scan parse-definition define-union ;
: ignore-cli-args? ( -- ? )
os macosx? "run" get "ui" = and ;
-: script-mode ( -- ) ;
-
[ default-cli-args ] "command-line" add-init-hook
} ;
: push-functor-words ( -- )
- functor-words use get push ;
+ functor-words use-words ;
: pop-functor-words ( -- )
- functor-words use get delq ;
+ functor-words unuse-words ;
: parse-functor-body ( -- form )
push-functor-words
] dip remember-definition ;
SYNTAX: ABOUT:
- in get vocab scan-object >>help changed-definition ;
+ current-vocab scan-object >>help changed-definition ;
<< {
{ [ os windows? ] [ "windows.winsock" ] }
{ [ os unix? ] [ "unix" ] }
-} cond add-ambiguous-use >>
+} cond use-vocab >>
! Addressing
GENERIC: protocol-family ( addrspec -- af )
] with-file-vocabs
[
- "debugger" add-use
+ "debugger" add-ambiguous-use
[ [ \ + 1 2 3 4 ] ]
[
GENERIC: stream-read-quot ( stream -- quot/f )
: parse-lines-interactive ( lines -- quot/f )
- [ parse-lines in get ] with-compilation-unit in set ;
+ [ parse-lines ] with-compilation-unit ;
: read-quot-step ( lines -- quot/f )
[ parse-lines-interactive ] [
] [ drop ] if ;
: prompt. ( -- )
- in get auto-use? get [ " - auto" append ] when "( " " )" surround
+ current-vocab name>> auto-use? get [ " - auto" append ] when "( " " )" surround
H{ { background T{ rgba f 1 0.7 0.7 1 } } } format bl flush ;
:: (listener) ( datastack -- )
[ <local-word> [ dup name>> set ] [ ] [ ] tri ] dip
"local-word-def" set-word-prop ;
-: push-locals ( assoc -- )
- use get push ;
-
-: pop-locals ( assoc -- )
- use get delq ;
-
SINGLETON: lambda-parser
SYMBOL: locals
'[
in-lambda? on
lambda-parser quotation-parser set
- [ locals set ] [ push-locals @ ] [ pop-locals ] tri
+ [ locals set ]
+ [ use-words @ ]
+ [ unuse-words ] tri
] with-scope ; inline
: (parse-lambda) ( assoc -- quot )
: parse-bindings* ( end -- words assoc )
[
- namespace push-locals
+ namespace use-words
(parse-bindings)
- namespace pop-locals
+ namespace unuse-words
] with-bindings ;
: parse-let* ( -- form )
{ [ os macosx? ] [ "opengl.gl.macosx" ] }
{ [ os unix? ] [ "opengl.gl.unix" ] }
[ unknown-gl-platform ]
-} cond add-use >>
+} cond use-vocab >>
SYMBOL: +gl-function-number-counter+
SYMBOL: +gl-function-pointers+
USING: destructors help.markup help.syntax kernel math multiline sequences
-vocabs vocabs.parser words ;
+vocabs vocabs.parser words namespaces ;
IN: ui.pixel-formats
! break circular dependency
<<
"ui.gadgets.worlds" create-vocab drop
"world" "ui.gadgets.worlds" create drop
- "ui.gadgets.worlds" (add-use)
+ "ui.gadgets.worlds" vocab-words use-words
>>
ARTICLE: "ui.pixel-formats-attributes" "Pixel format attributes"
[ thread>> dup [ thread-registered? ] when ]
} 1&& not ;
-SLOT: vocabs
+SLOT: manifest
-M: interactor vocabs>>
+M: interactor manifest>>
dup interactor-busy? [ drop f ] [
- use swap
interactor-continuation name>>
- assoc-stack
+ manifest swap assoc-stack
] if ;
: vocab-exists? ( name -- ? )
drop dup vocab-exists? [ >vocab-link ] [ drop f ] if ;
M: word-completion (word-at-caret)
- vocabs>> assoc-stack ;
+ manifest>> search-manifest ;
M: char-completion (word-at-caret)
2drop f ;
: clear-stack ( listener -- )
[ [ clear ] \ clear ] dip (call-listener) ;
-: use-if-necessary ( word seq -- )
+: use-if-necessary ( word manifest -- )
2dup [ vocabulary>> ] dip and [
- 2dup [ assoc-stack ] keep = [ 2drop ] [
- [ vocabulary>> vocab-words ] dip push
- ] if
+ manifest [
+ vocabulary>> use-vocab
+ ] with-variable
] [ 2drop ] if ;
M: word accept-completion-hook
- interactor>> vocabs>> use-if-necessary ;
+ interactor>> manifest>> use-if-necessary ;
M: object accept-completion-hook 2drop ;
M: word com-stack-effect 1quotation com-stack-effect ;
-: com-enter-in ( vocab -- ) vocab-name set-in ;
+: com-enter-in ( vocab -- ) vocab-name set-current-vocab ;
[ vocab? ] \ com-enter-in H{
{ +listener+ t }
} define-operation
-: com-use-vocab ( vocab -- ) vocab-name add-use ;
+: com-use-vocab ( vocab -- ) vocab-name use-vocab ;
[ vocab-spec? ] \ com-use-vocab H{
{ +secondary+ t }
-! Copyright (C) 2004, 2008 Slava Pestov.
+! Copyright (C) 2004, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: arrays debugger generic hashtables io assocs
-kernel.private kernel math memory namespaces make parser
-prettyprint sequences vectors words system splitting
-init io.files bootstrap.image bootstrap.image.private vocabs
-vocabs.loader system debugger continuations ;
+USING: arrays debugger generic hashtables io assocs kernel.private
+kernel math memory namespaces make parser prettyprint sequences
+vectors words system splitting init io.files vocabs vocabs.loader
+debugger continuations ;
+QUALIFIED: bootstrap.image.private
IN: bootstrap.stage1
"Bootstrap stage 1..." print flush
] if
] %
] [ ] make
-bootstrap-boot-quot set
+bootstrap.image.private:bootstrap-boot-quot set
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: parser words kernel classes compiler.units lexer ;
+USING: parser vocabs.parser words kernel classes compiler.units lexer ;
IN: classes.parser
: save-class-location ( class -- )
! Copyright (C) 2004, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: continuations continuations.private kernel
-kernel.private sequences assocs namespaces namespaces.private
-continuations continuations.private ;
+kernel.private sequences assocs namespaces namespaces.private ;
IN: init
SYMBOL: init-hooks
! Copyright (C) 2007, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: init kernel system namespaces io io.encodings
-io.encodings.utf8 init assocs splitting alien ;
+io.encodings.utf8 assocs splitting alien ;
IN: io.backend
SYMBOL: io-backend
M: parsing-word stack-effect drop (( parsed -- parsed )) ;
-TUPLE: no-current-vocab ;
-
-: no-current-vocab ( -- vocab )
- \ no-current-vocab boa
- { { "Define words in scratchpad vocabulary" "scratchpad" } }
- throw-restarts dup set-in ;
-
-: current-vocab ( -- str )
- in get [ no-current-vocab ] unless* ;
-
: create-in ( str -- word )
current-vocab create dup set-word dup save-location ;
: no-word-restarted ( restart-value -- word )
dup word? [
dup vocabulary>>
- [ (add-use) ]
+ [ use-vocab ]
[ amended-use get dup [ push ] [ 2drop ] if ]
[ "Added \"" "\" vocabulary to search path" surround note. ]
tri
: with-file-vocabs ( quot -- )
[
- f in set { "syntax" } set-use
- bootstrap-syntax get [ use get push ] when*
+ <manifest> manifest set
+ "syntax" use-vocab
+ bootstrap-syntax get [ use-words ] when*
call
] with-scope ; inline
: with-interactive-vocabs ( quot -- )
[
- "scratchpad" in set
- interactive-vocabs get set-use
+ <manifest> manifest set
+ "scratchpad" set-current-vocab
+ interactive-vocabs get only-use-vocabs
call
] with-scope ; inline
! Copyright (C) 2004, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel math strings sequences.private sequences
+USING: accessors kernel math sequences.private sequences
strings growable strings.private ;
IN: sbufs
[ [ 2unclip-slice ] dip [ call ] keep ] dip
compose 2reduce ; inline
-: map-find ( seq quot -- result elt )
- [ f ] 2dip
- [ [ nip ] dip call dup ] curry find
+<PRIVATE
+
+: (map-find) ( seq quot find-quot -- result elt )
+ [ [ f ] 2dip [ [ nip ] dip call dup ] curry ] dip call
[ [ drop f ] unless ] dip ; inline
+PRIVATE>
+
+: map-find ( seq quot -- result elt )
+ [ find ] (map-find) ; inline
+
+: map-find-last ( seq quot -- result elt )
+ [ find-last ] (map-find) ; inline
+
: unclip-last-slice ( seq -- butlast-slice last )
[ but-last-slice ] [ peek ] bi ; inline
! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays byte-arrays kernel kernel.private math namespaces
-make sequences strings words effects generic generic.standard
+make sequences strings effects generic generic.standard
classes classes.algebra slots.private combinators accessors
words sequences.private assocs alien quotations hashtables ;
IN: slots
-! Copyright (C) 2005, 2008 Slava Pestov.
+! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays kernel math sequences vectors math.order
-sequences sequences.private math.order ;
+USING: accessors arrays kernel math vectors math.order
+sequences sequences.private ;
IN: sorting
! Optimized merge-sort:
"#!" [ POSTPONE: ! ] define-core-syntax
- "IN:" [ scan set-in ] define-core-syntax
+ "IN:" [ scan set-current-vocab ] define-core-syntax
- "PRIVATE>" [ in get ".private" ?tail drop set-in ] define-core-syntax
+ "<PRIVATE" [ begin-private ] define-core-syntax
- "<PRIVATE" [
- POSTPONE: PRIVATE> in get ".private" append set-in
- ] define-core-syntax
+ "PRIVATE>" [ end-private ] define-core-syntax
- "USE:" [ scan add-use ] define-core-syntax
+ "USE:" [ scan use-vocab ] define-core-syntax
- "USING:" [ ";" parse-tokens [ add-use ] each ] define-core-syntax
+ "USING:" [ ";" parse-tokens [ use-vocab ] each ] define-core-syntax
"QUALIFIED:" [ scan dup add-qualified ] define-core-syntax
"QUALIFIED-WITH:" [ scan scan add-qualified ] define-core-syntax
"FROM:" [
- scan "=>" expect ";" parse-tokens swap add-words-from
+ scan "=>" expect ";" parse-tokens add-words-from
] define-core-syntax
"EXCLUDE:" [
- scan "=>" expect ";" parse-tokens swap add-words-excluding
+ scan "=>" expect ";" parse-tokens add-words-excluding
] define-core-syntax
"RENAME:" [
"))" parse-effect parsed
] define-core-syntax
- "MAIN:" [ scan-word in get vocab (>>main) ] define-core-syntax
+ "MAIN:" [ scan-word current-vocab (>>main) ] define-core-syntax
"<<" [
[
! Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: assocs hashtables kernel namespaces sequences
-sets strings vocabs sorting accessors arrays compiler.units ;
+sets strings vocabs sorting accessors arrays compiler.units
+combinators vectors splitting continuations ;
IN: vocabs.parser
ERROR: no-word-error name ;
-: word-restarts ( name possibilities -- restarts )
- natural-sort
- [ [ vocabulary>> "Use the " " vocabulary" surround ] keep ] { } map>assoc
- swap "Defer word in current vocabulary" swap 2array
- suffix ;
+TUPLE: manifest
+current-vocab
+{ search-vocabs vector }
+{ qualified-vocabs vector }
+{ extra-words vector } ;
-: <no-word-error> ( name possibilities -- error restarts )
- [ drop \ no-word-error boa ] [ word-restarts ] 2bi ;
+: <manifest> ( -- manifest )
+ manifest new
+ V{ } clone >>search-vocabs
+ V{ } clone >>qualified-vocabs
+ V{ } clone >>extra-words ;
-SYMBOL: use
-SYMBOL: in
+M: manifest clone
+ call-next-method
+ [ clone ] change-search-vocabs
+ [ clone ] change-qualified-vocabs
+ [ clone ] change-extra-words ;
-: (add-use) ( vocab -- )
- vocab-words use get push ;
+<PRIVATE
-: add-use ( vocab -- )
- load-vocab (add-use) ;
+: clear-manifest ( -- )
+ manifest get
+ [ search-vocabs>> delete-all ]
+ [ qualified-vocabs>> delete-all ]
+ [ extra-words>> delete-all ]
+ tri ;
-: set-use ( seq -- )
- [ vocab-words ] V{ } map-as sift use set ;
+: (use-vocab) ( vocab -- vocab seq )
+ load-vocab manifest get search-vocabs>> ;
-: add-qualified ( vocab prefix -- )
- [ load-vocab vocab-words ] [ CHAR: : suffix ] bi*
+: (add-qualified) ( qualified -- )
+ manifest get qualified-vocabs>> push ;
+
+: (from) ( vocab words -- vocab words words' assoc )
+ 2dup swap load-vocab words>> ;
+
+: (use-words) ( assoc -- assoc seq )
+ manifest get extra-words>> ;
+
+: extract-words ( seq assoc -- assoc' )
+ extract-keys dup [ [ drop ] [ no-word-error ] if ] assoc-each ;
+
+: (lookup) ( name assoc -- word/f )
+ at dup forward-reference? [ drop f ] when ;
+
+PRIVATE>
+
+: set-current-vocab ( name -- )
+ create-vocab manifest get
+ [ (>>current-vocab) ]
+ [ [ words>> ] dip extra-words>> push ]
+ 2bi ;
+
+TUPLE: no-current-vocab ;
+
+: no-current-vocab ( -- vocab )
+ \ no-current-vocab boa
+ { { "Define words in scratchpad vocabulary" "scratchpad" } }
+ throw-restarts dup set-current-vocab ;
+
+: current-vocab ( -- vocab )
+ manifest get current-vocab>> [ no-current-vocab ] unless* ;
+
+: begin-private ( -- )
+ manifest get current-vocab>> vocab-name ".private" ?tail
+ [ drop ] [ ".private" append set-current-vocab ] if ;
+
+: end-private ( -- )
+ manifest get current-vocab>> vocab-name ".private" ?tail
+ [ set-current-vocab ] [ drop ] if ;
+
+: use-vocab ( vocab -- ) (use-vocab) push ;
+
+: unuse-vocab ( vocab -- ) (use-vocab) delq ;
+
+: only-use-vocabs ( vocabs -- )
+ clear-manifest
+ [ vocab ] V{ } map-as sift
+ manifest get search-vocabs>> push-all ;
+
+TUPLE: qualified vocab prefix words ;
+
+: <qualified> ( vocab prefix -- qualified )
+ 2dup
+ [ load-vocab words>> ] [ CHAR: : suffix ] bi*
[ swap [ prepend ] dip ] curry assoc-map
- use get push ;
+ qualified boa ;
-: words-named-in ( words assoc -- assoc' )
- [ dupd at [ no-word-error ] unless* ] curry { } map>assoc ;
+: add-qualified ( vocab prefix -- )
+ <qualified> (add-qualified) ;
+
+TUPLE: from vocab names words ;
+
+: <from> ( vocab words -- from )
+ (from) extract-words from boa ;
-: partial-vocab-including ( words vocab -- assoc )
- load-vocab vocab-words words-named-in ;
+: add-words-from ( vocab words -- )
+ <from> (add-qualified) ;
-: add-words-from ( words vocab -- )
- partial-vocab-including use get push ;
+TUPLE: exclude vocab names words ;
-: partial-vocab-excluding ( words vocab -- assoc )
- load-vocab vocab-words [ nip ] [ words-named-in ] 2bi assoc-diff ;
+: <exclude> ( vocab words -- from )
+ (from) [ nip ] [ extract-words ] 2bi assoc-diff exclude boa ;
-: add-words-excluding ( words vocab -- )
- partial-vocab-excluding use get push ;
+: add-words-excluding ( vocab words -- )
+ <exclude> (add-qualified) ;
+
+TUPLE: rename word vocab words ;
+
+: <rename> ( word vocab new-name -- rename )
+ [ 2dup load-vocab words>> dupd at [ ] [ no-word-error ] ?if ] dip
+ associate rename boa ;
: add-renamed-word ( word vocab new-name -- )
- [ load-vocab vocab-words dupd at [ ] [ no-word-error ] ?if ] dip
- associate use get push ;
-
-: check-vocab-string ( name -- name )
- dup string? [ "Vocabulary name must be a string" throw ] unless ;
-
-: set-in ( name -- )
- check-vocab-string dup in set create-vocab (add-use) ;
-
-: check-forward ( str word -- word/f )
- dup forward-reference? [
- drop
- use get
- [ at ] with map sift
- [ forward-reference? not ] find-last nip
- ] [
- nip
+ <rename> (add-qualified) ;
+
+: use-words ( words -- ) (use-words) push ;
+
+: unuse-words ( words -- ) (use-words) delq ;
+
+ERROR: ambiguous-use-error words ;
+
+<PRIVATE
+
+: (vocab-search) ( name assocs -- words n )
+ [ words>> (lookup) ] with map
+ sift dup length ;
+
+: vocab-search ( name manifest -- word/f )
+ search-vocabs>>
+ (vocab-search) {
+ { 0 [ drop f ] }
+ { 1 [ first ] }
+ [ drop ambiguous-use-error ]
+ } case ;
+
+: qualified-search ( name manifest -- word/f )
+ qualified-vocabs>>
+ (vocab-search) 0 = [ drop f ] [ peek ] if ;
+
+: word-search ( name manifest -- word/f )
+ extra-words>> [ (lookup) ] with map-find-last drop ;
+
+PRIVATE>
+
+: search-manifest ( name manifest -- word/f )
+ 2dup word-search dup [ 2nip ] [
+ drop 2dup qualified-search dup [ 2nip ] [
+ drop vocab-search
+ ] if
] if ;
-: search ( str -- word/f )
- dup use get assoc-stack check-forward ;
\ No newline at end of file
+: search ( name -- word/f )
+ manifest get search-manifest ;
+
+: word-restarts ( name possibilities -- restarts )
+ natural-sort
+ [ [ vocabulary>> "Use the " " vocabulary" surround ] keep ] { } map>assoc
+ swap "Defer word in current vocabulary" swap 2array
+ suffix ;
+
+: <no-word-error> ( name possibilities -- error restarts )
+ [ drop \ no-word-error boa ] [ word-restarts ] 2bi ;
: notify-vocab-observers ( -- )
vocab-observers get [ vocabs-changed ] each ;
+ERROR: bad-vocab-name name ;
+
+: check-vocab-name ( name -- name )
+ dup string? [ bad-vocab-name ] unless ;
+
: create-vocab ( name -- vocab )
+ check-vocab-name
dictionary get [ <vocab> ] cache
notify-vocab-observers ;
! Copyright (C) 2004, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays definitions graphs assocs kernel
-kernel.private kernel.private slots.private math namespaces sequences
+USING: accessors arrays definitions graphs kernel
+kernel.private slots.private math namespaces sequences
strings vectors sbufs quotations assocs hashtables sorting vocabs
math.order sets ;
IN: words
ERROR: bad-create name vocab ;
: check-create ( name vocab -- name vocab )
- 2dup [ string? ] both?
+ 2dup [ string? ] [ [ string? ] [ vocab? ] bi or ] bi* and
[ bad-create ] unless ;
: create ( name vocab -- word )
check-create 2dup lookup
- dup [ 2nip ] [ drop <word> dup reveal ] if ;
+ dup [ 2nip ] [ drop vocab-name <word> dup reveal ] if ;
: constructor-word ( name vocab -- word )
[ "<" ">" surround ] dip create ;
"infix]" [infix-parse parsed \ call parsed ;
<PRIVATE
+
: parse-infix-locals ( assoc end -- quot )
- [
- in-lambda? on
- [ dup [ locals set ] [ push-locals ] bi ] dip
- [infix-parse prepare-operand swap pop-locals
- ] with-scope ;
+ '[ _ [infix-parse prepare-operand ] ((parse-lambda)) ;
+
PRIVATE>
SYNTAX: [infix|