alien.structs alien.syntax cpu.architecture alien inspector
quotations assocs kernel.private threads continuations.private
libc combinators compiler.errors continuations layouts accessors
-init ;
+init sets ;
IN: alien.compiler
TUPLE: #alien-node < node return parameters abi ;
[ H{ } clone callbacks set-global ] "alien.compiler" add-init-hook
-: register-callback ( word -- ) dup callbacks get set-at ;
+: register-callback ( word -- ) callbacks get conjoin ;
M: alien-callback-error summary
drop "Words calling ``alien-callback'' must be compiled with the optimizing compiler." ;
ARTICLE: "assocs-mutation" "Storing keys and values in assocs"
"Utility operations built up from the " { $link "assocs-protocol" } ":"
{ $subsection delete-at* }
-{ $subsection delete-any }
{ $subsection rename-at }
{ $subsection change-at }
{ $subsection at+ }
{ $description "Removes an entry from the assoc and outputs the previous value together with a boolean indicating whether it was present." }
{ $side-effects "assoc" } ;
-HELP: delete-any
-{ $values { "assoc" assoc } { "key" "a key" } { "value" "a value" } }
-{ $description "Removes an undetermined entry from the assoc and outputs it." }
-{ $errors "Throws an error if the assoc is empty." }
-{ $notes "This word is useful when using an assoc as an unordered queue which requires constant-time membership tests. Entries are enqueued with " { $link set-at } " and dequeued with " { $link delete-any } "." } ;
-
HELP: rename-at
{ $values { "newkey" object } { "key" object } { "assoc" assoc } }
{ $description "Removes the values associated to " { $snippet "key" } " and re-adds it as " { $snippet "newkey" } ". Does nothing if the assoc does not contain " { $snippet "key" } "." }
: rename-at ( newkey key assoc -- )
tuck delete-at* [ -rot set-at ] [ 3drop ] if ;
-: delete-any ( assoc -- key value )
- [
- [ 2drop t ] assoc-find
- [ "Assoc is empty" throw ] unless over
- ] keep delete-at ;
-
: assoc-empty? ( assoc -- ? )
assoc-size zero? ;
: (define-class) ( word props -- )
>r
- dup reset-class
dup class? [ dup new-class ] unless
+ dup reset-class
dup deferred? [ dup define-symbol ] when
dup word-props
r> assoc-union over set-word-props
#! updated by transitivity; the mixins usages appear in
#! class-usages of the member, now that it's been added.
[ 2drop ] [
- [ [ suffix ] change-mixin-class ] 2keep drop
- dup new-class? [ update-classes/new ] [ update-classes ] if
+ [ [ suffix ] change-mixin-class ] 2keep
+ tuck [ new-class? ] either? [
+ update-classes/new
+ ] [
+ update-classes
+ ] if
] if-mixin-member? ;
: remove-mixin-instance ( class mixin -- )
inference.state generator debugger words compiler.units
continuations vocabs assocs alien.compiler dlists optimizer
definitions math compiler.errors threads graphs generic
-inference combinators ;
+inference combinators dequeues search-dequeues ;
IN: compiler
-: ripple-up ( word -- )
- compiled-usage [ drop queue-compile ] assoc-each ;
+SYMBOL: +failed+
+
+: ripple-up ( words -- )
+ dup "compiled-effect" word-prop +failed+ eq?
+ [ usage [ word? ] filter ] [ compiled-usage keys ] if
+ [ queue-compile ] each ;
+
+: ripple-up? ( word effect -- ? )
+ #! If the word has previously been compiled and had a
+ #! different stack effect, we have to recompile any callers.
+ swap "compiled-effect" word-prop [ = not ] keep and ;
: save-effect ( word effect -- )
- [
- over "compiled-effect" word-prop = [
- dup "compiled-uses" word-prop
- [ dup ripple-up ] when
- ] unless drop
- ]
- [ "compiled-effect" set-word-prop ] 2bi ;
+ [ dupd ripple-up? [ ripple-up ] [ drop ] if ]
+ [ "compiled-effect" set-word-prop ]
+ 2bi ;
: compile-begins ( word -- )
f swap compiler-error ;
[ swap compiler-error ]
[
drop
+ [ compiled-unxref ]
[ f swap compiled get set-at ]
- [ f save-effect ]
- bi
+ [ +failed+ save-effect ]
+ tri
] 2bi ;
: compile-succeeded ( effect word -- )
] tri ;
: (compile) ( word -- )
+ dup dup "compile-count" word-prop 0 or 1 + "compile-count" set-word-prop
[
H{ } clone dependencies set
} cleave
] curry with-return ;
-: compile-loop ( assoc -- )
- dup assoc-empty? [ drop ] [
- dup delete-any drop (compile)
- yield
- compile-loop
- ] if ;
+: compile-loop ( dequeue -- )
+ [ (compile) yield ] slurp-dequeue ;
: decompile ( word -- )
f 2array 1array t modify-code-heap ;
: optimized-recompile-hook ( words -- alist )
[
- H{ } clone compile-queue set
+ <hashed-dlist> compile-queue set
H{ } clone compiled set
[ queue-compile ] each
compile-queue get compile-loop
--- /dev/null
+IN: compiler.tests
+USING: words kernel inference alien.strings tools.test ;
+
+[ ] [ \ if redefined [ string>alien ] infer. ] unit-test
+++ /dev/null
-IN: compiler.tests
-USING: compiler tools.test math parser ;
-
-GENERIC: method-redefine-test ( a -- b )
-
-M: integer method-redefine-test 3 + ;
-
-: method-redefine-test-1 ( -- b ) 3 method-redefine-test ;
-
-[ 6 ] [ method-redefine-test-1 ] unit-test
-
-[ ] [ "IN: compiler.tests USE: math M: fixnum method-redefine-test 4 + ;" eval ] unit-test
-
-[ 7 ] [ method-redefine-test-1 ] unit-test
--- /dev/null
+IN: compiler.tests
+USING: compiler compiler.units tools.test math parser kernel
+sequences sequences.private classes.mixin generic definitions
+arrays words assocs ;
+
+GENERIC: method-redefine-test ( a -- b )
+
+M: integer method-redefine-test 3 + ;
+
+: method-redefine-test-1 ( -- b ) 3 method-redefine-test ;
+
+[ 6 ] [ method-redefine-test-1 ] unit-test
+
+[ ] [ "IN: compiler.tests USE: math M: fixnum method-redefine-test 4 + ;" eval ] unit-test
+
+[ 7 ] [ method-redefine-test-1 ] unit-test
+
+[ ] [ [ fixnum \ method-redefine-test method forget ] with-compilation-unit ] unit-test
+
+[ 6 ] [ method-redefine-test-1 ] unit-test
+
+! Test ripple-up behavior
+: hey ( -- ) ;
+: there ( -- ) hey ;
+
+[ t ] [ \ hey compiled? ] unit-test
+[ t ] [ \ there compiled? ] unit-test
+[ ] [ "IN: compiler.tests : hey ( -- ) 3 ;" eval ] unit-test
+[ f ] [ \ hey compiled? ] unit-test
+[ f ] [ \ there compiled? ] unit-test
+[ ] [ "IN: compiler.tests : hey ( -- ) ;" eval ] unit-test
+[ t ] [ \ there compiled? ] unit-test
+
+! Just changing the stack effect didn't mark a word for recompilation
+DEFER: change-effect
+
+[ ] [ "IN: compiler.tests GENERIC: change-effect ( a -- b )" eval ] unit-test
+{ 1 1 } [ change-effect ] must-infer-as
+
+[ ] [ "IN: compiler.tests GENERIC: change-effect ( a -- )" eval ] unit-test
+{ 1 0 } [ change-effect ] must-infer-as
+
+: good ( -- ) ;
+: bad ( -- ) good ;
+: ugly ( -- ) bad ;
+
+[ t ] [ \ good compiled? ] unit-test
+[ t ] [ \ bad compiled? ] unit-test
+[ t ] [ \ ugly compiled? ] unit-test
+
+[ f ] [ \ good compiled-usage assoc-empty? ] unit-test
+
+[ ] [ "IN: compiler.tests : good ( -- ) 3 ;" eval ] unit-test
+
+[ f ] [ \ good compiled? ] unit-test
+[ f ] [ \ bad compiled? ] unit-test
+[ f ] [ \ ugly compiled? ] unit-test
+
+[ t ] [ \ good compiled-usage assoc-empty? ] unit-test
+
+[ ] [ "IN: compiler.tests : good ( -- ) ;" eval ] unit-test
+
+[ t ] [ \ good compiled? ] unit-test
+[ t ] [ \ bad compiled? ] unit-test
+[ t ] [ \ ugly compiled? ] unit-test
+
+[ f ] [ \ good compiled-usage assoc-empty? ] unit-test
--- /dev/null
+IN: compiler.tests
+USING: compiler compiler.units tools.test math parser kernel
+sequences sequences.private classes.mixin generic definitions
+arrays words assocs ;
+
+DEFER: blah
+
+[ ] [ "USE: sequences USE: kernel IN: compiler.tests TUPLE: blah ; M: blah nth 2drop 3 ; INSTANCE: blah sequence" eval ] unit-test
+
+[ t ] [ blah new sequence? ] unit-test
+
+[ 3 ] [ 0 blah new nth-unsafe ] unit-test
+
+[ ] [ [ blah sequence remove-mixin-instance ] with-compilation-unit ] unit-test
+
+[ f ] [ blah new sequence? ] unit-test
+
+[ 0 blah new nth-unsafe ] must-fail
--- /dev/null
+IN: compiler.tests
+USING: compiler compiler.units tools.test math parser kernel
+sequences sequences.private classes.mixin generic definitions
+arrays words assocs ;
+
+GENERIC: sheeple ( obj -- x )
+
+M: object sheeple drop "sheeple" ;
+
+MIXIN: empty-mixin
+
+M: empty-mixin sheeple drop "wake up" ;
+
+: sheeple-test ( -- string ) { } sheeple ;
+
+[ "sheeple" ] [ sheeple-test ] unit-test
+[ t ] [ \ sheeple-test compiled? ] unit-test
+[ t ] [ object \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test
+[ f ] [ empty-mixin \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test
+
+[ ] [ "IN: compiler.tests USE: arrays INSTANCE: array empty-mixin" eval ] unit-test
+
+[ "wake up" ] [ sheeple-test ] unit-test
+[ f ] [ object \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test
+[ t ] [ empty-mixin \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test
+
+[ ] [ [ array empty-mixin remove-mixin-instance ] with-compilation-unit ] unit-test
+
+[ "sheeple" ] [ sheeple-test ] unit-test
+[ t ] [ \ sheeple-test compiled? ] unit-test
+[ t ] [ object \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test
+[ f ] [ empty-mixin \ sheeple method \ sheeple-test "compiled-uses" word-prop key? ] unit-test
--- /dev/null
+IN: compiler.tests
+USE: vocabs.loader
+
+"parser" reload
+"sequences" reload
+"kernel" reload
: call-update-tuples-hook ( -- )
update-tuples-hook get call ;
+: unxref-forgotten-definitions ( -- )
+ forgotten-definitions get
+ keys [ word? ] filter
+ [ delete-compiled-xref ] each ;
+
: finish-compilation-unit ( -- )
call-recompile-hook
call-update-tuples-hook
+ unxref-forgotten-definitions
dup [ drop crossref? ] assoc-contains? modify-code-heap ;
: with-nested-compilation-unit ( quot -- )
-! Copyright (C) 2004, 2008 Slava Pestov.
+ ! Copyright (C) 2004, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs classes combinators cpu.architecture
effects generator.fixup generator.registers generic hashtables
inference inference.backend inference.dataflow io kernel
kernel.private layouts math namespaces optimizer
optimizer.specializers prettyprint quotations sequences system
-threads words vectors ;
+threads words vectors sets dequeues ;
IN: generator
SYMBOL: compile-queue
{ [ dup compiled get key? ] [ drop ] }
{ [ dup inlined-block? ] [ drop ] }
{ [ dup primitive? ] [ drop ] }
- [ dup compile-queue get set-at ]
+ [ compile-queue get push-front ]
} cond ;
: maybe-compile ( word -- )
: affected-methods ( class generic -- seq )
"methods" word-prop swap
- [ nip classes-intersect? ] curry assoc-filter
+ [ nip [ classes-intersect? ] [ class<= ] 2bi or ] curry assoc-filter
values ;
: update-generic ( class generic -- )
- [ affected-methods [ +called+ changed-definition ] each ]
- [ make-generic ]
- bi ;
+ affected-methods [ +called+ changed-definition ] each ;
: with-methods ( class generic quot -- )
+ [ drop update-generic ]
[ [ "methods" word-prop ] dip call ]
- [ drop update-generic ] 3bi ;
- inline
+ [ drop make-generic drop ]
+ 3tri ; inline
: method-word-name ( class word -- string )
word-name "/" rot word-name 3append ;
"method-generic" word-prop stack-effect ;
M: method-body crossref?
- drop t ;
+ "forgotten" word-prop not ;
: method-word-props ( class generic -- assoc )
[
] if ;
: <default-method> ( generic combination -- method )
- object bootstrap-word pick <method>
- [ -rot make-default-method define ] keep ;
+ [ drop object bootstrap-word swap <method> ] [ make-default-method ] 2bi
+ [ define ] [ drop t "default" set-word-prop ] [ drop ] 2tri ;
: define-default-method ( generic combination -- )
dupd <default-method> "default-method" set-word-prop ;
M: method-body forget*
dup "forgotten" word-prop [ drop ] [
[
- [ ]
- [ "method-class" word-prop ]
- [ "method-generic" word-prop ] tri
- 3dup method eq? [
- [ delete-at ] with-methods
- call-next-method
- ] [ 3drop ] if
+ dup "default" word-prop [ call-next-method ] [
+ dup
+ [ "method-class" word-prop ]
+ [ "method-generic" word-prop ] bi
+ 3dup method eq? [
+ [ delete-at ] with-methods
+ call-next-method
+ ] [ 3drop ] if
+ ] if
]
[ t "forgotten" set-word-prop ] bi
] if ;
[ call-next-method ] bi ;
M: assoc update-methods ( class assoc -- )
- implementors [ update-generic ] with each ;
+ implementors [
+ [ update-generic ]
+ [ make-generic drop ] 2bi
+ ] with each ;
: define-generic ( word combination -- )
over "combination" word-prop over = [
[ extra-values ] [ stack-effect ] bi
dup [ clone [ length + ] change-in ] [ 2drop f ] if ;
-M: engine-word crossref? drop t ;
+M: engine-word crossref? "forgotten" word-prop not ;
M: engine-word irrelevant? drop t ;
! Copyright (C) 2006, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: assocs kernel namespaces sequences ;
+USING: assocs kernel namespaces sequences sets ;
IN: graphs
SYMBOL: graph
over previous get key? [
2drop
] [
- over dup previous get set-at
+ over previous get conjoin
dup slip
[ nip (closure) ] curry assoc-each
] if ; inline
io.streams.string kernel math namespaces parser prettyprint
sequences strings vectors words quotations effects classes
continuations debugger assocs combinators compiler.errors
-generic.standard.engines.tuple accessors math.order definitions ;
+generic.standard.engines.tuple accessors math.order definitions
+sets ;
IN: inference.backend
: recursive-label ( word -- label/f )
: (redefined) ( word -- )
dup visited get key? [ drop ] [
[ reset-on-redefine reset-props ]
- [ dup visited get set-at ]
+ [ visited get conjoin ]
[
crossref get at keys
[ word? ] filter
[ [ erg's-inference-bug ] infer ] must-fail
-! : inference-invalidation-a ( -- );
-! : inference-invalidation-b ( quot -- ) [ inference-invalidation-a ] dip call ; inline
-! : inference-invalidation-c ( a b -- c ) [ + ] inference-invalidation-b ;
-!
-! [ 7 ] [ 4 3 inference-invalidation-c ] unit-test
-!
-! { 2 1 } [ [ + ] inference-invalidation-b ] must-infer-as
-!
-! [ ] [ "IN: inference.tests : inference-invalidation-a 1 2 ;" eval ] unit-test
-!
-! [ 3 ] [ inference-invalidation-c ] unit-test
-!
-! { 0 1 } [ inference-invalidation-c ] must-infer-as
-!
-! GENERIC: inference-invalidation-d ( obj -- )
-!
-! M: object inference-invalidation-d inference-invalidation-c 2drop ;
-!
-! \ inference-invalidation-d must-infer
-!
-! [ ] [ "IN: inference.tests : inference-invalidation-a ;" eval ] unit-test
-!
-! [ [ inference-invalidation-d ] infer ] must-fail
+: inference-invalidation-a ( -- ) ;
+: inference-invalidation-b ( quot -- ) [ inference-invalidation-a ] dip call ; inline
+: inference-invalidation-c ( a b -- c ) [ + ] inference-invalidation-b ; inline
+
+[ 7 ] [ 4 3 inference-invalidation-c ] unit-test
+
+{ 2 1 } [ [ + ] inference-invalidation-b ] must-infer-as
+
+[ ] [ "IN: inference.tests : inference-invalidation-a ( -- a b ) 1 2 ;" eval ] unit-test
+
+[ 3 ] [ inference-invalidation-c ] unit-test
+
+{ 0 1 } [ inference-invalidation-c ] must-infer-as
+
+GENERIC: inference-invalidation-d ( obj -- )
+
+M: object inference-invalidation-d inference-invalidation-c 2drop ;
+
+\ inference-invalidation-d must-infer
+
+[ ] [ "IN: inference.tests : inference-invalidation-a ( -- ) ;" eval ] unit-test
+
+[ [ inference-invalidation-d ] infer ] must-fail
GENERIC: infer ( quot -- effect )
M: callable infer ( quot -- effect )
- [ f infer-quot ] with-infer drop ;
+ [ recursive-state get infer-quot ] with-infer drop ;
: infer. ( quot -- )
+ #! Safe to call from inference transforms.
infer effect>string print ;
GENERIC: dataflow ( quot -- dataflow )
M: callable dataflow
+ #! Not safe to call from inference transforms.
[ f infer-quot ] with-infer nip ;
GENERIC# dataflow-with 1 ( quot stack -- dataflow )
M: callable dataflow-with
+ #! Not safe to call from inference transforms.
[
V{ } like meta-d set
f infer-quot
! Copyright (C) 2007, 2008 Doug Coleman
! See http://factorcode.org/license.txt for BSD license.
USING: alien assocs continuations destructors init kernel
-namespaces accessors ;
+namespaces accessors sets ;
IN: libc
<PRIVATE
[ H{ } clone mallocs set-global ] "libc" add-init-hook
: add-malloc ( alien -- )
- dup mallocs get-global set-at ;
+ mallocs get-global conjoin ;
: delete-malloc ( alien -- )
[
] unit-test
] times
-[ ] [ "parser" reload ] unit-test
-
[ ] [
[ "this-better-not-exist" forget-vocab ] with-compilation-unit
] unit-test
USING: arrays generic hashtables io kernel math assocs
namespaces sequences strings io.styles vectors words
prettyprint.config splitting classes continuations
-io.streams.nested accessors ;
+io.streams.nested accessors sets ;
IN: prettyprint.sections
! State
: <pprinter> ( -- pprinter ) 0 1 0 pprinter boa ;
: record-vocab ( word -- )
- word-vocabulary [ dup pprinter-use get set-at ] when* ;
+ word-vocabulary [ pprinter-use get conjoin ] when* ;
! Utility words
: line-limit? ( -- ? )
--- /dev/null
+Slava Pestov
"Default implementation:"
{ $subsection <hashed-dlist> } ;
+ABOUT: "search-dequeues"
+
HELP: <search-dequeue> ( assoc dequeue -- search-dequeue )
{ $values { "assoc" assoc } { "dequeue" dequeue } { "search-dequeue" search-dequeue } }
{ $description "Creates a new " { $link search-dequeue } "." } ;
--- /dev/null
+Double-ended queues with sub-linear membership testing
--- /dev/null
+collections
[ "asdf" ] [ " asdf " [ CHAR: \s = ] trim ] unit-test
[ "asdf " ] [ " asdf " [ CHAR: \s = ] left-trim ] unit-test
[ " asdf" ] [ " asdf " [ CHAR: \s = ] right-trim ] unit-test
-
-! Hardcore
-[ ] [ "sequences" reload ] unit-test
] define-syntax
"(" [
- ")" parse-effect word
- [ swap "declared-effect" set-word-prop ] [ drop ] if*
+ ")" parse-effect
+ word dup [
+ swap
+ [ "declared-effect" set-word-prop ]
+ [ drop redefined ]
+ [ drop +inlined+ changed-definition ]
+ 2tri
+ ] [ 2drop ] if
] define-syntax
"((" [
USING: help.markup help.syntax kernel kernel.private io
threads.private continuations dlists init quotations strings
-assocs heaps boxes namespaces ;
+assocs heaps boxes namespaces dequeues ;
IN: threads
ARTICLE: "threads-start/stop" "Starting and stopping threads"
USING: arrays hashtables heaps kernel kernel.private math
namespaces sequences vectors continuations continuations.private
dlists assocs system combinators init boxes accessors
-math.order ;
+math.order dequeues ;
IN: threads
SYMBOL: initial-thread
: sleep-time ( -- ms/f )
{
- { [ run-queue dlist-empty? not ] [ 0 ] }
+ { [ run-queue dequeue-empty? not ] [ 0 ] }
{ [ sleep-queue heap-empty? ] [ f ] }
[ sleep-queue heap-peek nip millis [-] ]
} cond ;
: next ( -- * )
expire-sleep-loop
- run-queue dup dlist-empty? [
+ run-queue dup dequeue-empty? [
drop no-runnable-threads
] [
pop-back dup array? [ first2 ] [ f swap ] if (next)
[ t ] [ "decl-forget-test" "words.tests" lookup "flushable" word-prop ] unit-test
[ ] [ "IN: words.tests : decl-forget-test ;" eval ] unit-test
[ f ] [ "decl-forget-test" "words.tests" lookup "flushable" word-prop ] unit-test
+
+[ { } ]
+[
+ all-words [
+ "compiled-uses" word-prop
+ keys [ "forgotten" word-prop ] contains?
+ ] filter
+] unit-test
+
+[ { } ] [
+ crossref get keys
+ [ word? ] filter [ "forgotten" word-prop ] filter
+] unit-test
M: object (quot-uses) 2drop ;
-M: word (quot-uses)
- >r dup crossref? [ dup r> set-at ] [ r> 2drop ] if ;
+M: word (quot-uses) over crossref? [ conjoin ] [ 2drop ] if ;
: seq-uses ( seq assoc -- ) [ (quot-uses) ] curry each ;
: compiled-xref ( word dependencies -- )
[ drop crossref? ] assoc-filter
- 2dup "compiled-uses" set-word-prop
- compiled-crossref get add-vertex* ;
+ [ "compiled-uses" set-word-prop ]
+ [ compiled-crossref get add-vertex* ]
+ 2bi ;
: compiled-unxref ( word -- )
- dup "compiled-uses" word-prop
- compiled-crossref get remove-vertex* ;
+ [
+ dup "compiled-uses" word-prop
+ compiled-crossref get remove-vertex*
+ ]
+ [ f "compiled-uses" set-word-prop ] bi ;
: delete-compiled-xref ( word -- )
dup compiled-unxref
M: word subwords drop f ;
: reset-generic ( word -- )
- dup subwords forget-all
- dup reset-word
- { "methods" "combination" "default-method" } reset-props ;
+ [ subwords forget-all ]
+ [ reset-word ]
+ [ { "methods" "combination" "default-method" } reset-props ]
+ tri ;
: gensym ( -- word )
"( gensym )" f <word> ;
M: word set-where swap "loc" set-word-prop ;
M: word forget*
- dup "forgotten" word-prop [
- dup delete-xref
- dup delete-compiled-xref
- dup word-name over word-vocabulary vocab-words delete-at
- dup t "forgotten" set-word-prop
- ] unless drop ;
+ dup "forgotten" word-prop [ drop ] [
+ [ delete-xref ]
+ [ [ word-name ] [ word-vocabulary vocab-words ] bi delete-at ]
+ [ t "forgotten" set-word-prop ]
+ tri
+ ] if ;
M: word hashcode*
nip 1 slot { fixnum } declare ;
! Copyright (C) 2008 Slava Pestov.\r
! See http://factorcode.org/license.txt for BSD license.\r
-USING: dlists dlists.private threads kernel arrays sequences\r
-alarms ;\r
+USING: dequeues threads kernel arrays sequences alarms ;\r
IN: concurrency.conditions\r
\r
-: notify-1 ( dlist -- )\r
- dup dlist-empty? [ drop ] [ pop-back resume-now ] if ;\r
+: notify-1 ( dequeue -- )\r
+ dup dequeue-empty? [ drop ] [ pop-back resume-now ] if ;\r
\r
-: notify-all ( dlist -- )\r
- [ resume-now ] dlist-slurp ;\r
+: notify-all ( dequeue -- )\r
+ [ resume-now ] slurp-dequeue ;\r
\r
: queue-timeout ( queue timeout -- alarm )\r
#! Add an alarm which removes the current thread from the\r
#! queue, and resumes it, passing it a value of t.\r
- >r self over push-front* [\r
- tuck delete-node\r
- dlist-node-obj t swap resume-with\r
+ >r [ self swap push-front* ] keep [\r
+ [ delete-node ] [ drop node-value ] 2bi\r
+ t swap resume-with\r
] 2curry r> later ;\r
\r
: wait ( queue timeout status -- )\r
! Copyright (C) 2008 Slava Pestov.\r
! See http://factorcode.org/license.txt for BSD license.\r
-USING: dlists kernel threads continuations math\r
+USING: dequeues dlists kernel threads continuations math\r
concurrency.conditions ;\r
IN: concurrency.locks\r
\r
\r
: release-write-lock ( lock -- )\r
f over set-rw-lock-writer\r
- dup rw-lock-readers dlist-empty?\r
+ dup rw-lock-readers dequeue-empty?\r
[ notify-writer ] [ rw-lock-readers notify-all ] if ;\r
\r
: reentrant-read-lock-ok? ( lock -- ? )\r
! Copyright (C) 2005, 2008 Chris Double, Slava Pestov.\r
! See http://factorcode.org/license.txt for BSD license.\r
IN: concurrency.mailboxes\r
-USING: dlists threads sequences continuations destructors\r
-namespaces random math quotations words kernel arrays assocs\r
-init system concurrency.conditions accessors debugger ;\r
+USING: dlists dequeues threads sequences continuations\r
+destructors namespaces random math quotations words kernel\r
+arrays assocs init system concurrency.conditions accessors\r
+debugger ;\r
\r
TUPLE: mailbox threads data disposed ;\r
\r
<dlist> <dlist> f mailbox boa ;\r
\r
: mailbox-empty? ( mailbox -- bool )\r
- data>> dlist-empty? ;\r
+ data>> dequeue-empty? ;\r
\r
: mailbox-put ( obj mailbox -- )\r
[ data>> push-front ]\r
! See http://factorcode.org/license.txt for BSD license.
!
USING: kernel threads vectors arrays sequences
-namespaces tools.test continuations dlists strings math words
+namespaces tools.test continuations dequeues strings math words
match quotations concurrency.messaging concurrency.mailboxes
concurrency.count-downs accessors ;
IN: concurrency.messaging.tests
-[ ] [ my-mailbox mailbox-data dlist-delete-all ] unit-test
+[ ] [ my-mailbox mailbox-data clear-dequeue ] unit-test
[ "received" ] [
[
io.streams.string prettyprint definitions arrays vectors
combinators splitting debugger hashtables sorting effects vocabs
vocabs.loader assocs editors continuations classes.predicate
-macros combinators.lib sequences.lib math sets ;
+macros math sets ;
IN: help.lint
: check-example ( element -- )
: check-values ( word element -- )
{
- [ over "declared-effect" word-prop ]
- [ dup contains-funky-elements? not ]
- [ over macro? not ]
+ { [ over "declared-effect" word-prop ] [ 2drop ] }
+ { [ dup contains-funky-elements? not ] [ 2drop ] }
+ { [ over macro? not ] [ 2drop ] }
[
- 2dup extract-values >array
- >r effect-values >array
- r> assert=
- t
+ [ effect-values >array ]
+ [ extract-values >array ]
+ bi* assert=
]
- } 0&& 3drop ;
+ } cond ;
: check-see-also ( word element -- )
nip \ $see-also swap elements [
vocabs [ dup vocab-docs-path swap ] H{ } map>assoc
H{ } clone [
[
- >r >r dup >link where ?first r> at r> [ ?push ] change-at
+ >r >r dup >link where dup
+ [ first r> at r> [ ?push ] change-at ]
+ [ r> r> 2drop 2drop ]
+ if
] 2curry each
] keep ;
USING: io.files kernel sequences accessors
-dlists arrays sequences.lib ;
+dlists dequeues arrays sequences.lib ;
IN: io.paths
TUPLE: directory-iterator path bfs queue ;
dup path>> over push-directory ;
: next-file ( iter -- file/f )
- dup queue>> dlist-empty? [ drop f ] [
+ dup queue>> dequeue-empty? [ drop f ] [
dup queue>> pop-back first2
[ over push-directory next-file ] [ nip ] if
] if ;
words kernel arrays shuffle tools.annotations\r
prettyprint.config prettyprint debugger io.streams.string\r
splitting continuations effects arrays.lib parser strings\r
-combinators.lib quotations fry symbols accessors ;\r
+quotations fry symbols accessors ;\r
IN: logging\r
\r
SYMBOLS: DEBUG NOTICE WARNING ERROR CRITICAL ;\r
\r
<PRIVATE\r
\r
-: one-string? ( obj -- ? )\r
- {\r
- [ dup array? ]\r
- [ dup length 1 = ]\r
- [ dup first string? ]\r
- } 0&& nip ;\r
+PREDICATE: one-string-array < array\r
+ [ length 1 = ] [ [ string? ] all? ] bi and ;\r
\r
: stack>message ( obj -- inputs>message )\r
- dup one-string? [ first ] [\r
- H{\r
- { string-limit f }\r
- { line-limit 1 }\r
- { nesting-limit 3 }\r
- { margin 0 }\r
- } clone [ unparse ] bind\r
+ dup one-string-array? [ first ] [\r
+ [\r
+ string-limit off\r
+ 1 line-limit set\r
+ 3 nesting-limit set\r
+ 0 margin set\r
+ unparse\r
+ ] with-scope\r
] if ;\r
\r
PRIVATE>\r
{ $values { "..." "inputs to a macro" } { "word" macro } { "quot" quotation } }
{ $description "Expands a macro. Useful for debugging." }
{ $examples
- { $code "{ [ dup integer? ] [ dup 0 > ] [ dup 13 mod zero? ] } \ && macro-expand ." }
+ { $code "USING: math macros combinators.lib ;" "{ [ integer? ] [ 0 > ] [ 13 mod zero? ] } \ 1&& macro-expand ." }
} ;
ARTICLE: "macros" "Macros"
{ $subsection POSTPONE: MACRO: }
"Expanding macros for debugging purposes:"
{ $subsection macro-expand }
-! "Two sample macros which implement short-circuiting boolean operators (as found in C, Java and similar languages):"
-! { $subsection && }
-! { $subsection || }
"Macros are really just a very thin layer of syntax sugar over " { $link "compiler-transforms" } "." ;
ABOUT: "macros"
"USING: math ;\nIN: macros.tests\n: see-test ( a b -- c ) - ;\n" dup eval
[ \ see-test see ] with-string-writer =
] unit-test
+
+[ ] [ "USING: macros inference kernel ; IN: hanging-macro MACRO: c ( quot -- ) infer drop [ ] ; : a ( -- ) [ a ] c ;" eval ] unit-test
+
"multi-method-generic" word-prop stack-effect ;
M: method-body crossref?
- drop t ;
+ "forgotten" word-prop not ;
: method-word-name ( specializer generic -- string )
[ word-name % "-" % unparse % ] "" make ;
--- /dev/null
+collections
--- /dev/null
+collections
--- /dev/null
+collections
USING: tools.test kernel serialize io io.streams.byte-array math
alien arrays byte-arrays sequences math prettyprint parser
classes math.constants io.encodings.binary random
-combinators.lib assocs ;
+assocs ;
IN: serialize.tests
: test-serialize-cell
[ t ] [
100 [
drop
- {
- [ 40 [ test-serialize-cell ] all? ]
- [ 4 [ 40 * test-serialize-cell ] all? ]
- [ 4 [ 400 * test-serialize-cell ] all? ]
- [ 4 [ 4000 * test-serialize-cell ] all? ]
- } &&
+ 40 [ test-serialize-cell ] all?
+ 4 [ 40 * test-serialize-cell ] all?
+ 4 [ 400 * test-serialize-cell ] all?
+ 4 [ 4000 * test-serialize-cell ] all?
+ and and and
] all?
] unit-test
USING: kernel threads threads.private ;
IN: debugger
-: print-error die ;
+: print-error ( error -- ) die drop ;
-: error. die ;
+: error. ( error -- ) die drop ;
M: thread error-in-thread ( error thread -- ) die 2drop ;
USING: libc.private ;
IN: libc
-: malloc (malloc) check-ptr ;
+: malloc ( size -- newalien ) (malloc) check-ptr ;
-: realloc (realloc) check-ptr ;
+: realloc ( alien size -- newalien ) (realloc) check-ptr ;
-: calloc (calloc) check-ptr ;
+: calloc ( size count -- newalien ) (calloc) check-ptr ;
-: free (free) ;
+: free ( alien -- ) (free) ;
IN: ui.gadgets.tests
USING: ui.gadgets ui.gadgets.packs ui.gadgets.worlds tools.test
-namespaces models kernel dlists math sets
+namespaces models kernel dlists dequeues math sets
math.parser ui sequences hashtables assocs io arrays
prettyprint io.streams.string ;
[
<dlist> \ graft-queue [
[ ] [ <mock-gadget> dup queue-graft unqueue-graft ] unit-test
- [ t ] [ graft-queue dlist-empty? ] unit-test
+ [ t ] [ graft-queue dequeue-empty? ] unit-test
] with-variable
<dlist> \ graft-queue [
- [ t ] [ graft-queue dlist-empty? ] unit-test
+ [ t ] [ graft-queue dequeue-empty? ] unit-test
<mock-gadget> "g" set
[ ] [ "g" get queue-graft ] unit-test
- [ f ] [ graft-queue dlist-empty? ] unit-test
+ [ f ] [ graft-queue dequeue-empty? ] unit-test
[ { f t } ] [ "g" get gadget-graft-state ] unit-test
[ ] [ "g" get graft-later ] unit-test
[ { f t } ] [ "g" get gadget-graft-state ] unit-test
[ ] [ "g" get ungraft-later ] unit-test
[ { f f } ] [ "g" get gadget-graft-state ] unit-test
- [ t ] [ graft-queue dlist-empty? ] unit-test
+ [ t ] [ graft-queue dequeue-empty? ] unit-test
[ ] [ "g" get ungraft-later ] unit-test
[ ] [ "g" get graft-later ] unit-test
[ ] [ notify-queued ] unit-test
[ { t t } ] [ "g" get gadget-graft-state ] unit-test
- [ t ] [ graft-queue dlist-empty? ] unit-test
+ [ t ] [ graft-queue dequeue-empty? ] unit-test
[ ] [ "g" get graft-later ] unit-test
[ 1 ] [ "g" get mock-gadget-graft-called ] unit-test
[ ] [ "g" get ungraft-later ] unit-test
[ { f t } ] [ "1" get gadget-graft-state ] unit-test
[ { f t } ] [ "2" get gadget-graft-state ] unit-test
[ { f t } ] [ "3" get gadget-graft-state ] unit-test
- [ ] [ [ "x" print notify ] graft-queue swap dlist-slurp ] unit-test
+ [ ] [ graft-queue [ "x" print notify ] slurp-dequeue ] unit-test
[ ] [ notify-queued ] unit-test
[ V{ { t t } } ] [ status-flags ] unit-test
] with-variable ;
! Copyright (C) 2005, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: arrays hashtables kernel models math namespaces sequences
-quotations math.vectors combinators sorting vectors dlists
-models threads concurrency.flags math.order ;
+USING: accessors arrays hashtables kernel models math namespaces
+sequences quotations math.vectors combinators sorting vectors
+dlists dequeues models threads concurrency.flags math.order ;
IN: ui.gadgets
SYMBOL: ui-notify-flag
: graft-queue ( -- dlist ) \ graft-queue get ;
: unqueue-graft ( gadget -- )
- graft-queue over gadget-graft-node delete-node
- dup gadget-graft-state first { t t } { f f } ?
- swap set-gadget-graft-state ;
+ [ graft-node>> graft-queue delete-node ]
+ [ [ first { t t } { f f } ? ] change-graft-state drop ] bi ;
: (queue-graft) ( gadget flags -- )
- over set-gadget-graft-state
- dup graft-queue push-front* swap set-gadget-graft-node
+ >>graft-state
+ dup graft-queue push-front* >>graft-node drop
notify-ui-thread ;
: queue-graft ( gadget -- )
>r >link r> history>> set-model ;
: <help-pane> ( browser-gadget -- gadget )
- history>> [ [ dup help ] try drop ] <pane-control> ;
+ history>> [ [ help ] curry try ] <pane-control> ;
: init-history ( browser-gadget -- )
"handbook" >link <history> >>history drop ;
! Copyright (C) 2006, 2007 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs io kernel math models namespaces
-prettyprint dlists sequences threads sequences words
+prettyprint dlists dequeues sequences threads sequences words
debugger ui.gadgets ui.gadgets.worlds ui.gadgets.tracks
ui.gestures ui.backend ui.render continuations init combinators
hashtables concurrency.flags sets ;
: event-loop? ( -- ? )
{
{ [ stop-after-last-window? get not ] [ t ] }
- { [ graft-queue dlist-empty? not ] [ t ] }
+ { [ graft-queue dequeue-empty? not ] [ t ] }
{ [ windows get-global empty? not ] [ t ] }
[ f ]
} cond ;
in-layout? on
layout-queue [
dup layout find-world [ , ] when*
- ] dlist-slurp
+ ] slurp-dequeue
] { } make prune ;
: redraw-worlds ( seq -- )
} case ;
: notify-queued ( -- )
- graft-queue [ notify ] dlist-slurp ;
+ graft-queue [ notify ] slurp-dequeue ;
: update-ui ( -- )
[ notify-queued layout-queued redraw-worlds ] assert-depth ;