functional queue in place of dlists; disable generic partial eval due to buggyness
parent
b02f5d305c
commit
d0bb4944f1
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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> ( -- 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* ;
|
||||
|
|
|
@ -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
|
|
@ -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 ( -- )
|
||||
<dlist> set-run-queue ;
|
||||
: init-threads ( -- ) <queue> 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,
|
||||
|
|
Loading…
Reference in New Issue