]> gitweb.factorcode.org Git - factor.git/commitdiff
reworked bootstrap code, a lot of cleanups
authorSlava Pestov <slava@factorcode.org>
Wed, 15 Dec 2004 21:57:29 +0000 (21:57 +0000)
committerSlava Pestov <slava@factorcode.org>
Wed, 15 Dec 2004 21:57:29 +0000 (21:57 +0000)
41 files changed:
examples/more-random.factor
factor/jedit/FactorPlugin.java
library/bootstrap/boot-stage2.factor
library/bootstrap/boot.factor
library/bootstrap/cross-compiler.factor [deleted file]
library/bootstrap/image.factor
library/bootstrap/init.factor
library/bootstrap/primitives.factor [new file with mode: 0644]
library/cli.factor
library/combinators.factor
library/compiler/alien.factor
library/compiler/linearizer.factor
library/cons.factor
library/errors.factor
library/generic/generic.factor
library/generic/traits.factor
library/hashtables.factor
library/io/files.factor
library/io/io-internals.factor
library/io/stream.factor
library/kernel.factor
library/lists.factor
library/math/generic.factor
library/namespaces.factor
library/sdl/hsv.factor
library/strings.factor
library/syntax/parse-syntax.factor
library/syntax/parser.factor
library/syntax/unparser.factor
library/test/benchmark/sort.factor
library/test/inspector.factor
library/test/lists/combinators.factor
library/test/lists/lists.factor
library/test/namespaces.factor
library/test/test.factor
library/test/words.factor
library/types.factor [deleted file]
library/vectors.factor
library/vocabularies.factor
library/words.factor
native/types.h

index bbba2966fee1abf7507766c99483dd7eca498424..c9d9f3357ed757c1364e5d9f0facec2f304f3048 100644 (file)
@@ -5,6 +5,13 @@ USE: math
 USE: test
 USE: namespaces
 
+: nth ( n list -- list[n] )
+    #! nth element of a proper list.
+    #! Supplying n <= 0 pushes the first element of the list.
+    #! Supplying an argument beyond the end of the list raises
+    #! an error.
+    swap [ cdr ] times car ;
+
 : random-element ( list -- random )
     #! Returns a random element from the given list.
     dup >r length pred 0 swap random-int r> nth ;
@@ -85,4 +92,8 @@ USE: namespaces
         "random-pairs" get
         check-random-subset
     ] unit-test
+
+    [ 1 ] [  -1 [ 1 2 ] nth ] unit-test
+    [ 1 ] [  0  [ 1 2 ] nth ] unit-test
+    [ 2 ] [  1  [ 1 2 ] nth ] unit-test
 ] with-scope
index 23cbadc4778c294141ed88e90b9f95438090b7c9..e556b70560ad1fcc2c2d5b5bf9cb965fba17cbfa 100644 (file)
@@ -170,32 +170,33 @@ public class FactorPlugin extends EditPlugin
                getExternalInstance().eval(cmd);
        } //}}}
 
-       //{{{ factorWord() method
+       //{{{ lookupWord() method
        /**
-        * Build a Factor expression for pushing the selected word on the stack
+        * Look up the given Factor word in the vocabularies USE:d in the given view.
         */
-       public static String factorWord(FactorWord word)
+       public static FactorWord lookupWord(View view, String word)
        {
-               return FactorReader.unparseObject(word.name)
-                       + " [ " + FactorReader.unparseObject(word.vocabulary)
-                       + " ] search";
+               SideKickParsedData data = SideKickParsedData.getParsedData(view);
+               if(data instanceof FactorParsedData)
+               {
+                       FactorParsedData fdata = (FactorParsedData)data;
+                       return getExternalInstance().searchVocabulary(fdata.use,word);
+               }
+               else
+                       return null;
        } //}}}
 
        //{{{ factorWord() method
        /**
-        * Build a Factor expression for pushing the selected word on the stack
+        * Look up the given Factor word in the vocabularies USE:d in the given view.
         */
