]> gitweb.factorcode.org Git - factor.git/commitdiff
generic.factor cleanups; started generalized dispatching
authorSlava Pestov <slava@factorcode.org>
Sat, 11 Dec 2004 23:18:43 +0000 (23:18 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 11 Dec 2004 23:18:43 +0000 (23:18 +0000)
23 files changed:
factor/jedit/FactorPlugin.java
library/bootstrap/boot-stage2.factor
library/bootstrap/boot.factor
library/bootstrap/image.factor
library/compiler/linearizer.factor
library/compiler/optimizer.factor
library/generic.factor
library/httpd/html.factor
library/inference/dataflow.factor
library/io/ansi.factor
library/io/network.factor
library/io/stdio.factor
library/io/stream-impl.factor
library/io/stream.factor
library/strings.factor
library/syntax/parse-syntax.factor
library/test/generic.factor
library/test/lists/assoc.factor
library/test/lists/cons.factor
library/test/stream.factor
library/tools/jedit-wire.factor
library/types.factor
library/words.factor

index 6c4be2b07a5bd4282abe3eb7f6585c1fa32ac13c..23cbadc4778c294141ed88e90b9f95438090b7c9 100644 (file)
@@ -447,6 +447,8 @@ public class FactorPlugin extends EditPlugin
                String decl = "USE: " + vocab;
                if(leadingNewline)
                        decl = "\n" + decl;
+               if(lastUseOffset == 0)
+                       decl = decl + "\n";
                buffer.insert(lastUseOffset,decl);
                showStatus(view,"inserted-use",decl);
        } //}}}
index 74dbd719dc7584bb182c95375bbfaff1162ced6a..5eff3381a056f30b531e472890dd80c117561b23 100644 (file)
@@ -36,6 +36,7 @@ USE: stdio
     "/version.factor"\r
     "/library/kernel.factor"\r
     "/library/stack.factor"\r
+    "/library/generic.factor"\r
     "/library/types.factor"\r
     "/library/math/math.factor"\r
     "/library/cons.factor"\r
@@ -50,7 +51,6 @@ USE: stdio
     "/library/strings.factor"\r
     "/library/hashtables.factor"\r
     "/library/namespaces.factor"\r
-    "/library/generic.factor"\r
     "/library/list-namespaces.factor"\r
     "/library/sbuf.factor"\r
     "/library/continuations.factor"\r
index 4553f809c729049e4dd0072d70736b0b8dc971b8..ae03fdf034eca0af7b2ed4f28cd0002d68297ee9 100644 (file)
@@ -38,6 +38,7 @@ primitives,
     "/version.factor"
     "/library/stack.factor"
     "/library/kernel.factor"
+    "/library/generic.factor"
     "/library/types.factor"
     "/library/combinators.factor"
     "/library/math/math.factor"
@@ -52,7 +53,6 @@ primitives,
     "/library/strings.factor"
     "/library/hashtables.factor"
     "/library/namespaces.factor"
-    "/library/generic.factor"
     "/library/list-namespaces.factor"
     "/library/sbuf.factor"
     "/library/continuations.factor"
index c569d6d3857c21d7f94686746a32c2f753c7cecf..dd3a5730fd499949113962bd77a72ac4b022f7a3 100644 (file)
@@ -42,7 +42,6 @@ IN: image
 USE: errors
 USE: hashtables
 USE: kernel
-USE: kernel-internals
 USE: lists
 USE: math
 USE: namespaces
@@ -84,6 +83,26 @@ SYMBOL: boot-quot
 : untag ( cell tag -- ) tag-mask bitnot bitand ;
 : tag ( cell -- tag ) tag-mask bitand ;
 
+: fixnum-tag  BIN: 000 ; inline
+: word-tag    BIN: 001 ; inline
+: cons-tag    BIN: 010 ; inline
+: object-tag  BIN: 011 ; inline
+: ratio-tag   BIN: 100 ; inline
+: complex-tag BIN: 101 ; inline
+: header-tag  BIN: 110 ; inline
+
+: f-type      6  ; inline
+: t-type      7  ; inline
+: array-type  8  ; inline
+: bignum-type 9  ; inline
+: float-type  10 ; inline
+: vector-type 11 ; inline
+: string-type 12 ; inline
+: sbuf-type   13 ; inline
+: port-type   14 ; inline
+: dll-type    15 ; inline
+: alien-type  16 ; inline
+
 : immediate ( x tag -- tagged ) swap tag-bits shift bitor ;
 : >header ( id -- tagged ) header-tag immediate ;
 
