diff --git a/library/dlists.factor b/contrib/dlists.factor similarity index 100% rename from library/dlists.factor rename to contrib/dlists.factor diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor index 7701ee1580..f59e5237ed 100644 --- a/library/bootstrap/boot-stage2.factor +++ b/library/bootstrap/boot-stage2.factor @@ -28,7 +28,6 @@ USING: kernel lists parser stdio words namespaces ; "/library/math/float.factor" "/library/math/complex.factor" "/library/lists.factor" - "/library/dlists.factor" "/library/vectors.factor" "/library/strings.factor" "/library/hashtables.factor" diff --git a/library/bootstrap/boot.factor b/library/bootstrap/boot.factor index 9dc6239564..250b4d5fbe 100644 --- a/library/bootstrap/boot.factor +++ b/library/bootstrap/boot.factor @@ -20,7 +20,6 @@ words hashtables ; "/library/math/float.factor" parse-resource append, "/library/math/complex.factor" parse-resource append, "/library/lists.factor" parse-resource append, - "/library/dlists.factor" parse-resource append, "/library/vectors.factor" parse-resource append, "/library/strings.factor" parse-resource append, "/library/hashtables.factor" parse-resource append, diff --git a/library/lists.factor b/library/lists.factor index 4107c8d7ea..e4d42d6d52 100644 --- a/library/lists.factor +++ b/library/lists.factor @@ -173,3 +173,20 @@ M: cons hashcode ( cons -- hash ) car hashcode ; #! Make a list of elements that occur in list2 but not #! list1. [ over contains? not ] subset nip ; + +: ( -- queue ) + #! Make a new functional queue. + [[ [ ] [ ] ]] ; + +: queue-empty? ( queue -- ? ) + uncons or not ; + +: enque ( obj queue -- queue ) + uncons >r cons r> cons ; + +: deque ( queue -- obj queue ) + uncons [ + uncons swapd cons + ] [ + reverse uncons f swons + ] ifte* ; diff --git a/library/test/lists/queues.factor b/library/test/lists/queues.factor new file mode 100644 index 0000000000..dd221ee70f --- /dev/null +++ b/library/test/lists/queues.factor @@ -0,0 +1,7 @@ +IN: scratchpad +USING: kernel lists test ; + +[ [ 1 2 3 4 5 ] ] [ + [ 1 2 3 4 5 ] [ swap enque ] each + 5 [ drop deque swap ] project nip +] unit-test diff --git a/library/threads.factor b/library/threads.factor index dc224c5c7f..abff946d89 100644 --- a/library/threads.factor +++ b/library/threads.factor @@ -2,23 +2,23 @@ ! Copyright (C) 2005 Mackenzie Straight. ! See http://factor.sf.net/license.txt for BSD license. IN: threads -USING: io-internals kernel kernel-internals lists dlists -namespaces ; +USING: io-internals kernel kernel-internals lists namespaces ; ! Core of the multitasker. Used by io-internals.factor and ! in-thread.factor. : run-queue ( -- queue ) 9 getenv ; : set-run-queue ( queue -- ) 9 setenv ; - -: init-threads ( -- ) - set-run-queue ; +: init-threads ( -- ) set-run-queue ; : next-thread ( -- quot ) - run-queue dlist-pop-front ; + run-queue dup queue-empty? [ + drop f + ] [ + deque set-run-queue + ] ifte ; -: schedule-thread ( quot -- ) - run-queue dlist-push-end ; +: schedule-thread ( quot -- ) run-queue enque set-run-queue ; : (yield) ( -- ) #! If there is a quotation in the run queue, call it,