-       public static String factorWord(View view)
+       public static String factorWord(View view, String word)
        {
-               JEditTextArea textArea = view.getTextArea();
                SideKickParsedData data = SideKickParsedData
                        .getParsedData(view);
                if(data instanceof FactorParsedData)
                {
                        FactorParsedData fdata = (FactorParsedData)data;
-                       String word = FactorPlugin.getWordAtCaret(textArea);
-                       if(word == null)
-                               return null;
                        return "\""
                                + FactorReader.charsToEscapes(word)
                                + "\" " + FactorReader.unparseObject(fdata.use)
@@ -204,6 +205,31 @@ public class FactorPlugin extends EditPlugin
                else
                        return null;
        } //}}}
+
+       //{{{ factorWord() method
+       /**
+        * Build a Factor expression for pushing the selected word on the stack
+        */
+       public static String factorWord(View view)
+       {
+               JEditTextArea textArea = view.getTextArea();
+               String word = FactorPlugin.getWordAtCaret(textArea);
+               if(word == null)
+                       return null;
+               else
+                       return factorWord(view,word);
+       } //}}}
+
+       //{{{ factorWord() method
+       /**
+        * Build a Factor expression for pushing the selected word on the stack
+        */
+       public static String factorWord(FactorWord word)
+       {
+               return FactorReader.unparseObject(word.name)
+                       + " [ " + FactorReader.unparseObject(word.vocabulary)
+                       + " ] search";
+       } //}}}
        
        //{{{ factorWordOutputOp() method
        /**
index 4dcba8c05de313a7d57a52ca454018b284781e71..4471d3012bb56fe585f38c930c1f90dbad77fbfe 100644 (file)
@@ -32,6 +32,7 @@ USE: parser
 USE: stdio\r
 \r
 "Cold boot in progress..." print\r
+\r
 [\r
     "/version.factor"\r
     "/library/stack.factor"\r
@@ -41,7 +42,6 @@ USE: stdio
     "/library/generic/builtin.factor"\r
     "/library/generic/predicate.factor"\r
     "/library/generic/traits.factor"\r
-    "/library/types.factor"\r
     "/library/math/math.factor"\r
     "/library/cons.factor"\r
     "/library/combinators.factor"\r
@@ -117,6 +117,7 @@ USE: stdio
     "/library/compiler/xt.factor"\r
     "/library/compiler/optimizer.factor"\r
     "/library/compiler/linearizer.factor"\r
+    "/library/compiler/simplifier.factor"\r
     "/library/compiler/generator.factor"\r
     "/library/compiler/compiler.factor"\r
     "/library/compiler/alien-types.factor"\r
@@ -131,7 +132,6 @@ USE: stdio
     "/library/sdl/hsv.factor"\r
 \r
     "/library/bootstrap/image.factor"\r
-    "/library/bootstrap/cross-compiler.factor"\r
 \r
     "/library/httpd/url-encoding.factor"\r
     "/library/httpd/html-tags.factor"\r
index 564b633a27ed3f4a9317623de3342b4781611b4f..e39c467513135b197289f848567aa367218557de 100644 (file)
@@ -32,57 +32,66 @@ USE: namespaces
 USE: stdio
 USE: kernel
 USE: vectors
+USE: words
+USE: hashtables
 
-primitives,
-[
-    "/version.factor"
-    "/library/stack.factor"
-    "/library/kernel.factor"
-    "/library/generic/generic.factor"
-    "/library/generic/object.factor"
-    "/library/generic/builtin.factor"
-    "/library/generic/predicate.factor"
-    "/library/generic/traits.factor"
-    "/library/types.factor"
-    "/library/combinators.factor"
-    "/library/math/math.factor"
-    "/library/cons.factor"
-    "/library/logic.factor"
-    "/library/vectors.factor"
-    "/library/lists.factor"
-    "/library/assoc.factor"
-    "/library/math/arithmetic.factor"
-    "/library/math/math-combinators.factor"
-    "/library/strings.factor"
-    "/library/hashtables.factor"
-    "/library/namespaces.factor"
-    "/library/list-namespaces.factor"
-    "/library/sbuf.factor"
-    "/library/continuations.factor"
-    "/library/errors.factor"
-    "/library/threads.factor"
-    "/library/io/stream.factor"
-    "/library/io/io-internals.factor"
-    "/library/io/stream-impl.factor"
-    "/library/io/stdio.factor"
-    "/library/words.factor"
-    "/library/vocabularies.factor"
-    "/library/syntax/parse-numbers.factor"
-    "/library/syntax/parser.factor"
-    "/library/syntax/parse-syntax.factor"
-    "/library/syntax/parse-stream.factor"
-    "/library/math/generic.factor"
-    "/library/bootstrap/init.factor"
-] [
-    cross-compile-resource
-] each
+"/library/bootstrap/primitives.factor" run-resource
+"/version.factor" run-resource
+"/library/stack.factor" run-resource
+"/library/combinators.factor" run-resource
+"/library/kernel.factor" run-resource
+"/library/logic.factor" run-resource
+"/library/cons.factor" run-resource
+"/library/assoc.factor" run-resource
+"/library/math/generic.factor" run-resource
+"/library/words.factor" run-resource
+"/library/math/arithmetic.factor" run-resource
+"/library/math/math-combinators.factor" run-resource
+"/library/math/math.factor" run-resource
+"/library/lists.factor" run-resource
+"/library/vectors.factor" run-resource
+"/library/strings.factor" run-resource
+"/library/hashtables.factor" run-resource
+"/library/namespaces.factor" run-resource
+"/library/list-namespaces.factor" run-resource
+"/library/sbuf.factor" run-resource
+"/library/errors.factor" run-resource
+"/library/continuations.factor" run-resource
+"/library/threads.factor" run-resource
+"/library/io/stream.factor" run-resource
+"/library/io/stdio.factor" run-resource
+"/library/io/io-internals.factor" run-resource
+"/library/io/stream-impl.factor" run-resource
+"/library/vocabularies.factor" run-resource
+"/library/syntax/parse-numbers.factor" run-resource
+"/library/syntax/parser.factor" run-resource
+"/library/syntax/parse-stream.factor" run-resource
 
-IN: init
-DEFER: boot
+! A bootstrapping trick. See doc/bootstrap.txt.
+vocabularies get [
+    "generic" off
+] bind
 
-[
-    boot
-    "Good morning!" print
-    flush
-    "/library/bootstrap/boot-stage2.factor" run-resource
-] boot-quot set
+"/library/generic/generic.factor" run-resource
+"/library/generic/object.factor" run-resource
+"/library/generic/builtin.factor" run-resource
+"/library/generic/predicate.factor" run-resource
+"/library/generic/traits.factor" run-resource
+
+"/library/bootstrap/init.factor" run-resource
+
+! A bootstrapping trick. See doc/bootstrap.txt.
+"/library/syntax/parse-syntax.factor" run-resource
+
+vocabularies get [
+    "!syntax" get "syntax" set
+    "!syntax" off
+
+    "syntax" get [
+        cdr dup word? [
+            "syntax" "vocabulary" set-word-property
+        ] [
+            drop
+        ] ifte
+    ] hash-each
+] bind
diff --git a/library/bootstrap/cross-compiler.factor b/library/bootstrap/cross-compiler.factor
deleted file mode 100644 (file)
index 6325cc5..0000000
+++ /dev/null
@@ -1,431 +0,0 @@
-! :folding=none:collapseFolds=1:
-
-! $Id$
-!
-! Copyright (C) 2004 Slava Pestov.
-! 
-! Redistribution and use in source and binary forms, with or without
-! modification, are permitted provided that the following conditions are met:
-! 
-! 1. Redistributions of source code must retain the above copyright notice,
-!    this list of conditions and the following disclaimer.
-! 
-! 2. Redistributions in binary form must reproduce the above copyright notice,
-!    this list of conditions and the following disclaimer in the documentation
-!    and/or other materials provided with the distribution.
-! 
-! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-USE: errors
-USE: kernel
-USE: lists
-USE: math
-USE: math-internals
-USE: namespaces
-USE: parser
-USE: stdio
-USE: streams
-USE: strings
-USE: vectors
-USE: words
-
-IN: alien
-DEFER: dlopen
-DEFER: dlsym
-DEFER: dlsym-self
-DEFER: dlclose
-DEFER: <alien>
-DEFER: <local-alien>
-DEFER: alien-cell
-DEFER: set-alien-cell
-DEFER: alien-4
-DEFER: set-alien-4
-DEFER: alien-2
-DEFER: set-alien-2
-DEFER: alien-1
-DEFER: set-alien-1
-
-IN: compiler
-DEFER: set-compiled-byte
-DEFER: set-compiled-cell
-DEFER: compiled-offset
-DEFER: set-compiled-offset
-DEFER: literal-top
-DEFER: set-literal-top
-
-IN: kernel
-DEFER: gc-time
-DEFER: getenv
-DEFER: setenv
-DEFER: save-image
-DEFER: room
-DEFER: os-env
-DEFER: type
-DEFER: size
-DEFER: address
-DEFER: heap-stats
-DEFER: drop
-DEFER: dup
-DEFER: over
-DEFER: pick
-DEFER: swap
-DEFER: >r
-DEFER: r>
-DEFER: ifte
-DEFER: call
-DEFER: datastack
-DEFER: callstack
-DEFER: set-datastack
-DEFER: set-callstack
-
-IN: strings
-DEFER: str=
-DEFER: str-hashcode
-DEFER: sbuf=
-DEFER: sbuf-hashcode
-DEFER: sbuf-clone
-
-IN: files
-DEFER: stat
-DEFER: (directory)
-DEFER: cwd
-DEFER: cd
-
-IN: io-internals
-DEFER: open-file
-DEFER: client-socket
-DEFER: server-socket
-DEFER: close-port
-DEFER: add-accept-io-task
-DEFER: accept-fd
-DEFER: can-read-line?
-DEFER: add-read-line-io-task
-DEFER: read-line-fd-8
-DEFER: can-read-count?
-DEFER: add-read-count-io-task
-DEFER: read-count-fd-8
-DEFER: can-write?
-DEFER: add-write-io-task
-DEFER: write-fd-8
-DEFER: add-copy-io-task
-DEFER: pending-io-error
-DEFER: next-io-task
-
-IN: math
-DEFER: fraction>
-
-IN: math-internals
-DEFER: arithmetic-type
-DEFER: fixnum=
-DEFER: fixnum+
-DEFER: fixnum-
-DEFER: fixnum*
-DEFER: fixnum/i
-DEFER: fixnum/f
-DEFER: fixnum-mod
-DEFER: fixnum/mod
-DEFER: fixnum-bitand
-DEFER: fixnum-bitor
-DEFER: fixnum-bitxor
-DEFER: fixnum-bitnot
-DEFER: fixnum-shift
-DEFER: fixnum<
-DEFER: fixnum<=
-DEFER: fixnum>
-DEFER: fixnum>=
-DEFER: bignum=
-DEFER: bignum+
-DEFER: bignum-
-DEFER: bignum*
-DEFER: bignum/i
-DEFER: bignum/f
-DEFER: bignum-mod
-DEFER: bignum/mod
-DEFER: bignum-bitand
-DEFER: bignum-bitor
-DEFER: bignum-bitxor
-DEFER: bignum-bitnot
-DEFER: bignum-shift
-DEFER: bignum<
-DEFER: bignum<=
-DEFER: bignum>
-DEFER: bignum>=
-DEFER: float=
-DEFER: float+
-DEFER: float-
-DEFER: float*
-DEFER: float/f
-DEFER: float<
-DEFER: float<=
-DEFER: float>
-DEFER: float>=
-DEFER: facos
-DEFER: fasin
-DEFER: fatan
-DEFER: fatan2
-DEFER: fcos
-DEFER: fexp
-DEFER: fcosh
-DEFER: flog
-DEFER: fpow
-DEFER: fsin
-DEFER: fsinh
-DEFER: fsqrt
-
-IN: parser
-DEFER: str>float
-
-IN: profiler
-DEFER: call-profiling
-DEFER: call-count
-DEFER: set-call-count
-DEFER: allot-profiling
-DEFER: allot-count
-DEFER: set-allot-count
-
-IN: random
-DEFER: init-random
-DEFER: (random-int)
-
-IN: words
-DEFER: <word>
-DEFER: word-hashcode
-DEFER: word-xt
-DEFER: set-word-xt
-DEFER: word-primitive
-DEFER: set-word-primitive
-DEFER: word-parameter
-DEFER: set-word-parameter
-DEFER: word-plist
-DEFER: set-word-plist
-DEFER: compiled?
-
-IN: unparser
-DEFER: (unparse-float)
-
-IN: image
-
-: primitives, ( -- )
-    2 [
-        execute
-        call
-        ifte
-        cons
-        car
-        cdr
-        <vector>
-        vector-length
-        set-vector-length
-        vector-nth
-        set-vector-nth
-        str-length
-        str-nth
-        str-compare
-        str=
-        str-hashcode
-        index-of*
-        substring
-        str-reverse
-        <sbuf>
-        sbuf-length
-        set-sbuf-length
-        sbuf-nth
-        set-sbuf-nth
-        sbuf-append
-        sbuf>str
-        sbuf-reverse
-        sbuf-clone
-        sbuf=
-        sbuf-hashcode
-        arithmetic-type
-        number?
-        >fixnum
-        >bignum
-        >float
-        numerator
-        denominator
-        fraction>
-        str>float
-        (unparse-float)
-        float>bits
-        real
-        imaginary
-        rect>
-        fixnum=
-        fixnum+
-        fixnum-
-        fixnum*
-        fixnum/i
-        fixnum/f
-        fixnum-mod
-        fixnum/mod
-        fixnum-bitand
-        fixnum-bitor
-        fixnum-bitxor
-        fixnum-bitnot
-        fixnum-shift
-        fixnum<
-        fixnum<=
-        fixnum>
-        fixnum>=
-        bignum=
-        bignum+
-        bignum-
-        bignum*
-        bignum/i
-        bignum/f
-        bignum-mod
-        bignum/mod
-        bignum-bitand
-        bignum-bitor
-        bignum-bitxor
-        bignum-bitnot
-        bignum-shift
-        bignum<
-        bignum<=
-        bignum>
-        bignum>=
-        float=
-        float+
-        float-
-        float*
-        float/f
-        float<
-        float<=
-        float>
-        float>=
-        facos
-        fasin
-        fatan
-        fatan2
-        fcos
-        fexp
-        fcosh
-        flog
-        fpow
-        fsin
-        fsinh
-        fsqrt
-        <word>
-        word-hashcode
-        word-xt
-        set-word-xt
-        word-primitive
-        set-word-primitive
-        word-parameter
-        set-word-parameter
-        word-plist
-        set-word-plist
-        call-profiling
-        call-count
-        set-call-count
-        allot-profiling
-        allot-count
-        set-allot-count
-        compiled?
-        drop
-        dup
-        swap
-        over
-        pick
-        >r
-        r>
-        eq?
-        getenv
-        setenv
-        open-file
-        stat
-        (directory)
-        garbage-collection
-        gc-time
-        save-image
-        datastack
-        callstack
-        set-datastack
-        set-callstack
-        exit*
-        client-socket
-        server-socket
-        close-port
-        add-accept-io-task
-        accept-fd
-        can-read-line?
-        add-read-line-io-task
-        read-line-fd-8
-        can-read-count?
-        add-read-count-io-task
-        read-count-fd-8
-        can-write?
-        add-write-io-task
-        write-fd-8
-        add-copy-io-task
-        pending-io-error
-        next-io-task
-        room
-        os-env
-        millis
-        init-random
-        (random-int)
-        type
-        size
-        cwd
-        cd
-        compiled-offset
-        set-compiled-offset
-        set-compiled-cell
-        set-compiled-byte
-        literal-top
-        set-literal-top
-        address
-        dlopen
-        dlsym
-        dlsym-self
-        dlclose
-        <alien>
-        <local-alien>
-        alien-cell
-        set-alien-cell
-        alien-4
-        set-alien-4
-        alien-2
-        set-alien-2
-        alien-1
-        set-alien-1
-        heap-stats
-        throw
-    ] [
-        USE: stack swap succ tuck f define,
-    ] each drop ;
-
-: make-image ( name -- )
-    #! Make an image for the C interpreter.
-    [
-        "/library/bootstrap/boot.factor" run-resource
-    ] with-image
-
-    swap write-image ;
-
-: make-images ( -- )
-    "64-bits" off
-    "big-endian" off "boot.image.le32" make-image
-    "big-endian" on  "boot.image.be32" make-image
-    "64-bits" on
-    "big-endian" off "boot.image.le64" make-image
-    "big-endian" on  "boot.image.be64" make-image
-    "64-bits" off ;
-
-: cross-compile-resource ( resource -- )
-    [
-        ! Change behavior of ; and SYMBOL:
-        [ define, ] "define-hook" set
-        run-resource
-    ] with-scope ;
index 4d0afde88cd0cf36a0ef2f348dab7bd3bbd3d762..adc60e4d25eb9400ac5f3aba5edaaf53f2adc1a5 100644 (file)
@@ -55,10 +55,7 @@ USE: test
 USE: vectors
 USE: unparser
 USE: words
-
-USE: stack
-USE: combinators
-USE: logic
+USE: parser
 
 ! The image being constructed; a vector of word-size integers
 SYMBOL: image
@@ -193,24 +190,49 @@ M: f ' ( obj -- ptr )
 
 ( Words )
 
-: word, ( word -- pointer )
-    word-tag here-as >r word-tag >header emit
-    hashcode emit ( hashcode )
-    0 emit r> ;
+: make-plist ( word -- plist )
+    [
+        dup word-name "name" swons ,
+        dup word-vocabulary "vocabulary" swons ,
+        parsing? [ t "parsing" swons , ] when
+    ] make-list ;
 
-! This is to handle mutually recursive words
+: word, ( word -- )
+    [
+        word-tag >header ,
+        dup hashcode ,
+        0 ,
+        dup word-primitive ,
+        dup word-parameter ' ,
+        dup make-plist ' ,
+        0 ,
+        0 ,
+    ] make-list
+    swap word-tag here-as pool-object
+    [ emit ] each ;
+
+: word-error ( word msg -- )
+    [
+        ,
+        dup word-vocabulary ,
+        " " ,
+        word-name ,
+    ] make-string throw ;
+
+: transfer-word ( word -- word )
+    #! This is a hack. See doc/bootstrap.txt.
+    dup dup word-name swap word-vocabulary unit search
+    dup [
+        nip
+    ] [
+        drop "Missing DEFER: " word-error
+    ] ifte ;
 
 : fixup-word ( word -- offset )
     dup pooled-object dup [
         nip
     ] [
-        drop
-        [
-            "Not in image: " ,
-            dup word-vocabulary ,
-            " " ,
-            word-name ,
-        ] make-string throw
+        drop "Not in image: " word-error
     ] ifte ;
 
 : fixup-words ( -- )
@@ -219,7 +241,7 @@ M: f ' ( obj -- ptr )
     ] vector-map image set ;
 
 M: word ' ( word -- pointer )
-    dup pooled-object dup [ nip ] [ drop ] ifte ;
+    transfer-word dup pooled-object dup [ nip ] [ drop ] ifte ;
 
 ( Conses )
 
@@ -263,40 +285,6 @@ M: string ' ( string -- pointer )
         drop dup emit-string dup >r pool-object r>
     ] ifte ;
 
-( Word definitions )
-
-: (vocabulary) ( name -- vocab )
-    #! Vocabulary for target image.
-    dup "vocabularies" get hash dup [
-        nip
-    ] [
-        drop >r namespace-buckets <hashtable> dup r>
-        "vocabularies" get set-hash
-    ] ifte ;
-
-: (word+) ( word -- )
-    #! Add the word to a vocabulary in the target image.
-    dup word-name over word-vocabulary 
-    (vocabulary) set-hash ;
-
-: emit-plist ( word -- plist )
-    [
-        dup word-name "name" swons ,
-        dup word-vocabulary "vocabulary" swons ,
-        "parsing" word-property [ t "parsing" swons , ] when
-    ] make-list ' ;
-
-: define, ( word primitive parameter -- )
-    #! Write a word definition to the image.
-    ' >r >r dup (word+) dup emit-plist >r
-    dup word, pool-object
-    r> ( -- plist )
-    r> ( primitive -- ) emit
-    r> ( parameter -- ) emit
-    ( plist -- ) emit
-    0 emit ( padding )
-    0 emit ;
-
 ( Arrays and vectors )
 
 : emit-array ( list -- pointer )
@@ -317,35 +305,29 @@ M: vector ' ( vector -- pointer )
 
 ( End of the image )
 
-: vocabularies, ( -- )
-    #! Produces code with stack effect ( -- vocabularies ).
-    #! This code sets up vocabulary hash tables.
-    \ <namespace> ,
+: vocabularies, ( vocabularies -- )
     [
-        "vocabularies" get [
-            uncons hash>alist , \ alist>hash , , \ set ,
-        ] hash-each
-    ] make-list ,
-    \ extend , ;
+        cdr dup vector? [
+            [
+                cdr dup word? [ word, ] [ drop ] ifte
+            ] hash-each
+        ] [
+            drop
+        ] ifte
+    ] hash-each ;
 
 : global, ( -- )
-    #! Produces code with stack effect ( vocabularies -- ).
-    <namespace> ' global-offset fixup
-    "vocabularies" ,
-    \ global ,
-    \ set-hash , ;
-
-: hash-quot ( -- quot )
-    #! Generate a quotation to generate vocabulary and global
-    #! namespace hashtables.
-    [ vocabularies, global, ] make-list ;
+    vocabularies get
+    dup vocabularies,
+    <namespace> [ vocabularies set ] extend '
+    global-offset fixup ;
 
 : boot, ( quot -- )
-    boot-quot get append ' boot-quot-offset fixup ;
+    boot-quot get ' boot-quot-offset fixup ;
 
 : end ( -- )
-    hash-quot
     boot,
+    global,
     fixup-words
     here base - heap-size-offset fixup ;
 
@@ -373,7 +355,6 @@ M: vector ' ( vector -- pointer )
     [
         300000 <vector> image set
         521 <hashtable> "objects" set
-        namespace-buckets <hashtable> "vocabularies" set
         ! Note that this is a vector that we can side-effect,
         ! since ; ends up using this variable from nested
         ! parser namespaces.
@@ -386,3 +367,21 @@ M: vector ' ( vector -- pointer )
     [ begin call end ] with-minimal-image ;
 
 : test-image ( quot -- ) with-image vector>list . ;
+
+: make-image ( name -- )
+    #! Make an image for the C interpreter.
+    [
+        "/library/bootstrap/boot.factor" run-resource
+        boot-quot set
+    ] with-image
+
+    swap write-image ;
+
+: make-images ( -- )
+    "64-bits" off
+    "big-endian" off "boot.image.le32" make-image
+    "big-endian" on  "boot.image.be32" make-image
+    "64-bits" on
+    "big-endian" off "boot.image.le64" make-image
+    "big-endian" on  "boot.image.be64" make-image
+    "64-bits" off ;
index 5e394005dddaccd4e144c6da230ccbab1a509516..dcc6f128c3edaa8d228c8785dd534737f958f63d 100644 (file)
@@ -26,8 +26,6 @@
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: init
-USE: compiler
-USE: errors
 USE: kernel
 USE: namespaces
 USE: parser
@@ -35,7 +33,6 @@ USE: stdio
 USE: streams
 USE: threads
 USE: words
-USE: vectors
 
 : boot ( -- )
     #! Initialize an interpreter with the basic services.
@@ -43,5 +40,11 @@ USE: vectors
     init-threads
     init-stdio
     "HOME" os-env [ "." ] unless* "~" set
-    "/" "/" set
     init-search-path ;
+
+[
+    boot
+    "Good morning!" print
+    flush
+    "/library/bootstrap/boot-stage2.factor" run-resource
+]
diff --git a/library/bootstrap/primitives.factor b/library/bootstrap/primitives.factor
new file mode 100644 (file)
index 0000000..5c1d1a4
--- /dev/null
@@ -0,0 +1,242 @@
+! :folding=none:collapseFolds=1:
+
+! $Id$
+!
+! Copyright (C) 2004 Slava Pestov.
+! 
+! Redistribution and use in source and binary forms, with or without
+! modification, are permitted provided that the following conditions are met:
+! 
+! 1. Redistributions of source code must retain the above copyright notice,
+!    this list of conditions and the following disclaimer.
+! 
+! 2. Redistributions in binary form must reproduce the above copyright notice,
+!    this list of conditions and the following disclaimer in the documentation
+!    and/or other materials provided with the distribution.
+! 
+! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+IN: image
+USE: kernel
+USE: lists
+USE: math
+USE: namespaces
+USE: parser
+USE: words
+USE: vectors
+USE: hashtables
+
+! Bring up a bare cross-compiling vocabulary.
+"syntax" vocab
+"generic" vocab
+
+! This symbol needs the same hashcode in the target as in the
+! host.
+vocabularies
+
+<namespace> vocabularies set
+vocabularies get [
+    reveal
+    "generic" set
+    "syntax" set
+] bind
+
+2 [
+    [ "words" | "execute" ]
+    [ "kernel" | "call" ]
+    [ "kernel" | "ifte" ]
+    [ "lists" | "cons" ]
+    [ "lists" | "car" ]
+    [ "lists" | "cdr" ]
+    [ "vectors" | "<vector>" ]
+    [ "vectors" | "vector-length" ]
+    [ "vectors" | "set-vector-length" ]
+    [ "vectors" | "vector-nth" ]
+    [ "vectors" | "set-vector-nth" ]
+    [ "strings" | "str-length" ]
+    [ "strings" | "str-nth" ]
+    [ "strings" | "str-compare" ]
+    [ "strings" | "str=" ]
+    [ "strings" | "str-hashcode" ]
+    [ "strings" | "index-of*" ]
+    [ "strings" | "substring" ]
+    [ "strings" | "str-reverse" ]
+    [ "strings" | "<sbuf>" ]
+    [ "strings" | "sbuf-length" ]
+    [ "strings" | "set-sbuf-length" ]
+    [ "strings" | "sbuf-nth" ]
+    [ "strings" | "set-sbuf-nth" ]
+    [ "strings" | "sbuf-append" ]
+    [ "strings" | "sbuf>str" ]
+    [ "strings" | "sbuf-reverse" ]
+    [ "strings" | "sbuf-clone" ]
+    [ "strings" | "sbuf=" ]
+    [ "strings" | "sbuf-hashcode" ]
+    [ "math-internals" | "arithmetic-type" ]
+    [ "math" | "number?" ]
+    [ "math" | ">fixnum" ]
+    [ "math" | ">bignum" ]
+    [ "math" | ">float" ]
+    [ "math" | "numerator" ]
+    [ "math" | "denominator" ]
+    [ "math" | "fraction>" ]
+    [ "parser" | "str>float" ]
+    [ "unparser" | "(unparse-float)" ]
+    [ "math" | "float>bits" ]
+    [ "math" | "real" ]
+    [ "math" | "imaginary" ]
+    [ "math" | "rect>" ]
+    [ "math-internals" | "fixnum=" ]
+    [ "math-internals" | "fixnum+" ]
+    [ "math-internals" | "fixnum-" ]
+    [ "math-internals" | "fixnum*" ]
+    [ "math-internals" | "fixnum/i" ]
+    [ "math-internals" | "fixnum/f" ]
+    [ "math-internals" | "fixnum-mod" ]
+    [ "math-internals" | "fixnum/mod" ]
+    [ "math-internals" | "fixnum-bitand" ]
+    [ "math-internals" | "fixnum-bitor" ]
+    [ "math-internals" | "fixnum-bitxor" ]
+    [ "math-internals" | "fixnum-bitnot" ]
+    [ "math-internals" | "fixnum-shift" ]
+    [ "math-internals" | "fixnum<" ]
+    [ "math-internals" | "fixnum<=" ]
+    [ "math-internals" | "fixnum>" ]
+    [ "math-internals" | "fixnum>=" ]
+    [ "math-internals" | "bignum=" ]
+    [ "math-internals" | "bignum+" ]
+    [ "math-internals" | "bignum-" ]
+    [ "math-internals" | "bignum*" ]
+    [ "math-internals" | "bignum/i" ]
+    [ "math-internals" | "bignum/f" ]
+    [ "math-internals" | "bignum-mod" ]
+    [ "math-internals" | "bignum/mod" ]
+    [ "math-internals" | "bignum-bitand" ]
+    [ "math-internals" | "bignum-bitor" ]
+    [ "math-internals" | "bignum-bitxor" ]
+    [ "math-internals" | "bignum-bitnot" ]
+    [ "math-internals" | "bignum-shift" ]
+    [ "math-internals" | "bignum<" ]
+    [ "math-internals" | "bignum<=" ]
+    [ "math-internals" | "bignum>" ]
+    [ "math-internals" | "bignum>=" ]
+    [ "math-internals" | "float=" ]
+    [ "math-internals" | "float+" ]
+    [ "math-internals" | "float-" ]
+    [ "math-internals" | "float*" ]
+    [ "math-internals" | "float/f" ]
+    [ "math-internals" | "float<" ]
+    [ "math-internals" | "float<=" ]
+    [ "math-internals" | "float>" ]
+    [ "math-internals" | "float>=" ]
+    [ "math-internals" | "facos" ]
+    [ "math-internals" | "fasin" ]
+    [ "math-internals" | "fatan" ]
+    [ "math-internals" | "fatan2" ]
+    [ "math-internals" | "fcos" ]
+    [ "math-internals" | "fexp" ]
+    [ "math-internals" | "fcosh" ]
+    [ "math-internals" | "flog" ]
+    [ "math-internals" | "fpow" ]
+    [ "math-internals" | "fsin" ]
+    [ "math-internals" | "fsinh" ]
+    [ "math-internals" | "fsqrt" ]
+    [ "words" | "<word>" ]
+    [ "words" | "word-hashcode" ]
+    [ "words" | "word-xt" ]
+    [ "words" | "set-word-xt" ]
+    [ "words" | "word-primitive" ]
+    [ "words" | "set-word-primitive" ]
+    [ "words" | "word-parameter" ]
+    [ "words" | "set-word-parameter" ]
+    [ "words" | "word-plist" ]
+    [ "words" | "set-word-plist" ]
+    [ "profiler" | "call-profiling" ]
+    [ "profiler" | "call-count" ]
+    [ "profiler" | "set-call-count" ]
+    [ "profiler" | "allot-profiling" ]
+    [ "profiler" | "allot-count" ]
+    [ "profiler" | "set-allot-count" ]
+    [ "words" | "compiled?" ]
+    [ "kernel" | "drop" ]
+    [ "kernel" | "dup" ]
+    [ "kernel" | "swap" ]
+    [ "kernel" | "over" ]
+    [ "kernel" | "pick" ]
+    [ "kernel" | ">r" ]
+    [ "kernel" | "r>" ]
+    [ "kernel" | "eq?" ]
+    [ "kernel" | "getenv" ]
+    [ "kernel" | "setenv" ]
+    [ "io-internals" | "open-file" ]
+    [ "files" | "stat" ]
+    [ "files" | "(directory)" ]
+    [ "kernel" | "garbage-collection" ]
+    [ "kernel" | "gc-time" ]
+    [ "kernel" | "save-image" ]
+    [ "kernel" | "datastack" ]
+    [ "kernel" | "callstack" ]
+    [ "kernel" | "set-datastack" ]
+    [ "kernel" | "set-callstack" ]
+    [ "kernel" | "exit*" ]
+    [ "io-internals" | "client-socket" ]
+    [ "io-internals" | "server-socket" ]
+    [ "io-internals" | "close-port" ]
+    [ "io-internals" | "add-accept-io-task" ]
+    [ "io-internals" | "accept-fd" ]
+    [ "io-internals" | "can-read-line?" ]
+    [ "io-internals" | "add-read-line-io-task" ]
+    [ "io-internals" | "read-line-fd-8" ]
+    [ "io-internals" | "can-read-count?" ]
+    [ "io-internals" | "add-read-count-io-task" ]
+    [ "io-internals" | "read-count-fd-8" ]
+    [ "io-internals" | "can-write?" ]
+    [ "io-internals" | "add-write-io-task" ]
+    [ "io-internals" | "write-fd-8" ]
+    [ "io-internals" | "add-copy-io-task" ]
+    [ "io-internals" | "pending-io-error" ]
+    [ "io-internals" | "next-io-task" ]
+    [ "kernel" | "room" ]
+    [ "kernel" | "os-env" ]
+    [ "kernel" | "millis" ]
+    [ "random" | "init-random" ]
+    [ "random" | "(random-int)" ]
+    [ "kernel" | "type" ]
+    [ "kernel" | "size" ]
+    [ "files" | "cwd" ]
+    [ "files" | "cd" ]
+    [ "compiler" | "compiled-offset" ]
+    [ "compiler" | "set-compiled-offset" ]
+    [ "compiler" | "set-compiled-cell" ]
+    [ "compiler" | "set-compiled-byte" ]
+    [ "compiler" | "literal-top" ]
+    [ "compiler" | "set-literal-top" ]
+    [ "kernel" | "address" ]
+    [ "alien" | "dlopen" ]
+    [ "alien" | "dlsym" ]
+    [ "alien" | "dlsym-self" ]
+    [ "alien" | "dlclose" ]
+    [ "alien" | "<alien>" ]
+    [ "alien" | "<local-alien>" ]
+    [ "alien" | "alien-cell" ]
+    [ "alien" | "set-alien-cell" ]
+    [ "alien" | "alien-4" ]
+    [ "alien" | "set-alien-4" ]
+    [ "alien" | "alien-2" ]
+    [ "alien" | "set-alien-2" ]
+    [ "alien" | "alien-1" ]
+    [ "alien" | "set-alien-1" ]
+    [ "kernel" | "heap-stats" ]
+    [ "errors" | "throw" ]
+] [
+    unswons create swap succ [ f define ] keep
+] each drop
index 8e74bd5682a4517b3d2bf66e62d23271f78a3f7a..9c6cc95dcdaa82c9078dad576c38ca84263f6168 100644 (file)
@@ -50,7 +50,7 @@ USE: words
 : run-user-init ( -- )
     #! Run user init file if it exists
     "user-init" get [
-        [ "~" get , "/" get , ".factor-" , "rc" , ] make-string
+        [ "~" get , "/" , ".factor-" , "rc" , ] make-string
         ?run-file
     ] when ;
 
index 290e00d096f49681a9656b823992758ce8e1d864..197fc7c0ebbc951ecc3dcb1c9e401ec6642d5287 100644 (file)
@@ -51,6 +51,7 @@ USE: lists
     #! Apply code to input.
     swap dup >r call r> swap ; inline
 
+IN: lists DEFER: uncons IN: kernel
 : cond ( x list -- )
     #! The list is of this form:
     #!
index cec3613168d7279da31e9db6346d11fb21a26646..35aa35cbd0e76a620131541d6297db083aaa7e65 100644 (file)
@@ -28,6 +28,7 @@
 IN: alien
 USE: compiler
 USE: errors
+USE: generic
 USE: inference
 USE: interpreter
 USE: kernel
@@ -37,6 +38,9 @@ USE: namespaces
 USE: parser
 USE: words
 
+BUILTIN: dll   15
+BUILTIN: alien 16
+
 : library ( name -- handle )
     "libraries" get [
         dup get dup dll? [
index a307262a4af65e126d6c0af22508d628987cf2e9..f9b2b05c7e95a56ff733c24c62ed37afd78b2517 100644 (file)
@@ -99,7 +99,7 @@ SYMBOL: #target ( part of jump table )
     gensym  dup t "label" set-word-property ;
 
 : label? ( obj -- ? )
-    dup word ? [ "label" word-property ] [ drop f ] ifte ;
+    dup word? [ "label" word-property ] [ drop f ] ifte ;
 
 : label, ( label -- )
     #label swons , ;
index a809ec06fecb4cb44e4cbfafcefbc6421be930a4..0a9befa4e73117692ed0245572f6121cba13ba14 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: lists
+USE: generic
 USE: kernel
 
+! This file contains vital list-related words that everything
+! else depends on, and is loaded early in bootstrap.
+! lists.factor has everything else.
+
+BUILTIN: cons 2
+
 : swons ( cdr car -- [ car | cdr ] )
     #! Push a new cons cell. If the cdr is f or a proper list,
     #! has the effect of prepending the car to the cdr.
@@ -50,3 +57,53 @@ USE: kernel
 
 : 2cdr ( cons cons -- car car )
     swap cdr swap cdr ;
+
+: last* ( list -- last )
+    #! Last cons of a list.
+    dup cdr cons? [ cdr last* ] when ;
+
+: last ( list -- last )
+    #! Last element of a list.
+    last* car ;
+
+: tail ( list -- tail )
+    #! Return the cdr of the last cons cell, or f.
+    dup [ last* cdr ] when ;
+
+: list? ( list -- ? )
+    #! Proper list test. A proper list is either f, or a cons
+    #! cell whose cdr is a proper list.
+    dup cons? [ tail ] when not ;
+
+: all? ( list pred -- ? )
+    #! Push if the predicate returns true for each element of
+    #! the list.
+    over [
+        dup >r swap uncons >r swap call [
+            r> r> all?
+        ] [
+            r> drop r> drop f
+        ] ifte
+    ] [
+        2drop t
+    ] ifte ; inline
+
+: (each) ( list quot -- list quot )
+    >r uncons r> tuck 2slip ; inline
+
+: each ( list quot -- )
+    #! Push each element of a proper list in turn, and apply a
+    #! quotation with effect ( X -- ) to each element.
+    over [ (each) each ] [ 2drop ] ifte ; inline
+
+: subset ( list quot -- list )
+    #! Applies a quotation with effect ( X -- ? ) to each
+    #! element of a list; all elements for which the quotation
+    #! returned a value other than f are collected in a new
+    #! list.
+    over [
+        over car >r (each)
+        rot >r subset r> [ r> swons ] [ r> drop ] ifte
+    ] [
+        drop
+    ] ifte ; inline
index 72f40d86e09d64a4993887ad7cf2980850c124cf..53eded4680e43256519e08950762871c2d56dfa1 100644 (file)
@@ -25,6 +25,9 @@
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+IN: kernel
+DEFER: callcc1
+
 IN: errors
 USE: kernel
 USE: lists
index 6ba89be5289724c092f7412a6df164d17d89a617..5c97b81423d0e245eecd2be3e00b042b89c877f7 100644 (file)
@@ -55,6 +55,9 @@ USE: vectors
 ! - metaclass: a metaclass is a symbol with a handful of word
 ! properties: "define-method" "builtin-types"
 
+: undefined-method
+    "No applicable method." throw ;
+
 : metaclass ( class -- metaclass )
     "metaclass" word-property ;
 
index a02943a12013e98a84879614acb02a15c8348622..518dc02db5d3fb15f13480859c44298d00376c86 100644 (file)
@@ -68,9 +68,6 @@ SYMBOL: delegate
 : init-traits-map ( word -- )
     <namespace> "traits-map" set-word-property ;
 
-: undefined-method
-    "No applicable method." throw ;
-
 : traits-dispatch ( 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
index 63238063be65b1032aabd260c7d6ac0fba8fccb1..db3cd9316a109a44308714df184fbce9a5c18153 100644 (file)
@@ -93,3 +93,27 @@ PREDICATE: vector hashtable ( obj -- ? )
 
 : alist>hash ( alist -- hash )
     37 <hashtable> swap [ unswons pick set-hash ] each ;
+
+: hash-map ( hash code -- hash )
+    #! Apply the code to each key/value pair of the hashtable,
+    #! collecting return values in a new hashtable.
+    >r hash>alist r> map alist>hash ;
+
+! In case I break hashing:
+
+! : hash ( key table -- value )
+!     hash>alist assoc ;
+! 
+! : set-hash ( value key table -- )
+!     dup vector-length [
+!         ( value key table index )
+!         >r 3dup r>
+!         ( value key table value key table index )
+!         [
+!             swap vector-nth
+!             ( value key table value key alist )
+!             set-assoc
+!         ] keep
+!         ( value key table new-assoc index )
+!         pick set-vector-nth
+!     ] times* 3drop ;
index ae97179635ef02e6b9439e06dbcf6038a24614c6..9cd1028932ceef5d58d685b68654ac509512e16e 100644 (file)
@@ -42,7 +42,7 @@ USE: strings
 
 : directory ( dir -- list )
     #! List a directory.
-    (directory) str-sort ;
+    (directory) [ str-lexi> ] sort ;
 
 : file-length ( file -- length )
     stat dup [ cdr cdr car ] when ;
index f80d9b4d53d083c8bb89eabaeb085d26f168e6e2..0496ac27936a18610a2377c29566a76b44b507a5 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: io-internals
+USE: generic
 USE: kernel
 USE: namespaces
 USE: strings
 USE: threads
 
+BUILTIN: port 14
+
 : stdin 0 getenv ;
 : stdout 1 getenv ;
 
index 0c5602914513c1e044323501907e147c63fc93eb..15b5b69a5222c43c9c3a2fa3f45c57d0de8845d1 100644 (file)
@@ -42,12 +42,12 @@ GENERIC: fclose      ( stream -- )
 : fread1 ( stream -- string )
     1 swap fread# dup f-or-"" [ 0 swap str-nth ] unless ;
 
-: fprint ( string stream -- )
-    tuck fwrite "\n" over fwrite fauto-flush ;
-
 : fwrite ( string stream -- )
     f swap fwrite-attr ;
 
+: fprint ( string stream -- )
+    tuck fwrite "\n" over fwrite fauto-flush ;
+
 TRAITS: string-output-stream
 
 M: string-output-stream fwrite-attr ( string style stream -- )
index 0f94ef4aa5383403e1d7c283bb399e443d1f6635..bd9e2aeae468b1cf978a031d3df85b7448456da2 100644 (file)
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+IN: syntax
+USE: generic
+BUILTIN: f 6 FORGET: f?
+BUILTIN: t 7 FORGET: t?
+
 IN: vectors
 DEFER: vector=
 DEFER: vector-hashcode
 
+IN: lists
+DEFER: cons=
+DEFER: cons-hashcode
+
 IN: kernel
 USE: lists
 USE: math
@@ -108,3 +117,7 @@ IN: kernel
 : set-boot ( quot -- )
     #! Set the boot quotation.
     8 setenv ;
+
+: num-types ( -- n )
+    #! One more than the maximum value from type primitive.
+    17 ;
index f01f6adf6292280f8d7cfedd98d18ee594174451..83c80d15471fc2c55a70095eda4f5d98e1ea1a9a 100644 (file)
@@ -56,30 +56,6 @@ USE: vectors
     #! Test if a list contains an element.
     [ over = ] some? >boolean nip ;
 
-: nth ( n list -- list[n] )
-    #! nth element of a proper list.
-    #! Supplying n <= 0 pushes the first element of the list.
-    #! Supplying an argument beyond the end of the list raises
-    #! an error.
-    swap [ cdr ] times car ;
-
-: last* ( list -- last )
-    #! Last cons of a list.
-    dup cdr cons? [ cdr last* ] when ;
-
-: last ( list -- last )
-    #! Last element of a list.
-    last* car ;
-
-: tail ( list -- tail )
-    #! Return the cdr of the last cons cell, or f.
-    dup [ last* cdr ] when ;
-
-: list? ( list -- ? )
-    #! Proper list test. A proper list is either f, or a cons
-    #! cell whose cdr is a proper list.
-    dup cons? [ tail ] when not ;
-
 : partition-add ( obj ? ret1 ret2 -- ret1 ret2 )
     rot [ swapd cons ] [ >r cons r> ] ifte ;
 
@@ -109,10 +85,6 @@ USE: vectors
         drop
     ] ifte ; inline
 
-: num-sort ( list -- sorted )
-    #! Sorts the list into ascending numerical order.
-    [ > ] sort ;
-
 ! Redefined below
 DEFER: tree-contains?
 
@@ -140,14 +112,6 @@ DEFER: tree-contains?
     #! list.
     2dup contains? [ nip ] [ cons ] ifte ;
 
-: (each) ( list quot -- list quot )
-    >r uncons r> tuck 2slip ; inline
-
-: each ( list quot -- )
-    #! Push each element of a proper list in turn, and apply a
-    #! quotation with effect ( X -- ) to each element.
-    over [ (each) each ] [ 2drop ] ifte ; inline
-
 : reverse ( list -- list )
     [ ] swap [ swons ] each ;
 
@@ -157,18 +121,6 @@ DEFER: tree-contains?
     #! ( X -- Y ) to each element into a new list.
     over [ (each) rot >r map r> swons ] [ drop ] ifte ; inline
 
-: subset ( list quot -- list )
-    #! Applies a quotation with effect ( X -- ? ) to each
-    #! element of a list; all elements for which the quotation
-    #! returned a value other than f are collected in a new
-    #! list.
-    over [
-        over car >r (each)
-        rot >r subset r> [ r> swons ] [ r> drop ] ifte
-    ] [
-        drop
-    ] ifte ; inline
-
 : remove ( obj list -- list )
     #! Remove all occurrences of the object from the list.
     [ dupd = not ] subset nip ;
@@ -182,19 +134,6 @@ DEFER: tree-contains?
         uncons prune 2dup contains? [ nip ] [ cons ] ifte
     ] when ;
 
-: all? ( list pred -- ? )
-    #! Push if the predicate returns true for each element of
-    #! the list.
-    over [
-        dup >r swap uncons >r swap call [
-            r> r> all?
-        ] [
-            r> drop r> drop f
-        ] ifte
-    ] [
-        2drop t
-    ] ifte ; inline
-
 : all=? ( list -- ? )
     #! Check if all elements of a list are equal.
     dup [ uncons [ over = ] all? nip ] [ drop t ] ifte ;
@@ -241,15 +180,6 @@ DEFER: tree-contains?
 : cons-hashcode ( cons -- hash )
     4 (cons-hashcode) ;
 
-: list>vector ( list -- vector )
-    dup length <vector> swap [ over vector-push ] each ;
-
-: stack>list ( vector -- list )
-    [ ] swap [ swons ] vector-each ;
-
-: vector>list ( vector -- list )
-    stack>list reverse ;
-
 : project ( n quot -- list )
     #! Execute the quotation n times, passing the loop counter
     #! the quotation as it ranges from 0..n-1. Collect results
index 3b88e1da4b558673756b881bba2bcd8bc7e1764a..82c7aaac3003b66ec94477bf14e8790d6db1e067 100644 (file)
@@ -32,7 +32,27 @@ USE: kernel
 USE: vectors
 USE: words
 
+BUILTIN: fixnum  0
+BUILTIN: ratio   4
+BUILTIN: complex 5
+BUILTIN: bignum  9
+BUILTIN: float   10
+
 DEFER: number=
+DEFER: mod
+DEFER: abs
+DEFER: <
+DEFER: <=
+DEFER: >
+DEFER: >=
+DEFER: neg
+DEFER: /i
+DEFER: *
+DEFER: +
+DEFER: -
+DEFER: /
+DEFER: /f
+DEFER: sq
 
 : (gcd) ( x y -- z ) dup 0 = [ drop ] [ tuck mod (gcd) ] ifte ;
 : gcd ( x y -- z ) abs swap abs 2dup < [ swap ] when (gcd) ;
index 0d7ce7c6a9f31b4dd018c9d039547da3f9ba5c70..79160b77b5185228d645a335ffce960667709383 100644 (file)
@@ -70,7 +70,7 @@ USE: vectors
 : set-global ( g -- ) 4 setenv ;
 
 : init-namespaces ( -- )
-    global >n  global "global" set ;
+    global >n ;
 
 : namespace-buckets 23 ;
 
index 5163fb4cfd6b0a7968adad667e1e94c5a76eb07f..79c1843d98b30c289b216059ab0c391903f38371 100644 (file)
@@ -11,24 +11,25 @@ USE: kernel
 USE: lists
 USE: math
 USE: namespaces
+USE: vectors
 
 : f_ ( h s v i -- f ) >r swap rot >r 2dup r> 6 * r> - ;
 : p ( v s x -- v p x ) >r dupd neg succ * r> ;
 : q ( v s f -- q ) * neg succ * ;
 : t_ ( v s f -- t_ ) neg succ * neg succ * ;
 
-: mod-cond ( p list -- )
-    #! Call p mod q'th entry of the list of quotations, where
-    #! q is the length of the list. The value q remains on the
+: mod-cond ( p vector -- )
+    #! Call p mod q'th entry of the vector of quotations, where
+    #! q is the length of the vector. The value q remains on the
     #! stack.
-    [ dupd length mod ] keep nth call ;
+    [ dupd length mod ] keep vector-nth call ;
 
 : hsv>rgb ( h s v -- r g b )
-    pick 6 * >fixnum [
+    pick 6 * >fixnum {
         [ f_ t_ p swap     ( v p t ) ]
         [ f_ q  p -rot     ( q v p ) ]
         [ f_ t_ p swapd    ( p v t ) ]
         [ f_ q  p rot      ( p q v ) ]
         [ f_ t_ p swap rot ( t p v ) ]
         [ f_ q  p          ( v p q ) ]
-    ] mod-cond ;
+    } mod-cond ;
index 683f3630ea24fbf004e03262fb17226bb045b44e..901145131fcb30c501676df8bc9247e01b979f6a 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: strings
+USE: generic
 USE: kernel
 USE: lists
 USE: math
 
+BUILTIN: string 12
+BUILTIN: sbuf   13
+
 : f-or-"" ( obj -- ? )
     dup not swap "" = or ;
 
@@ -132,11 +136,6 @@ USE: math
         -rot 2dup >r >r >r str-nth r> call r> r>
     ] times* 2drop ; inline
 
-: str-sort ( list -- sorted )
-    #! Sorts the list into ascending lexicographical string
-    #! order.
-    [ str-lexi> ] sort ;
-
 : blank? ( ch -- ? ) " \t\n\r" str-contains? ;
 : letter? ( ch -- ? ) CHAR: a CHAR: z between? ;
 : LETTER? ( ch -- ? ) CHAR: A CHAR: Z between? ;
index 737b2cec12f121fb4c42019a09ae63a849602b20..b17e74006e7922399c232f8ae49f8f1e097a630b 100644 (file)
@@ -25,7 +25,9 @@
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: parser
+! Bootstrapping trick; see doc/bootstrap.txt.
+IN: !syntax
+USE: syntax
 
 USE: errors
 USE: hashtables
@@ -33,82 +35,17 @@ USE: kernel
 USE: lists
 USE: math
 USE: namespaces
+USE: parser
 USE: strings
 USE: words
 USE: vectors
 USE: unparser
 
-! Colon defs
-: CREATE ( -- word )
-    scan "in" get create dup set-word
-    dup f "documentation" set-word-property
-    dup f "stack-effect" set-word-property
-    dup "line-number" get "line" set-word-property
-    dup "col"         get "col"  set-word-property
-    dup "file"        get "file" set-word-property ;
-
-! \x
-: unicode-escape>ch ( -- esc )
-    #! Read \u....
-    next-ch digit> 16 *
-    next-ch digit> + 16 *
-    next-ch digit> + 16 *
-    next-ch digit> + ;
-
-: ascii-escape>ch ( ch -- esc )
-    [
-        [ CHAR: e | CHAR: \e ]
-        [ CHAR: n | CHAR: \n ]
-        [ CHAR: r | CHAR: \r ]
-        [ CHAR: t | CHAR: \t ]
-        [ CHAR: s | CHAR: \s ]
-        [ CHAR: \s | CHAR: \s ]
-        [ CHAR: 0 | CHAR: \0 ]
-        [ CHAR: \\ | CHAR: \\ ]
-        [ CHAR: \" | CHAR: \" ]
-    ] assoc ;
-
-: escape ( ch -- esc )
-    dup CHAR: u = [
-        drop unicode-escape>ch
-    ] [
-        ascii-escape>ch
-    ] ifte ;
-
-: parse-escape ( -- )
-    next-ch escape dup [ drop "Bad escape" throw ] unless ;
-
-: parse-ch ( ch -- ch )
-    dup CHAR: \\ = [ drop parse-escape ] when ;
-
-: doc-comment-here? ( parsed -- ? )
-    not "in-definition" get and ;
-
-: parsed-stack-effect ( parsed str -- parsed )
-    over doc-comment-here? [
-        word stack-effect [
-            drop
-        ] [
-            word swap "stack-effect" set-word-property
-        ] ifte
-    ] [
-        drop
-    ] ifte ;
-
-: documentation+ ( word str -- )
-    over "documentation" word-property [
-        swap "\n" swap cat3
-    ] when*
-    "documentation" set-word-property ;
-
-: parsed-documentation ( parsed str -- parsed )
-    over doc-comment-here? [
-        word swap documentation+
-    ] [
-        drop
-    ] ifte ;
-
-IN: syntax
+: parsing ( -- )
+    #! Mark the most recently defined word to execute at parse
+    #! time, rather than run time. The word can use 'scan' to
+    #! read ahead in the input stream.
+    word t "parsing" set-word-property ; parsing
 
 : inline ( -- )
     #! Mark the last word to be inlined.
index eec6b8364aeaa0f92179ee645bdab26863426838..9b81047823e102ef7e3f8570f51969bccd2a049f 100644 (file)
@@ -79,7 +79,7 @@ USE: unparser
         ] ifte
     ] [
         r> drop nip str-length
-    ] ifte ;
+    ] ifte ; inline
 
 : skip-blank ( n line -- n )
     [ blank? not ] skip ;
@@ -179,15 +179,71 @@ USE: unparser
 : next-word-ch ( -- ch )
     "col" get "line" get skip-blank "col" set next-ch ;
 
-IN: syntax
+: CREATE ( -- word )
+    scan "in" get create dup set-word
+    dup f "documentation" set-word-property
+    dup f "stack-effect" set-word-property
+    dup "line-number" get "line" set-word-property
+    dup "col"         get "col"  set-word-property
+    dup "file"        get "file" set-word-property ;
+
+! \x
+: unicode-escape>ch ( -- esc )
+    #! Read \u....
+    next-ch digit> 16 *
+    next-ch digit> + 16 *
+    next-ch digit> + 16 *
+    next-ch digit> + ;
+
+: ascii-escape>ch ( ch -- esc )
+    [
+        [ CHAR: e | CHAR: \e ]
+        [ CHAR: n | CHAR: \n ]
+        [ CHAR: r | CHAR: \r ]
+        [ CHAR: t | CHAR: \t ]
+        [ CHAR: s | CHAR: \s ]
+        [ CHAR: \s | CHAR: \s ]
+        [ CHAR: 0 | CHAR: \0 ]
+        [ CHAR: \\ | CHAR: \\ ]
+        [ CHAR: \" | CHAR: \" ]
+    ] assoc ;
+
+: escape ( ch -- esc )
+    dup CHAR: u = [
+        drop unicode-escape>ch
+    ] [
+        ascii-escape>ch
+    ] ifte ;
+
+: parse-escape ( -- )
+    next-ch escape dup [ drop "Bad escape" throw ] unless ;
+
+: parse-ch ( ch -- ch )
+    dup CHAR: \\ = [ drop parse-escape ] when ;
+
+: doc-comment-here? ( parsed -- ? )
+    not "in-definition" get and ;
+
+: parsed-stack-effect ( parsed str -- parsed )
+    over doc-comment-here? [
+        word stack-effect [
+            drop
+        ] [
+            word swap "stack-effect" set-word-property
+        ] ifte
+    ] [
+        drop
+    ] ifte ;
 
-: parsing ( -- )
-    #! Mark the most recently defined word to execute at parse
-    #! time, rather than run time. The word can use 'scan' to
-    #! read ahead in the input stream.
-    word t "parsing" set-word-property ;
+: documentation+ ( word str -- )
+    over "documentation" word-property [
+        swap "\n" swap cat3
+    ] when*
+    "documentation" set-word-property ;
 
-! Once this file has loaded, we can use 'parsing' normally.
-! This hack is needed because in Java Factor, 'parsing' is
-! not parsing, but in CFactor, it is.
-\ parsing t "parsing" set-word-property
+: parsed-documentation ( parsed str -- parsed )
+    over doc-comment-here? [
+        word swap documentation+
+    ] [
+        drop
+    ] ifte ;
index dfe891c5f28bf2c90e13bc527bf24f359936de5f..e89fa25c93d3477c02d68b4710fafb35719b2033 100644 (file)
@@ -37,6 +37,34 @@ USE: stdio
 USE: strings
 USE: words
 
+: type-name ( n -- str )
+    [
+        [ 0 | "fixnum" ]
+        [ 1 | "word" ]
+        [ 2 | "cons" ]
+        [ 3 | "object" ]
+        [ 4 | "ratio" ]
+        [ 5 | "complex" ]
+        [ 6 | "f" ]
+        [ 7 | "t" ]
+        [ 8 | "array" ]
+        [ 9 | "bignum" ]
+        [ 10 | "float" ]
+        [ 11 | "vector" ]
+        [ 12 | "string" ]
+        [ 13 | "sbuf" ]
+        [ 14 | "port" ]
+        [ 15 | "dll" ]
+        [ 16 | "alien" ]
+        ! These values are only used by the kernel for error
+        ! reporting.
+        [ 100 | "fixnum/bignum" ]
+        [ 101 | "fixnum/bignum/ratio" ]
+        [ 102 | "fixnum/bignum/ratio/float" ]
+        [ 103 | "fixnum/bignum/ratio/float/complex" ]
+        [ 104 | "fixnum/string" ]
+    ] assoc ;
+
 GENERIC: unparse ( obj -- str )
 
 M: object unparse ( obj -- str )
index 79b743ec72d20c0f4d32971e94931d1a47fbdeaa..264583f1b340b3618c8eef074b613ef366ba09f8 100644 (file)
@@ -5,4 +5,4 @@ USE: math
 USE: random
 USE: test
 
-[ ] [ [ 100000 [ 0 10000 random-int , ] times ] make-list num-sort drop ] unit-test
+[ ] [ [ 100000 [ 0 10000 random-int , ] times ] make-list [ > ] sort drop ] unit-test
index 63983a2cf5a27d8d98afd035d13d5cc371223727..256538ba3380b332b1ae0d83e8e2a71d29fe0cbb 100644 (file)
@@ -6,4 +6,4 @@ USE: words
 "httpd" apropos.
 "car" usages.
 global describe
-"vocabularies" get describe
+vocabularies get describe
index de6815b30415ecd48b522c57ed07c5e9d92519f8..d5a1dca4ad5e6f1b20dc66c818ec442f5e4b626e 100644 (file)
@@ -17,10 +17,10 @@ USE: strings
 
 [ [ 43 "a" [ ] ] ] [ [ "a" 43 43 43 [ ] 43 "a" [ ] ] prune ] unit-test
 
-[ "fdsfs" num-sort ] unit-test-fails
-[ [ ] ] [ [ ] num-sort ] unit-test
+[ "fdsfs" [ > ] sort ] unit-test-fails
+[ [ ] ] [ [ ] [ > ] sort ] unit-test
 [ [ "2 + 2" ] ] [ [ "2 + 2" ] [ str-lexi> ] sort ] unit-test
-[ [ 1 2 3 4 5 6 7 ] ] [ [ 6 4 5 7 2 1 3 ] num-sort ] unit-test
+[ [ 1 2 3 4 5 6 7 ] ] [ [ 6 4 5 7 2 1 3 ] [ > ] sort ] unit-test
 
 [ f ] [ [ { } { } "Hello" ] all=? ] unit-test
 [ f ] [ [ { 2 } { } { } ] all=? ] unit-test
index c6f9f43b30b21157cece8b1a46180aa0e421a6d4..cac9c7447a10d28f15fc34a72b06a827fecdb2f2 100644 (file)
@@ -17,10 +17,6 @@ USE: strings
 [ t ] [ 1 [ 1 2 ] contains? >boolean ] unit-test
 [ t ] [ 2 [ 1 2 ] contains? >boolean ] unit-test
 
-[ 1 ] [  -1 [ 1 2 ] nth ] unit-test
-[ 1 ] [  0  [ 1 2 ] nth ] unit-test
-[ 2 ] [  1  [ 1 2 ] nth ] unit-test
-
 [ [ 3 ]     ] [ [ 3 ]         last* ] unit-test
 [ [ 3 ]     ] [ [ 1 2 3 ]     last* ] unit-test
 [ [ 3 | 4 ] ] [ [ 1 2 3 | 4 ] last* ] unit-test
index 2a95b8b40a2819a5a6cf43f622829b82a449cf46..08926e7be7fb7ab0616259dd82e8d270f0bd78d4 100644 (file)
@@ -29,7 +29,7 @@ unit-test
 [ t ]
 [
     \ test-word
-    global [ [ "vocabularies" "test" "test-word" ] object-path ] bind
+    global [ [ vocabularies "test" "test-word" ] object-path ] bind
     =
 ] unit-test
 
index 480aaaa60184d0db798b035c92cfea478cbae8e8..eeb93eea0df36b62f0483d251fa31c22ac3a574b 100644 (file)
@@ -13,6 +13,7 @@ USE: prettyprint
 USE: stdio
 USE: strings
 USE: words
+USE: vectors
 USE: unparser
 
 : assert ( t -- )
@@ -62,7 +63,7 @@ USE: unparser
 
 : all-tests ( -- )
     "Running Factor test suite..." print
-    "vocabularies" get [ f "scratchpad" set ] bind
+    vocabularies get [ "scratchpad" off ] bind
     [
         "lists/cons"
         "lists/lists"
index 92a159aed7c416c4a1d23f71f3b0e5bf05eebf77..e8198c12e12fa2f6f96405987d71048fc3857bad 100644 (file)
@@ -36,8 +36,6 @@ DEFER: plist-test
 ] unit-test
 
 [
-    <namespace> "vocabularies" set
-    
     [ t ] [ \ car "car" [ "lists" ] search = ] unit-test
 
     "test-scope" "scratchpad" create drop
diff --git a/library/types.factor b/library/types.factor
deleted file mode 100644 (file)
index 12384f4..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-! :folding=indent:collapseFolds=0:
-
-! $Id$
-!
-! Copyright (C) 2004 Slava Pestov.
-! 
-! Redistribution and use in source and binary forms, with or without
-! modification, are permitted provided that the following conditions are met:
-! 
-! 1. Redistributions of source code must retain the above copyright notice,
-!    this list of conditions and the following disclaimer.
-! 
-! 2. Redistributions in binary form must reproduce the above copyright notice,
-!    this list of conditions and the following disclaimer in the documentation
-!    and/or other materials provided with the distribution.
-! 
-! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-USE: kernel
-USE: math
-USE: generic
-
-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: syntax       BUILTIN: f       6 FORGET: f?
-IN: syntax       BUILTIN: t       7 FORGET: t?
-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
-
-: type-name ( n -- str )
-    [
-        [ 0 | "fixnum" ]
-        [ 1 | "word" ]
-        [ 2 | "cons" ]
-        [ 3 | "object" ]
-        [ 4 | "ratio" ]
-        [ 5 | "complex" ]
-        [ 6 | "f" ]
-        [ 7 | "t" ]
-        [ 8 | "array" ]
-        [ 9 | "bignum" ]
-        [ 10 | "float" ]
-        [ 11 | "vector" ]
-        [ 12 | "string" ]
-        [ 13 | "sbuf" ]
-        [ 14 | "port" ]
-        [ 15 | "dll" ]
-        [ 16 | "alien" ]
-        ! These values are only used by the kernel for error
-        ! reporting.
-        [ 100 | "fixnum/bignum" ]
-        [ 101 | "fixnum/bignum/ratio" ]
-        [ 102 | "fixnum/bignum/ratio/float" ]
-        [ 103 | "fixnum/bignum/ratio/float/complex" ]
-        [ 104 | "fixnum/string" ]
-    ] assoc ;
-
-: num-types ( -- n )
-    #! One more than the maximum value from type primitive.
-    17 ;
index d938d12537c10cc8eba585627d7b5711d62d2fb2..3791ef25d01bc8939538ad6fbcc74d16a41cc18e 100644 (file)
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 IN: vectors
+USE: generic
 USE: kernel
 USE: lists
 USE: math
 
+BUILTIN: vector  11
+
 : empty-vector ( len -- vec )
     #! Creates a vector with 'len' elements set to f. Unlike
     #! <vector>, which gives an empty vector with a certain
@@ -105,6 +108,15 @@ USE: math
     #! Shallow copy of a vector.
     [ ] vector-map ;
 
+: list>vector ( list -- vector )
+    dup length <vector> swap [ over vector-push ] each ;
+
+: stack>list ( vector -- list )
+    [ ] swap [ swons ] vector-each ;
+
+: vector>list ( vector -- list )
+    stack>list reverse ;
+
 : vector-length= ( vec vec -- ? )
     vector-length swap vector-length number= ;
 
index b0b184d10f42fd3037a744d175c01ce70c80ef31..405d338cbb448da08b9dfc28316df7a655f5996f 100644 (file)
@@ -30,6 +30,31 @@ USE: hashtables
 USE: kernel
 USE: lists
 USE: namespaces
+USE: strings
+
+: word ( -- word ) global [ "last-word" get ] bind ;
+: set-word ( word -- ) global [ "last-word" set ] bind ;
+
+: vocabs ( -- list )
+    #! Push a list of vocabularies.
+    vocabularies get hash-keys [ str-lexi> ] sort ;
+
+: vocab ( name -- vocab )
+    #! Get a vocabulary.
+    vocabularies get hash ;
+
+: word-sort ( list -- list )
+    #! Sort a list of words by name.
+    [ swap word-name swap word-name str-lexi> ] sort ;
+
+: words ( vocab -- list )
+    #! Push a list of all words in a vocabulary.
+    #! Filter empty slots.
+    vocab hash-values [ ] subset word-sort ;
+
+: each-word ( quot -- )
+    #! Apply a quotation to each word in the image.
+    vocabs [ words [ swap dup >r call r> ] each ] each drop ;
 
 : (search) ( name vocab -- word )
     vocab dup [ hash ] [ 2drop f ] ifte ;
@@ -55,12 +80,10 @@ USE: namespaces
 
 : reveal ( word -- )
     #! Add a new word to its vocabulary.
-    global [
-        "vocabularies" get [
-            dup word-vocabulary
-            over word-name
-            2list set-object-path
-        ] bind
+    vocabularies get [
+        dup word-vocabulary
+        over word-name
+        2list set-object-path
     ] bind ;
 
 : create ( name vocab -- word )
@@ -72,3 +95,46 @@ USE: namespaces
 : forget ( word -- )
     #! Remove a word definition.
     dup word-vocabulary vocab [ word-name off ] bind ;
+
+: init-search-path ( -- )
+    ! For files
+    "scratchpad" "file-in" set
+    [ "builtins" "syntax" "scratchpad" ] "file-use" set
+    ! For interactive
+    "scratchpad" "in" set
+    [
+        "user"
+        "arithmetic"
+        "builtins"
+        "compiler"
+        "debugger"
+        "errors"
+        "files"
+        "hashtables"
+        "inference"
+        "inferior"
+        "interpreter"
+        "inspector"
+        "jedit"
+        "kernel"
+        "listener"
+        "lists"
+        "math"
+        "namespaces"
+        "parser"
+        "prettyprint"
+        "processes"
+        "profiler"
+        "stack"
+        "streams"
+        "stdio"
+        "strings"
+        "syntax"
+        "test"
+        "threads"
+        "unparser"
+        "vectors"
+        "vocabularies"
+        "words"
+        "scratchpad"
+    ] "use" set ;
index f834a23f64044f0fb32aa010b77a6d67fd7f820f..c5c93175064782b7dc2844e7f552d38e7e9a4ca1 100644 (file)
@@ -34,6 +34,10 @@ USE: math
 USE: namespaces
 USE: strings
 
+BUILTIN: word 1
+
+SYMBOL: vocabularies
+
 : word-property ( word pname -- pvalue )
     swap word-plist assoc ;
 
@@ -47,19 +51,11 @@ PREDICATE: word primitive ( obj -- ? ) word-primitive 2 > ;
 PREDICATE: word symbol    ( obj -- ? ) word-primitive 2 = ;
 PREDICATE: word undefined ( obj -- ? ) word-primitive 0 = ;
 
-: word ( -- word ) global [ "last-word" get ] bind ;
-: set-word ( word -- ) global [ "last-word" set ] bind ;
-
-: (define) ( word primitive parameter -- )
-    #! Define a word in the current Factor instance.
+: define ( word primitive parameter -- )
     pick set-word-parameter
     over set-word-primitive
     f "parsing" set-word-property ;
 
-: define ( word primitive parameter -- )
-    #! The define-hook is set by the image bootstrapping code.
-    "define-hook" get [ call ] [ (define) ] ifte* ;
-
 : define-compound ( word def -- ) 1 swap define ;
 : define-symbol   ( word -- ) 2 over define ;
 
@@ -68,66 +64,7 @@ PREDICATE: word undefined ( obj -- ? ) word-primitive 0 = ;
 : stack-effect    ( word -- str ) "stack-effect" word-property ;
 : documentation   ( word -- str ) "documentation" word-property ;
 
-: vocabs ( -- list )
-    #! Push a list of vocabularies.
-    global [ "vocabularies" get hash-keys str-sort ] bind ;
-
-: vocab ( name -- vocab )
-    #! Get a vocabulary.
-    global [ "vocabularies" get hash ] bind ;
-
-: word-sort ( list -- list )
-    #! Sort a list of words by name.
-    [ swap word-name swap word-name str-lexi> ] sort ;
-
-: words ( vocab -- list )
-    #! Push a list of all words in a vocabulary.
-    #! Filter empty slots.
-    vocab hash-values [ ] subset word-sort ;
-
-: each-word ( quot -- )
-    #! Apply a quotation to each word in the image.
-    vocabs [ words [ swap dup >r call r> ] each ] each drop ;
-
-: init-search-path ( -- )
-    ! For files
-    "scratchpad" "file-in" set
-    [ "builtins" "syntax" "scratchpad" ] "file-use" set
-    ! For interactive
-    "scratchpad" "in" set
-    [
-        "user"
-        "arithmetic"
-        "builtins"
-        "compiler"
-        "debugger"
-        "errors"
-        "files"
-        "hashtables"
-        "inference"
-        "inferior"
-        "interpreter"
-        "inspector"
-        "jedit"
-        "kernel"
-        "listener"
-        "lists"
-        "math"
-        "namespaces"
-        "parser"
-        "prettyprint"
-        "processes"
-        "profiler"
-        "stack"
-        "streams"
-        "stdio"
-        "strings"
-        "syntax"
-        "test"
-        "threads"
-        "unparser"
-        "vectors"
-        "vocabularies"
-        "words"
-        "scratchpad"
-    ] "use" set ;
+: word-clone ( word -- word )
+    dup word-primitive
+    over word-parameter
+    rot word-plist <word> ;
index 6bc956bc8a1f08669cbaa2ff4bfdb02a8332e3e3..2bbf947eb78e8083333d4107502d334d81ee3bfc 100644 (file)
@@ -51,6 +51,8 @@ INLINE CELL tag_header(CELL cell)
        return RETAG(cell << TAG_BITS,HEADER_TYPE);
 }
 
+#define HEADER_DEBUG
+
 INLINE CELL untag_header(CELL cell)
 {
        CELL type = cell >> TAG_BITS;
@@ -77,6 +79,10 @@ INLINE void type_check(CELL type, CELL tagged)
 {
        if(type < HEADER_TYPE)
        {
+#ifdef HEADER_DEBUG
+               if(type == WORD_TYPE && object_type(tagged) != WORD_TYPE)
+                       critical_error("word header check",tagged);
+#endif
                if(TAG(tagged) == type)
                        return;
        }