@@ -135,14 +154,14 @@ SYMBOL: boot-quot
 ( Bignums )
 
 : emit-bignum ( bignum -- tagged )
+    #! This can only emit 0, -1 and 1.
     object-tag here-as >r
     bignum-type >header emit
-    dup 0 = 1 2 ? emit ( capacity )
     [
-        [ 0 = ] [ emit pad ]
-        [ 0 < ] [ 1 emit neg emit ]
-        [ 0 > ] [ 0 emit     emit ]
-    ] cond r> ;
+        [ 0  | [ 1 0   ] ]
+        [ -1 | [ 2 1 1 ] ]
+        [ 1  | [ 2 0 1 ] ]
+    ] assoc [ emit ] each pad r> ;
 
 ( Special objects )
 
index e51bd5388b87c8ee180282e337f03c3b344ef05e..02d54c658b9b9a09681b49576a96792502192335 100644 (file)
@@ -86,10 +86,16 @@ SYMBOL: #return-to ( push addr on C stack )
 : label, ( label -- )
     #label swons , ;
 
-: (linearize-label) ( node -- )
+: linearize-simple-label ( node -- )
+    #! Some labels become simple labels after the optimization
+    #! stage.
     dup [ node-label get ] bind label,
     [ node-param get ] bind (linearize) ;
 
+#simple-label [
+    linearize-simple-label
+] "linearizer" set-word-property
+
 : linearize-label ( node -- )
     #! Labels are tricky, because they might contain non-tail
     #! calls. So we push the address of the location right after
@@ -98,11 +104,13 @@ SYMBOL: #return-to ( push addr on C stack )
     #! this in the common case where the labelled block does
     #! not contain non-tail recursive calls to itself.
     <label> dup #return-to swons , >r
-    (linearize-label)
+    linearize-simple-label
     [ #return ] ,
     r> label, ;
 
-#label [ linearize-label ] "linearizer" set-word-property
+#label [
+    linearize-label
+] "linearizer" set-word-property
 
 : linearize-ifte ( param -- )
     #! The parameter is a list of two lists, each one a dataflow
index 084b157098c688502c3fe27aa1117c012113fec4..70a4695225ed7ddbc9d20eec8597078a91b978a5 100644 (file)
@@ -129,20 +129,23 @@ USE: prettyprint
     [ node-param get ] bind can-kill?
 ] "can-kill" set-word-property
 
-: (calls-label?) ( label node -- ? )
-    "calls-label" [ 2drop f ] apply-dataflow ;
-
 #call-label [
     [ node-param get ] bind =
 ] "calls-label" set-word-property
 
 : calls-label? ( label list -- ? )
-    [ dupd (calls-label?) ] some? nip ;
+    [
+        dupd "calls-label" [ 2drop f ] apply-dataflow
+    ] some? nip ;
 
 #label [
     [ node-param get ] bind calls-label?
 ] "calls-label" set-word-property
 
+#simple-label [
+    [ node-param get ] bind calls-label?
+] "calls-label" set-word-property
+
 : branches-call-label? ( label list -- ? )
     [ dupd calls-label? ] some? nip ;
 
@@ -158,17 +161,16 @@ USE: prettyprint
     [ node-param get ] bind branches-call-label?
 ] "calls-label" set-word-property
 
-: recursive-label? ( node -- ? )
+: optimize-label ( -- op )
     #! Does the label node contain calls to itself?
-    [ node-label get node-param get ] bind
-    calls-label? ;
+    node-label get node-param get calls-label?
+    #label #simple-label ? ;
 
 #label [ ( literals node -- )
-    dup recursive-label? [
-       [ node-param [ kill-nodes ] change ] extend ,
-    ] [
-       [ node-param get ] bind (kill-nodes)
-    ] ifte
+    [
+        optimize-label node-op set
+        node-param [ kill-nodes ] change
+    ] extend ,
 ] "kill-node" set-word-property
 
 #ifte [ scan-branches ] "scan-literal" set-word-property
