functional queue in place of dlists; disable generic partial eval due to buggyness

cvs
Slava Pestov 2005-02-25 23:11:10 +00:00
parent b02f5d305c
commit d0bb4944f1
6 changed files with 32 additions and 10 deletions

View File

@ -28,7 +28,6 @@ USING: kernel lists parser stdio words namespaces ;
"/library/math/float.factor" "/library/math/float.factor"
"/library/math/complex.factor" "/library/math/complex.factor"
"/library/lists.factor" "/library/lists.factor"
"/library/dlists.factor"
"/library/vectors.factor" "/library/vectors.factor"
"/library/strings.factor" "/library/strings.factor"
"/library/hashtables.factor" "/library/hashtables.factor"

View File

@ -20,7 +20,6 @@ words hashtables ;
"/library/math/float.factor" parse-resource append, "/library/math/float.factor" parse-resource append,
"/library/math/complex.factor" parse-resource append, "/library/math/complex.factor" parse-resource append,
"/library/lists.factor" parse-resource append, "/library/lists.factor" parse-resource append,
"/library/dlists.factor" parse-resource append,
"/library/vectors.factor" parse-resource append, "/library/vectors.factor" parse-resource append,
"/library/strings.factor" parse-resource append, "/library/strings.factor" parse-resource append,
"/library/hashtables.factor" parse-resource append, "/library/hashtables.factor" parse-resource append,

View File

@ -173,3 +173,20 @@ M: cons hashcode ( cons -- hash ) car hashcode ;
#! Make a list of elements that occur in list2 but not #! Make a list of elements that occur in list2 but not
#! list1. #! list1.
[ over contains? not ] subset nip ; [ over contains? not ] subset nip ;
: <queue> ( -- 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* ;

View File

@ -0,0 +1,7 @@
IN: scratchpad
USING: kernel lists test ;
[ [ 1 2 3 4 5 ] ] [
<queue> [ 1 2 3 4 5 ] [ swap enque ] each
5 [ drop deque swap ] project nip
] unit-test

View File

@ -2,23 +2,23 @@
! Copyright (C) 2005 Mackenzie Straight. ! Copyright (C) 2005 Mackenzie Straight.
! See http://factor.sf.net/license.txt for BSD license. ! See http://factor.sf.net/license.txt for BSD license.
IN: threads IN: threads
USING: io-internals kernel kernel-internals lists dlists USING: io-internals kernel kernel-internals lists namespaces ;
namespaces ;
! Core of the multitasker. Used by io-internals.factor and ! Core of the multitasker. Used by io-internals.factor and
! in-thread.factor. ! in-thread.factor.
: run-queue ( -- queue ) 9 getenv ; : run-queue ( -- queue ) 9 getenv ;
: set-run-queue ( queue -- ) 9 setenv ; : set-run-queue ( queue -- ) 9 setenv ;
: init-threads ( -- ) <queue> set-run-queue ;
: init-threads ( -- )
<dlist> set-run-queue ;
: next-thread ( -- quot ) : next-thread ( -- quot )
run-queue dlist-pop-front ; run-queue dup queue-empty? [
drop f
] [
deque set-run-queue
] ifte ;
: schedule-thread ( quot -- ) : schedule-thread ( quot -- ) run-queue enque set-run-queue ;
run-queue dlist-push-end ;
: (yield) ( -- ) : (yield) ( -- )
#! If there is a quotation in the run queue, call it, #! If there is a quotation in the run queue, call it,