]> gitweb.factorcode.org Git - factor.git/commitdiff
inspector bug fix, sleep word
authorSlava Pestov <slava@factorcode.org>
Tue, 23 Aug 2005 19:50:32 +0000 (19:50 +0000)
committerSlava Pestov <slava@factorcode.org>
Tue, 23 Aug 2005 19:50:32 +0000 (19:50 +0000)
27 files changed:
TODO.FACTOR.txt
library/alien/compiler.factor
library/bootstrap/boot-stage1.factor
library/bootstrap/boot-stage2.factor
library/collections/cons.factor
library/collections/queues.factor [new file with mode: 0644]
library/collections/sequence-sort.factor
library/eval-catch.factor [deleted file]
library/generic/generic.factor
library/in-thread.factor [deleted file]
library/io/c-streams.factor
library/syntax/generic.factor
library/syntax/parse-syntax.factor
library/syntax/prettyprint.factor
library/test/inspector.factor
library/test/listener.factor [deleted file]
library/test/lists/queues.factor
library/test/parser.factor
library/test/test.factor
library/threads.factor
library/tools/annotations.factor
library/tools/inspector.factor
library/tools/jedit.factor
library/unix/io.factor
library/vocabularies.factor
library/words.factor
native/run.h

index 2fb590a5a0dd6797946442c02d6a0fd1a97f7a4e..1cbcc78c563ed74d0b409ce3205ddfb668bee211 100644 (file)
@@ -1,8 +1,6 @@
 - reader syntax for arrays, byte arrays, displaced aliens\r
 - sleep word\r
-- docstrings appear twice\r
 - fix infer hang\r
-- fix sort out of bounds\r
 \r
 + ui:\r
 \r
@@ -82,7 +80,6 @@
 \r
 - split: return vectors\r
 - specialized arrays\r
-- clear special word props when redefining words\r
 - there is a problem with hashcodes of words and bootstrapping\r
 - delegating generic words with a non-standard picker\r
 - powerpc has weird callstack residue\r
index a4a153ac6b09313937c69dc3b432ef51b200c112..0eea452912f1fcea65998af1c613aee70b3349b4 100644 (file)
@@ -26,11 +26,7 @@ namespaces prettyprint sequences strings words ;
 
 ! FFI code does not run in the interpreter.
 
-TUPLE: alien-error symbol library ;
-
-C: alien-error ( lib sym -- )
-    [ set-alien-error-symbol ] keep
-    [ set-alien-error-library ] keep ;
+TUPLE: alien-error library symbol ;
 
 M: alien-error error. ( error -- )
     "C library interface words cannot be interpreted. " write
index c5af463403bee1690ee6c9dcd6b7855d47477494..4ee4d27ee3ef7cd753bb03b4e5d7adbf97280787 100644 (file)
@@ -33,6 +33,7 @@ sequences io vectors words ;
         "/library/math/ratio.factor"
         "/library/math/float.factor"
         "/library/math/complex.factor"
+        "/library/math/random.factor"
 
         "/library/collections/growable.factor"
         "/library/collections/cons.factor"
@@ -50,6 +51,7 @@ sequences io vectors words ;
         "/library/collections/sequence-sort.factor"
         "/library/collections/strings-epilogue.factor"
         "/library/collections/tree-each.factor"
+        "/library/collections/queues.factor"
 
         "/library/math/matrices.factor"
 
@@ -66,8 +68,8 @@ sequences io vectors words ;
         "/library/io/string-streams.factor"
         "/library/io/c-streams.factor"
         "/library/io/files.factor"
-
-        "/library/threads.factor"
+        "/library/io/directories.factor"
+        "/library/io/binary.factor"
 
         "/library/syntax/parse-numbers.factor"
         "/library/syntax/parse-words.factor"
@@ -91,10 +93,29 @@ sequences io vectors words ;
         
         "/library/syntax/prettyprint.factor"
 
+        "/library/io/logging.factor"
+
         "/library/tools/gensym.factor"
         "/library/tools/interpreter.factor"
         "/library/tools/debugger.factor"
         "/library/tools/memory.factor"