index ff1ea3df798b2d0e6a4983a5cfa53318949bb3f4..c12dd31f0da52884130df8fbfa43608c5e469e94 100644 (file)
@@ -37,7 +37,23 @@ USE: strings
 USE: words
 USE: vectors
 
-! A simple prototype-based generic word system.
+! A simple single-dispatch generic word system.
+
+: predicate-word ( word -- word )
+    word-name "?" cat2 "in" get create ;
+
+: builtin-predicate ( symbol type# -- )
+    [ swap type eq? ] cons >r predicate-word r> define-compound ;
+
+: BUILTIN:
+    #! Followed by type name and type number. Define a built-in
+    #! type predicate with this number.
+    CREATE dup undefined? [ dup define-symbol ] when scan-word
+    2dup builtin-predicate
+    "builtin-type" set-word-property ; parsing
+
+: builtin-type ( symbol -- n )
+    "builtin-type" word-property ;
 
 ! Hashtable slot holding a selector->method map.
 SYMBOL: traits
@@ -63,7 +79,7 @@ SYMBOL: delegate
 : undefined-method
     "No applicable method." throw ;
 
-: method ( selector traits -- traits quot )
+: traits-method ( selector traits -- traits quot )
     #! Look up the method with the traits object on the stack.
     #! Returns the traits to call the method on; either the
     #! original object, or one of the delegates.
@@ -71,20 +87,17 @@ SYMBOL: delegate
         rot drop cdr ( method is defined )
     ] [
         drop delegate swap hash* dup [
-            cdr method ( check delegate )
+            cdr traits-method ( check delegate )
         ] [
             drop [ undefined-method ] ( no delegate )
         ] ifte
     ] ifte ;
 
-: predicate-word ( word -- word )
-    word-name "?" cat2 "in" get create ;
-
-: define-predicate ( word -- )
+: traits-predicate ( word -- )
     #! foo? where foo is a traits type tests if the top of stack
     #! is of this type.
     dup predicate-word swap
-    [ object-map ] swap traits-map [ eq? ] cons append
+    traits-map [ swap object-map eq? ] cons
     define-compound ;
 
 : TRAITS:
@@ -93,15 +106,26 @@ SYMBOL: delegate
     CREATE
     dup define-symbol
     dup init-traits-map
-    define-predicate ; parsing
+    traits-predicate ; parsing
+
+: add-method ( quot class vtable -- )
+    >r "builtin-type" word-property r>
+    set-vector-nth ;
+
+: <vtable> ( word -- vtable )
+    num-types [ drop [ undefined-method ] ] vector-project
+    [ "vtable" set-word-property ] keep ;
+
+: add-traits-dispatch ( word vtable -- )
+    >r unit [ car swap traits-method call ] cons \ vector r>
+    add-method ;
 
 : GENERIC:
     #! GENERIC: bar creates a generic word bar that calls the
     #! bar method on the traits object, with the traits object
     #! on the stack.
-    CREATE
-    dup unit [ car swap method call ] cons
-    define-compound ; parsing
+    CREATE dup <vtable> 2dup add-traits-dispatch
+    [ generic ] cons define-compound ; parsing
 
 : constructor-word ( word -- word )
     word-name "<" swap ">" cat3 "in" get create ;
@@ -111,23 +135,18 @@ SYMBOL: delegate
     traits-map [ traits pick set-hash ] cons append
     define-compound ;
 
-: C: ( -- word [ ] )
-    #! C: foo ... begins definition for <foo> where foo is a
-    #! traits type. We have to reverse the list at the end,
-    #! since the parser conses onto the list, and it will be
-    #! reversed again by ;C.
-    scan-word [ constructor-word [ <namespace> ] ] keep
-    traits-map [ traits pick set-hash ] cons append reverse ;
-    parsing
+: (;C) ( constructor traits definition -- )
+    >r
+    traits-map [ traits pick set-hash ] cons \ <namespace> swons
+    r> append define-compound ;
 
-: ;C ( word [ ] -- )
-    POSTPONE: ; ; parsing
+: C: ( -- constructor traits [ ] )
+    #! C: foo ... begins definition for <foo> where foo is a
+    #! traits type.
+    scan-word [ constructor-word ] keep [ (;C) ] [ ] ; parsing
 
 : M: ( -- type generic [ ] )
     #! M: foo bar begins a definition of the bar generic word
     #! specialized to the foo type.
-    scan-word scan-word f ; parsing
-
-: ;M ( type generic def -- )
-    #! ;M ends a method definition.
-    rot traits-map [ reverse put ] bind ; parsing
+    scan-word scan-word [ rot traits-map [ put ] bind ] [ ] ;
+    parsing
index d7982342719a76e3a635259558867f976d1310a3..5f2576086c994394491bf7c765c3c7224a2cec7b 100644 (file)
@@ -143,7 +143,7 @@ M: html-stream fwrite-attr ( str style stream -- )
                 ] file-link-tag
             ] object-link-tag
         ] icon-tag
-    ] bind ;M
+    ] bind ;
 
 C: html-stream ( stream -- stream )
     #! Wraps the given stream in an HTML stream. An HTML stream
@@ -159,7 +159,7 @@ C: html-stream ( stream -- stream )
     #! underline
     #! size
     #! link - an object path
-    [ dup delegate set stdio set ] extend ;C
+    [ dup delegate set stdio set ] extend ;
 
 : with-html-stream ( quot -- )
     [ stdio [ <html-stream> ] change  call ] with-scope ;
index 712200e1d38be7ab0c364483bef94c1584d5e0e1..0b04292a273a3e3cc2ecdc8dab9addacd2c8b982 100644 (file)
@@ -40,6 +40,11 @@ SYMBOL: dataflow-graph
 ! Label nodes have the node-label variable set.
 SYMBOL: #label
 
+! A label that is not called recursively at all, or only tail
+! recursively. The optimizer changes some #labels to
+! #simple-labels.
+SYMBOL: #simple-label
+
 SYMBOL: #call ( non-tail call )
 SYMBOL: #call-label
 SYMBOL: #push ( literal )
index 3f1800169af37d5ba1518160f10a1bf29735f0e5..b980d2b7075f2c0a6da37a4108d499574195ffe0 100644 (file)
@@ -82,7 +82,7 @@ M: ansi-stream fwrite-attr ( string style stream -- )
     [
         [ default-style ] unless* ansi-attr-string
         delegate get fwrite
-    ] bind ;M
+    ] bind ;
 
 C: ansi-stream ( stream -- stream )
     #! Wraps the given stream in an ANSI stream. ANSI streams
index 2158e2b34b2d1781ddc0c08c375e5d21b954d190..e2b8334d0300d5f0cedb49ff79ebd7d16c295885 100644 (file)
@@ -39,13 +39,13 @@ USE: generic
 TRAITS: server
 
 M: server fclose ( stream -- )
-    [ "socket" get close-port ] bind ;M
+    [ "socket" get close-port ] bind ;
 
 C: server ( port -- stream )
     #! Starts listening on localhost:port. Returns a stream that
     #! you can close with fclose, and accept connections from
     #! with accept. No other stream operations are supported.
-    [ server-socket "socket" set ] extend ;C
+    [ server-socket "socket" set ] extend ;
 
 : <client-stream> ( host port in out -- stream )
     <fd-stream> [ ":" swap unparse cat3 "client" set ] extend ;
index 79a5e57b762be656f85f8cd1c3ceff8fb2321392..d2f5bb3e501a0850636f2846d721b891502a9330 100644 (file)
@@ -63,10 +63,10 @@ SYMBOL: stdio
 TRAITS: stdio-stream
 
 M: stdio-stream fauto-flush ( -- )
-    [ delegate get fflush ] bind ;M
+    [ delegate get fflush ] bind ;
 
 M: stdio-stream fclose ( -- )
-    drop ;M
+    drop ;
 
 C: stdio-stream ( delegate -- stream )
-    [ delegate set ] extend ;C
+    [ delegate set ] extend ;
index 856e4d95279b6584a9b538c151c5a6248c4b26dd..bd756b11c61953c3cf2622fa25e041a8b12a446f 100644 (file)
@@ -41,28 +41,28 @@ USE: generic
 TRAITS: fd-stream
 
 M: fd-stream fwrite-attr ( str style stream -- )