+        "/library/tools/listener.factor"
+        "/library/tools/word-tools.factor"
+        "/library/tools/walker.factor"
+        "/library/tools/jedit.factor"
+
+        "/library/test/test.factor"
+
+        "/library/tools/annotations.factor"
+        "/library/tools/inspector.factor"
+
+        "/library/syntax/see.factor"
+
+        "/library/threads.factor"
+        
+        "/library/tools/telnetd.factor"
+
+        "/library/bootstrap/image.factor"
 
         "/library/inference/dataflow.factor"
         "/library/inference/inference.factor"
@@ -128,8 +149,6 @@ sequences io vectors words ;
 
         "/library/cli.factor"
         
-        "/library/tools/memory.factor"
-    
         "/library/bootstrap/init.factor"
     } [ dup print parse-resource % ] each
     
index e5bed970be8f426cc4e8df79f787b85f9bd85ce5..e04ec496b3df230b580d2ce4475dbe03509312bb 100644 (file)
@@ -34,8 +34,6 @@ cpu "ppc" = [
     "/library/compiler/ppc/alien.factor"\r
 ] pull-in\r
 \r
-"Compiling base..." print\r
-\r
 "statically-linked" get [\r
     unix? [\r
         "sdl"      "libSDL.so"     "cdecl"    add-library\r
@@ -59,6 +57,8 @@ cpu "ppc" = [
 : compile? "compile" get supported-cpu? and ;\r
 \r
 compile? [\r
+    "Compiling base..." print\r
+\r
     \ car compile\r
     \ * compile\r
     \ = compile\r
@@ -78,27 +78,6 @@ t [
     "/library/math/pow.factor"\r
     "/library/math/trig-hyp.factor"\r
     "/library/math/arc-trig-hyp.factor"\r
-    "/library/math/random.factor"\r
-\r
-    "/library/in-thread.factor"\r
-\r
-    "/library/io/directories.factor"\r
-    "/library/io/binary.factor"\r
-    \r
-    "/library/eval-catch.factor"\r
-    "/library/tools/listener.factor"\r
-    "/library/tools/word-tools.factor"\r
-    "/library/syntax/see.factor"\r
-    "/library/test/test.factor"\r
-    "/library/tools/walker.factor"\r
-    "/library/tools/annotations.factor"\r
-    "/library/tools/inspector.factor"\r
-    "/library/bootstrap/image.factor"\r
-    \r
-    "/library/io/logging.factor"\r
-\r
-    "/library/tools/telnetd.factor"\r
-    "/library/tools/jedit.factor"\r
 \r
     "/library/httpd/load.factor"\r
     "/library/sdl/load.factor"\r
index 4192b09b9f910147d674e4b2a70102f004c67001..65b9806e959c9bd0a48ea9d9d0266102d9be324f 100644 (file)
@@ -35,21 +35,6 @@ PREDICATE: general-list list ( list -- ? )
 : 2car ( cons cons -- car car ) swap car swap car ; inline
 : 2cdr ( cons cons -- car car ) swap cdr swap cdr ; inline
 
-: <queue> ( -- queue )
-    #! Make a new functional queue.
-    [[ [ ] [ ] ]] ; foldable
-
-: queue-empty? ( queue -- ? )
-    uncons or not ; foldable
-
-: enque ( obj queue -- queue )
-    uncons >r cons r> cons ; foldable
-
-: deque ( queue -- obj queue )
-    uncons
-    [ uncons swapd cons ] [ reverse uncons f swons ] ifte* ;
-    foldable
-
 M: cons = ( obj cons -- ? )
     2dup eq? [
         2drop t
diff --git a/library/collections/queues.factor b/library/collections/queues.factor
new file mode 100644 (file)
index 0000000..7e3ed95
--- /dev/null
@@ -0,0 +1,24 @@
+IN: queues
+USING: errors kernel lists math sequences vectors ;
+
+TUPLE: queue in out ;
+
+C: queue ( -- queue ) ;
+
+: queue-empty? ( queue -- ? )
+    dup queue-in swap queue-out or not ;
+
+: enque ( obj queue -- )
+    [ queue-in cons ] keep set-queue-in ;
+
+: deque ( queue -- obj )
+    dup queue-out [
+        uncons rot set-queue-out
+    ] [
+        dup queue-in [
+            reverse uncons pick set-queue-out
+            f rot set-queue-in
+        ] [
+            "Empty queue" throw
+        ] ifte*
+    ] ifte* ;
index ad8dd71cac754a78ff4c347013cc2bf2ddc9adef..6555bdd31f910ee43afae87fa51b92d683d84ccf 100644 (file)
@@ -72,7 +72,7 @@ DEFER: (nsort)
 IN: sequences
 
 : nsort ( seq quot -- | quot: elt elt -- -1/0/1 )
-    swap dup empty?
+    swap dup length 1 <=
     [ 2drop ] [ 0 over length 1 - (nsort) ] ifte ; inline
 
 : sort ( seq quot -- seq | quot: elt elt -- -1/0/1 )
diff --git a/library/eval-catch.factor b/library/eval-catch.factor
deleted file mode 100644 (file)
index 68b8833..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-! Copyright (C) 2004, 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: parser USING: kernel errors io ;
-
-: eval-catch ( str -- )
-    [ eval ] [ [ print-error debug-help drop ] when* ] catch ;
-
-: eval>string ( in -- out )
-    [ eval-catch ] string-out ;
index eb028bf5a7142292a358ce12f9f91bfdcf26243d..8571568259283dd0808eb53b78c0186c54b277f9 100644 (file)
@@ -62,7 +62,7 @@ SYMBOL: builtin
     "methods" word-prop hash-keys [ class-compare ] sort ;
 
 : make-generic ( word -- )
-    dup dup "combination" word-prop call (define-compound) ;
+    dup dup "combination" word-prop call define-compound ;
 
 : define-method ( class generic definition -- )
     -rot
diff --git a/library/in-thread.factor b/library/in-thread.factor
deleted file mode 100644 (file)
index 140123b..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-! Copyright (C) 2004, 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: threads
-USING: errors kernel lists namespaces sequences ;
-
-: in-thread ( quot -- )
-    #! Execute a quotation in a co-operative thread. The
-    #! quotation begins executing immediately, and execution
-    #! after the 'in-thread' call in the original thread
-    #! resumes when the quotation yields, either due to blocking
-    #! I/O or an explicit call to 'yield'.
-    [
-        schedule-thread
-        ! Clear stacks since we never go up from this point
-        [ ] set-catchstack
-        { } set-callstack
-        try
-        stop
-    ] callcc0 drop ;
index 6aebdb785d5fc3c2437d9f9f474b811adbd58761..483dcdfe50b971d58bf7286f04b39edd88ad684c 100644 (file)
@@ -34,6 +34,8 @@ M: c-stream stream-close ( stream -- )
 : init-io ( -- )
     13 getenv  14 getenv  t <c-stream> <line-reader> stdio set ;
 
+: io-multiplex ( ms -- ) drop ;
+
 IN: io
 
 : <file-reader> ( path -- stream )
index c611ddb1433aaffd886092319d86d808d2c32f46..eaf9959eaeef93ab9d4d9e1de7e8463172ad82bc 100644 (file)
@@ -8,11 +8,11 @@ words ;
 
 : GENERIC:
     #! GENERIC: bar == G: bar simple-combination ;
-    CREATE define-generic ; parsing
+    CREATE dup reset-word define-generic ; parsing
 
 : G:
     #! G: word combination ;
-    CREATE [ define-generic* ] [ ] ; parsing
+    CREATE dup reset-word [ define-generic* ] [ ] ; parsing
 
 : COMPLEMENT: ( -- )
     #! Followed by a class name, then a complemented class.
index 8436bb5b66873a4a8a468f50b519bc11431656b1..2e9dff7438c77041fa9041767ec15abe4a5e8d07 100644 (file)
@@ -62,7 +62,8 @@ words ;
 ! Word definitions
 : :
     #! Begin a word definition. Word name follows.
-    CREATE [ define-compound ] [ ] "in-definition" on ; parsing
+    CREATE dup reset-generic [ define-compound ]
+    [ ] "in-definition" on ; parsing
 
 : ;
     #! End a word definition.
@@ -71,7 +72,7 @@ words ;
 ! Symbols
 : SYMBOL:
     #! A symbol is a word that pushes itself when executed.
-    CREATE define-symbol ; parsing
+    CREATE dup reset-generic define-symbol ; parsing
 
 : \
     #! Word literals: \ foo
@@ -90,7 +91,7 @@ words ;
 : DEFER:
     #! Create a word with no definition. Used for mutually
     #! recursive words.
-    CREATE drop ; parsing
+    CREATE dup reset-generic drop ; parsing
 
 : FORGET:
     #! Followed by a word name. The word is removed from its
index 878c9c3ce72a3f1e98e69d0a654c2e8bb27f1131..f568030ae996337b60361efa10499724a0fdd846 100644 (file)
@@ -321,7 +321,7 @@ M: wrapper pprint* ( wrapper -- )
 
 : unparse-short ( object -- str ) [ pprint-short ] string-out ;
 
-: unparse-short ( object -- )
+: unparse-short. ( object -- )
     dup unparse-short swap write-object terpri ;
 
 : [.] ( sequence -- ) [ unparse-short. ] each ;
index ad245af24122203facf9b233a5e7e87616c665ad..7c08ce93b0d9be978de874e9b0984b1fd1c167d7 100644 (file)
@@ -1,7 +1,11 @@
 IN: temporary
-USING: test inspector prettyprint math ;
+USING: inspector math namespaces prettyprint test ;
+
+[[ "hello" "world" ]] inspect
+
+[ "hello" ] [ 0 get ] unit-test
+[ "world" ] [ 1 get ] unit-test
 
-[[ 1 2 ]] inspect
 [ 1 2 3 ] inspect
 f inspect
 \ + inspect
diff --git a/library/test/listener.factor b/library/test/listener.factor
deleted file mode 100644 (file)
index 353728f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-IN: temporary
-USE: namespaces
-USE: io
-USE: test
-USE: parser
-
-[
-    [ 4 ] [ "2 2 +" eval-catch ] unit-test
-    "The following will print an error; ignore it." print terpri
-    [ ] [ "clear drop" eval-catch ] unit-test
-] with-scope
index c8a7251e6eef4d26afca2dc16667c429a2b362cc..082381afbd05bc6591fcb385eac5a1e2d778cdcf 100644 (file)
@@ -1,7 +1,12 @@
 IN: temporary
-USING: kernel lists math sequences test ;
+USING: kernel math namespaces queues sequences test ;
 
-[ { 1 2 3 4 5 } ] [
-    <queue> [ 1 2 3 4 5 ] [ swap enque ] each
-    5 [ drop deque swap ] map nip
-] unit-test
+<queue> "queue" set
+
+[ t ] [ "queue" get queue-empty? ] unit-test
+
+[ ] [ [ 1 2 3 4 5 ] [ "queue" get enque ] each ] unit-test
+
+[ { 1 2 3 4 5 } ] [ 5 [ drop "queue" get deque ] map ] unit-test
+
+[ "queue" get deque ] unit-test-fails
index c7d6ce9d55f56812b9d6ede189ffb36bc32653af..3305ee51ff42bc28184be3fe6f6790df3ea555a1 100644 (file)
@@ -69,8 +69,4 @@ unit-test
 ! Test EOL comments in multiline strings.
 [ [ "Hello" ] ] [ "#! This calls until-eol.\n\"Hello\"" parse ] unit-test 
 
-[ 4 ] [ "2 2 +" eval-catch ] unit-test
-[ "4\n" ] [ "2 2 + ." eval>string ] unit-test
-[ ] [ "fdafdf" eval-catch ] unit-test
-
 [ word ] [ \ f class ] unit-test
index 80e8c3495ef6ca14327fd77c82933d123d7a74b6..711305e8645e88631fc2a396626fefe438688fc0 100644 (file)
@@ -80,7 +80,7 @@ SYMBOL: failures
         "continuations" "errors" "hashtables" "strings"
         "namespaces" "generic" "tuple" "files" "parser"
         "parse-number" "init" "io/io"
-        "listener" "vectors" "words" "prettyprint" "random"
+        "vectors" "words" "prettyprint" "random"
         "stream" "math/bitops"
         "math/math-combinators" "math/rational" "math/float"
         "math/complex" "math/irrational" "math/integer"
index e2e84024872dcd3b8644ec8c1d00f6f6e866b297..f0c96a196b5fa3f2274b60781f41ed06dabb8290 100644 (file)
@@ -2,32 +2,48 @@
 ! Copyright (C) 2005 Mackenzie Straight.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: threads
-USING: errors kernel kernel-internals lists namespaces ;
-! Core of the multitasker. Used by io-internals.factor and
-! in-thread.factor.
+USING: errors hashtables io-internals kernel lists math
+namespaces queues sequences vectors ;
 
-: run-queue ( -- queue ) 9 getenv ;
-: set-run-queue ( queue -- ) 9 setenv ;
-: init-threads ( -- ) <queue> set-run-queue ;
+! Co-operative multitasker.
+
+: run-queue ( -- queue ) \ run-queue global hash ;
+
+: schedule-thread ( quot -- ) run-queue enque ;
+
+: sleep-queue ( -- vec ) \ sleep-queue global hash ;
+
+: sleep-queue* ( -- vec )
+    sleep-queue dup [ 2car swap - ] nsort ;
+
+: sleep-time ( sorted-queue -- ms )
+    dup empty? [ drop -1 ] [ peek car millis - 0 max ] ifte ;
+
+DEFER: next-thread
+
+: do-sleep ( -- quot )
+    sleep-queue* dup sleep-time dup 0 =
+    [ drop pop ] [ io-multiplex next-thread ] ifte ;
 
 : next-thread ( -- quot )
-    run-queue dup queue-empty? [
-        drop f
-    ] [
-        deque set-run-queue
-    ] ifte ;
-
-: schedule-thread ( quot -- )
-    run-queue enque set-run-queue ;
-
-: stop ( -- )
-    #! Stop the current thread and begin executing the next one.
-    next-thread [ call ] [ "No more tasks" throw ] ifte* ;
-
-: yield ( -- )
-    #! Add the current continuation to the run queue, and yield
-    #! to the next quotation. The current continuation will
-    #! eventually be restored by a future call to stop or
-    #! yield.
-    [ schedule-thread stop ] callcc0 ;
+    run-queue dup queue-empty? [ drop do-sleep ] [ deque ] ifte ;
+
+: stop ( -- ) next-thread call ;
+
+: yield ( -- ) [ schedule-thread stop ] callcc0 ;
+
+: sleep ( ms -- )
+    millis + [ cons sleep-queue push stop ] callcc0 drop ;
+
+: in-thread ( quot -- )
+    [
+        schedule-thread
+        [ ] set-catchstack { } set-callstack
+        try stop
+    ] callcc0 drop ;
+
+: init-threads ( -- )
+    global [
+        <queue> \ run-queue set
+        10 <vector> \ sleep-queue set
+    ] bind ;
index 9484bee494a7e7c1f0e1c2c2e4aa73d7d085d08d..0f2c88342670f288a6a0abbafad371ce792e79ba 100644 (file)
@@ -10,7 +10,7 @@ USING: interpreter io kernel lists namespaces prettyprint
 sequences strings test ;
 
 : annotate ( word quot -- | quot: word def -- def )
-    over >r >r dup word-def r> call r> swap (define-compound) ;
+    over >r >r dup word-def r> call r> swap define-compound ;
     inline
 
 : (watch) ( word def -- def )
index 1a92619530850e2a6718d9bca1f038addd21c3ef..12ff72dcbf24b1a395ddba98be859f1bf142add4 100644 (file)
@@ -28,8 +28,11 @@ M: hashtable sheet dup hash-keys swap hash-values 2vector ;
     [ max-length ] keep
     [ swap CHAR: \s pad-right ] map-with ;
 
+: sheet-numbers ( sheet -- sheet )
+    dup first length >vector 1vector swap append ;
+
 : format-sheet ( sheet -- list )
-    dup first length >vector swons
+    sheet-numbers
     dup peek over first [ set ] 2each
     [ format-column ] map
     flip
index bceced0fe3359d7acf5e245b4fcc22f3fa18787d..ead715d2d4de0d47009ecaaf9c2b30fe501b184d 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2004, 2005 Slava Pestov.
 ! See http://factor.sf.net/license.txt for BSD license.
 IN: jedit
-USING: io kernel lists namespaces parser prettyprint sequences
-strings unparser vectors words ;
+USING: errors io kernel lists namespaces parser prettyprint
+sequences strings unparser vectors words ;
 
 ! Some words to send requests to a running jEdit instance to
 ! edit files and position the cursor on a specific line number.
@@ -63,6 +63,9 @@ strings unparser vectors words ;
 
 : read-packet ( -- string ) 4 read be> read ;
 
+: eval>string ( str -- )
+    [ [ [ eval ] keep ] try drop ] string-out ;
+
 : wire-server ( -- )
     #! Repeatedly read jEdit requests and execute them. Return
     #! on EOF.
index 8bbf1290d0b0e47bcaf95ce11988f52de74256fc..add19d9f9dcf76ec8992a10a1293428aa3222fe9 100644 (file)
@@ -300,10 +300,6 @@ M: port stream-close ( stream -- )
 : <fd-stream> ( infd outfd flush? -- stream )
     >r >r <reader> r> <writer> r> <duplex-stream> ;
 
-: idle-io-task ( -- )
-    [ schedule-thread 10 io-multiplex stop ] callcc0
-    idle-io-task ;
-
 USE: io
 
 : init-io ( -- )
@@ -315,5 +311,4 @@ USE: io
         <namespace> write-tasks set
         FD_SETSIZE <bit-array> write-fdset set
         0 1 t <fd-stream> stdio set
-    ] bind
-    [ idle-io-task ] in-thread ;
+    ] bind ;
index 8c1e71d579e1e715188351cd05935efcf00689f6..a09f26a65f6080f97d4d146c0e0494d4c40db68c 100644 (file)
@@ -85,10 +85,10 @@ SYMBOL: vocabularies
 : init-search-path ( -- )
     "scratchpad" "in" set
     [
-        "compiler" "errors" "gadgets" "generic"
-        "hashtables" "help" "inference" "inspector" "interpreter"
+        "compiler" "errors" "gadgets" "generic" "hashtables"
+        "help" "inference" "inspector" "interpreter" "io"
         "jedit" "kernel" "listener" "lists" "math" "matrices"
-        "memory" "namespaces" "parser" "prettyprint"
-        "sequences" "io" "strings" "styles" "syntax" "test"
-        "threads" "vectors" "words" "scratchpad"
+        "memory" "namespaces" "parser" "prettyprint" "queues"
+        "scratchpad" "sequences" "strings" "styles" "syntax"
+        "test" "threads" "vectors" "words"
     ] "use" set ;
index dcbb95c06de277acb78872a602e870becefc4d8f..119d44d9505a4bbaa4e2ee67d7c03ec093d04ab9 100644 (file)
@@ -111,18 +111,18 @@ M: symbol definer drop \ SYMBOL: ;
 PREDICATE: word compound  ( obj -- ? ) word-primitive 1 = ;
 M: compound definer drop \ : ;
 
-: (define-compound) ( word def -- )
+: define-compound ( word def -- )
     >r dup dup remove-crossref r> 1 swap define add-crossref ;
 
 : reset-props ( word seq -- )
     [ f swap set-word-prop ] each-with ;
 
-: reset-generic ( word -- )
-    #! Make a word no longer be generic.
-    { "methods" "combination" } reset-props ;
+: reset-word ( word -- )
+    { "parsing" "inline" "foldable" "flushable" "predicating" }
+    reset-props ;
 
-: define-compound ( word def -- )
-     over reset-generic (define-compound) ;
+: reset-generic ( word -- )
+    dup reset-word { "methods" "combination" } reset-props ;
 
 GENERIC: literalize ( obj -- obj )
 
index e09986e11cd66646f198c95bcb0a68c6febabc9d..e9cb3c04ab7b57119dd767c04dcba7da3e771d9f 100644 (file)
@@ -8,7 +8,7 @@
 #define CATCHSTACK_ENV 6 /* used by library only */
 #define CPU_ENV        7
 #define BOOT_ENV       8
-#define RUNQUEUE_ENV   9 /* used by library only */
+#define UNUSED_ENV     9
 #define ARGS_ENV       10
 #define OS_ENV         11
 #define ERROR_ENV      12 /* a marker consed onto kernel errors */