-    [ drop "out" get blocking-write ] bind ;M
+    [ drop "out" get blocking-write ] bind ;
 
 M: fd-stream freadln ( stream -- str )
-    [ "in" get dup [ blocking-read-line ] when ] bind ;M
+    [ "in" get dup [ blocking-read-line ] when ] bind ;
 
 M: fd-stream fread# ( count stream -- str )
-    [ "in" get dup [ blocking-read# ] [ nip ] ifte ] bind ;M
+    [ "in" get dup [ blocking-read# ] [ nip ] ifte ] bind ;
 
 M: fd-stream fflush ( stream -- )
-    [ "out" get [ blocking-flush ] when* ] bind ;M
+    [ "out" get [ blocking-flush ] when* ] bind ;
 
 M: fd-stream fauto-flush ( stream -- )
-    drop ;M
+    drop ;
 
 M: fd-stream fclose ( -- )
     [
         "out" get [ dup blocking-flush close-port ] when*
         "in" get [ close-port ] when*
-    ] bind ;M
+    ] bind ;
 
 C: fd-stream ( in out -- stream )
-    [ "out" set "in" set ] extend ;C
+    [ "out" set "in" set ] extend ;
 
 : <filecr> ( path -- stream )
     t f open-file <fd-stream> ;
index 6815d64ca5c57476889f7eff3ae4552f47407279..0c5602914513c1e044323501907e147c63fc93eb 100644 (file)
@@ -51,16 +51,16 @@ GENERIC: fclose      ( stream -- )
 TRAITS: string-output-stream
 
 M: string-output-stream fwrite-attr ( string style stream -- )
-    [ drop "buf" get sbuf-append ] bind ;M
+    [ drop "buf" get sbuf-append ] bind ;
 
 M: string-output-stream fclose ( stream -- )
-    drop ;M
+    drop ;
 
 M: string-output-stream fflush ( stream -- )
-    drop ;M
+    drop ;
 
 M: string-output-stream fauto-flush ( stream -- )
-    drop ;M
+    drop ;
 
 : stream>str ( stream -- string )
     #! Returns the string written to the given string output
@@ -69,4 +69,4 @@ M: string-output-stream fauto-flush ( stream -- )
 
 C: string-output-stream ( size -- stream )
     #! Creates a new stream for writing to a string buffer.
-    [ <sbuf> "buf" set ] extend ;C
+    [ <sbuf> "buf" set ] extend ;
index 060974acd553da14130dab2ddc9ca7d15c96493d..5b55ff9d08d6e8bf5c23679f904afb1f20f898d2 100644 (file)
@@ -151,10 +151,7 @@ USE: math
 : url-quotable? ( ch -- ? )
     #! In a URL, can this character be used without
     #! URL-encoding?
-    [
-        [ letter?              ] [ drop t ]
-        [ LETTER?              ] [ drop t ]
-        [ digit?               ] [ drop t ]
-        [ "/_?." str-contains? ] [ drop t ]
-        [                      ] [ drop f ]
-    ] cond ;
+    dup letter?
+    over LETTER? or
+    over digit? or
+    swap "/_?." str-contains? or ;
index f287357e18cbf603b1b769a46a2784d233d72ae9..737b2cec12f121fb4c42019a09ae63a849602b20 100644 (file)
@@ -144,11 +144,11 @@ IN: syntax
 
 : :
     #! Begin a word definition. Word name follows.
-    CREATE [ ] "in-definition" on ; parsing
+    CREATE [ define-compound ] [ ] "in-definition" on ; parsing
 
 : ;
     #! End a word definition.
-    "in-definition" off reverse define-compound ; parsing
+    "in-definition" off reverse swap call ; parsing
 
 ! Symbols
 : SYMBOL:
index 004cbb30f7ae40763f92a416892ac7f903d49253..c642aca08245be9155de6c79678c6b8f4285c67f 100644 (file)
@@ -6,7 +6,7 @@ USE: test
 USE: kernel
 
 TRAITS: test-traits
-C: test-traits ;C
+C: test-traits ;
 
 [ t ] [ <test-traits> test-traits? ] unit-test
 [ f ] [ "hello" test-traits? ] unit-test
@@ -14,20 +14,20 @@ C: test-traits ;C
 
 GENERIC: foo
 
-M: test-traits foo drop 12 ;M
+M: test-traits foo drop 12 ;
 
 TRAITS: another-test
-C: another-test ;C
+C: another-test ;
 
-M: another-test foo drop 13 ;M
+M: another-test foo drop 13 ;
 
 [ 12 ] [ <test-traits> foo ] unit-test
 [ 13 ] [ <another-test> foo ] unit-test
 
 TRAITS: quux
-C: quux ;C
+C: quux ;
 
-M: quux foo "foo" swap hash ;M
+M: quux foo "foo" swap hash ;
 
 [
     "Hi"
@@ -38,7 +38,7 @@ M: quux foo "foo" swap hash ;M
 ] unit-test
 
 TRAITS: ctr-test
-C: ctr-test [ 5 "x" set ] extend ;C
+C: ctr-test [ 5 "x" set ] extend ;
 
 [
     5
@@ -47,12 +47,12 @@ C: ctr-test [ 5 "x" set ] extend ;C
 ] unit-test
 
 TRAITS: del1
-C: del1 ;C
+C: del1 ;
 
 GENERIC: super
-M: del1 super drop 5 ;M
+M: del1 super drop 5 ;
 
 TRAITS: del2
-C: del2 ( delegate -- del2 ) [ delegate set ] extend ;C
+C: del2 ( delegate -- del2 ) [ delegate set ] extend ;
 
 [ 5 ] [ <del1> <del2> super ] unit-test
index 386018deec0dfbddf8ff91ca6071dfb7fc2bdf08..66511cd005103bc7f6736c55796040fd9787db72 100644 (file)
@@ -45,6 +45,3 @@ USE: test
 [ [ [ "one" + ] [ "four" * ] ] ] [
     "three" "quot-alist" get remove-assoc
 ] unit-test
-
-[ [ "one" "three" "four" ] [ [ + ] [ - ] [ * ] ] ]
-[ "quot-alist" get unzip ] unit-test
index f040f3242084f27f57d62517dc3e7efd64deeb79..9d82af3315d883c4234e2224ee5dad886a330b5a 100644 (file)
@@ -25,11 +25,3 @@ USE: test
 
 [ [ 1 2 ]   ] [ 1 2   2list  ] unit-test
 [ [ 1 2 3 ] ] [ 1 2 3 3list  ] unit-test
-
-[ [ "car1" | "cdr1" ] [ "car2" | "cdr2" ] ]
-[ "car1" "car2" "cdr1" "cdr2" 2cons ]
-unit-test
-
-[ [ "car1" | "cdr1" ] [ "car2" | "cdr2" ] ]
-[ "cdr1" "cdr2" "car1" "car2" 2swons ]
-unit-test
index fce52f384ef4a4dc7336425f06b10d76427eb316..e864c6d706d4700391727e7ed3b2c2fe1e42ef50 100644 (file)
@@ -15,19 +15,19 @@ M: xyzzy-stream fwrite-attr ( str style stream -- )
         drop "<" delegate get fwrite
         delegate get fwrite
         ">" delegate get fwrite
-    ] bind ;M
+    ] bind ;
 
 M: xyzzy-stream fclose ( stream -- )
-    drop ;M
+    drop ;
 
 M: xyzzy-stream fflush ( stream -- )
-    drop ;M
+    drop ;
 
 M: xyzzy-stream fauto-flush ( stream -- )
-    drop ;M
+    drop ;
 
 C: xyzzy-stream ( stream -- stream )
-    [ delegate set ] extend ;C
+    [ delegate set ] extend ;
 
 [
     "<xyzzy>"
index b851c698d2eb5c25b81e5fa88f3f9740fd2ef79d..87db36e0ef09fb527d6f3e558efd7f1835e7d40d 100644 (file)
@@ -80,16 +80,16 @@ USE: listener
 TRAITS: jedit-stream
 
 M: jedit-stream freadln ( stream -- str )
-    [ CHAR: r write flush read-big-endian-32 read# ] bind ;M
+    [ CHAR: r write flush read-big-endian-32 read# ] bind ;
 
 M: jedit-stream fwrite-attr ( str style stream -- )
-    [ [ default-style ] unless* jedit-write-attr ] bind ;M
+    [ [ default-style ] unless* jedit-write-attr ] bind ;
 
 M: jedit-stream fflush ( stream -- )
-    [ CHAR: f write flush ] bind ;M
+    [ CHAR: f write flush ] bind ;
 
 C: jedit-stream ( stream -- stream )
-    [ dup delegate set stdio set ] extend ;C
+    [ dup delegate set stdio set ] extend ;
 
 : stream-server ( -- )
     #! Execute this in the inferior Factor.
index 351681025424238fcff2a98dffb63af1ed1b29ba..a955940bf1c6fcc258f2f4ce36e9e58dc1b009fc 100644 (file)
 
 USE: kernel
 USE: math
+USE: generic
 
-IN: kernel-internals
-
-: fixnum-tag  BIN: 000 ; inline
-: word-tag    BIN: 001 ; inline
-: cons-tag    BIN: 010 ; inline
-: object-tag  BIN: 011 ; inline
-: ratio-tag   BIN: 100 ; inline
-: complex-tag BIN: 101 ; inline
-: header-tag  BIN: 110 ; inline
-
-: f-type      6  ; inline
-: t-type      7  ; inline
-: array-type  8  ; inline
-: bignum-type 9  ; inline
-: float-type  10 ; inline
-: vector-type 11 ; inline
-: string-type 12 ; inline
-: sbuf-type   13 ; inline
-: port-type   14 ; inline
-: dll-type    15 ; inline
-: alien-type  16 ; inline
-
-IN: math         : fixnum?  ( obj -- ? ) type fixnum-tag  eq? ;
-IN: words        : word?    ( obj -- ? ) type word-tag    eq? ;
-IN: lists        : cons?    ( obj -- ? ) type cons-tag    eq? ;
-IN: math         : ratio?   ( obj -- ? ) type ratio-tag   eq? ;
-IN: math         : complex? ( obj -- ? ) type complex-tag eq? ;
-IN: math         : bignum?  ( obj -- ? ) type bignum-type eq? ;
-IN: math         : float?   ( obj -- ? ) type float-type  eq? ;
-IN: vectors      : vector?  ( obj -- ? ) type vector-type eq? ;
-IN: strings      : string?  ( obj -- ? ) type string-type eq? ;
-IN: strings      : sbuf?    ( obj -- ? ) type sbuf-type   eq? ;
-IN: io-internals : port?    ( obj -- ? ) type port-type   eq? ;
-IN: alien        : dll?     ( obj -- ? ) type dll-type    eq? ;
-IN: alien        : alien?   ( obj -- ? ) type alien-type  eq? ;
+IN: vectors SYMBOL: vector
+IN: math         BUILTIN: fixnum  0
+IN: words        BUILTIN: word    1
+IN: lists        BUILTIN: cons    2
+IN: math         BUILTIN: ratio   4
+IN: math         BUILTIN: complex 5
+IN: math         BUILTIN: bignum  9
+IN: math         BUILTIN: float   10
+IN: vectors      BUILTIN: vector  11
+IN: strings      BUILTIN: string  12
+IN: strings      BUILTIN: sbuf    13
+IN: io-internals BUILTIN: port    14
+IN: alien        BUILTIN: dll     15
+IN: alien        BUILTIN: alien   16
 
 IN: kernel
 
index fa0647ff7e7adc5169b0abd31d3f46560b89c0cc..337d373bcd87a7ba779dded819e6448846d4b8eb 100644 (file)
@@ -42,11 +42,12 @@ USE: strings
     swap set-word-plist ;
 
 : ?word-primitive ( obj -- prim/0 )
-    dup word? [ word-primitive ] [ drop 0 ] ifte ;
+    dup word? [ word-primitive ] [ drop -1 ] ifte ;
 
 : compound?  ( obj -- ? ) ?word-primitive 1 = ;
 : primitive? ( obj -- ? ) ?word-primitive 2 > ;
 : symbol?    ( obj -- ? ) ?word-primitive 2 = ;
+: undefined? ( obj -- ? ) ?word-primitive 0 = ;
 
 : word ( -- word ) global [ "last-word" get ] bind ;
 : set-word ( word -- ) global [ "last-word" set ] bind ;