]> gitweb.factorcode.org Git - factor.git/commitdiff
0.72 ready for release
authorSlava Pestov <slava@factorcode.org>
Sat, 19 Feb 2005 01:37:01 +0000 (01:37 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 19 Feb 2005 01:37:01 +0000 (01:37 +0000)
22 files changed:
Makefile
TODO.FACTOR.txt
library/bootstrap/boot-stage2.factor
library/bootstrap/boot.factor
library/bootstrap/primitives.factor
library/generic/builtin.factor
library/generic/complement.factor
library/generic/generic.factor
library/generic/null.factor
library/generic/object.factor
library/generic/predicate.factor
library/generic/tuple.factor
library/generic/union.factor
library/syntax/generic.factor [new file with mode: 0644]
library/tools/heap-stats.factor [deleted file]
library/tools/memory.factor [new file with mode: 0644]
native/factor.h
native/memory.c
native/memory.h
native/primitives.c
native/scan.c [deleted file]
native/scan.h [deleted file]

index d44483531a906cd137e2fb0cf2d661a34e0615a4..45e4277e61586126fb20fe606fc24bfa4018f822 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,8 +22,7 @@ OBJS = $(UNIX_OBJS) native/arithmetic.o native/array.o native/bignum.o \
        native/word.o native/compiler.o \
        native/ffi.o native/boolean.o \
        native/debug.o \
-       native/hashtable.o \
-       native/scan.o
+       native/hashtable.o
 
 default:
        @echo "Run 'make' with one of the following parameters:"
index 6c4a2b9f9f536af26b2e330d95da9750a09df5b6..9a04a1a3320ecdfb73ba765f894d6ee582a11b60 100644 (file)
@@ -20,8 +20,7 @@
 - #jump-f #jump-f-label\r
 - extract word inside M:, C:, and structure browsing for these\r
 - fix checkbox alignment\r
-- begin-scan, next-object, end-scan primitives\r
-- each-object, each-slot combinators\r
+- each-slot combinator\r
 - references primitive\r
 - resize window: world not updated until mouse moved\r
 - x>offset\r
index 8fd5920415319b68ebeb74f2d22aa1fe89bdd3af..be61d3505b3b9845741d877b53f64f4002d4c714 100644 (file)
@@ -54,7 +54,7 @@ USING: kernel lists parser stdio words namespaces ;
 \r
     "/library/io/files.factor"\r
     "/library/eval-catch.factor"\r
-    "/library/tools/heap-stats.factor"\r
+    "/library/tools/memory.factor"\r
     "/library/tools/listener.factor"\r
     "/library/cli.factor"\r
 ] [\r
index dc22e2a20ae0a61150761c21fb1701acdcebfd80..e0b2c92d053a715d2021918e728e69065fc8fe01 100644 (file)
@@ -38,6 +38,8 @@ words hashtables ;
     "/library/syntax/parse-numbers.factor" parse-resource append,
     "/library/syntax/parser.factor" parse-resource append,
     "/library/syntax/parse-stream.factor" parse-resource append,
+    "/library/syntax/generic.factor" parse-resource append,
+    "/library/syntax/parse-syntax.factor" parse-resource append,
 
     "delegate" [ "generic" ] search
     "object" [ "generic" ] search
@@ -46,7 +48,7 @@ words hashtables ;
 
     reveal
     reveal
-
+    
     "/library/generic/generic.factor" parse-resource append,
     "/library/generic/object.factor" parse-resource append,
     "/library/generic/null.factor" parse-resource append,
@@ -57,7 +59,6 @@ words hashtables ;
     "/library/generic/tuple.factor" parse-resource append,
 
     "/library/bootstrap/init.factor" parse-resource append,
-    "/library/syntax/parse-syntax.factor" parse-resource append,
 ] make-list
 
 "boot" [ "kernel" ] search swons
index 4364f7fcfbbe30bca12fe4d84aa75da2fe88c90c..cacc1a04e5021c3b1af69d54b5de156e3cfb6f1b 100644 (file)
@@ -179,7 +179,6 @@ vocabularies get [
     [ "set-alien-2" "alien"                   [ [ integer alien integer ] [ ] ] ]
     [ "alien-1" "alien"                       [ [ alien integer ] [ fixnum ] ] ]
     [ "set-alien-1" "alien"                   [ [ integer alien integer ] [ ] ] ]
-    [ "heap-stats" "memory"                   [ [ ] [ general-list ] ] ]
     [ "throw" "errors"                        [ [ object ] [ ] ] ]
     [ "string>memory" "kernel-internals"      [ [ string integer ] [ ] ] ]
     [ "memory>string" "kernel-internals"      [ [ integer integer ] [ string ] ] ]
@@ -202,7 +201,8 @@ vocabularies get [
     [ ">tuple" "kernel-internals"             [ [ object ] [ tuple ] ] ]
     [ "begin-scan" "memory"                   [ [ ] [ ] ] ]
     [ "next-object" "memory"                  [ [ ] [ object ] ] ]
-    [ "end-scan" "memory"                     [ [ ] [ object ] ] ]                         
+    [ "end-scan" "memory"                     [ [ ] [ object ] ] ]       
+    [ "size" "memory"                         [ [ ] [ object ] ] ]                       
 ] [                                           
     3unlist >r create >r 1 + r> 2dup swap f define r>
     dup string? [
index d61dc5369d429b9b68a2be1f96fd425bd4720588..80e85df1be4ead0d840f897f69f3c248d37e8644 100644 (file)
@@ -1,40 +1,8 @@
-! :folding=indent: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.
-
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
 IN: generic
-USE: errors
-USE: hashtables
-USE: kernel
-USE: lists
-USE: namespaces
-USE: parser
-USE: strings
-USE: words
-USE: vectors
+USING: errors hashtables kernel lists namespaces parser strings
+words vectors ;
 
 ! Builtin metaclass for builtin types: fixnum, word, cons, etc.
 SYMBOL: builtin
@@ -75,15 +43,5 @@ builtin [ 2drop t ] "class<" set-word-property
     [ swap "builtin-type" set-word-property ] keep
     builtin define-class ;
 
-: BUILTIN:
-    #! Followed by type name and type number. Define a built-in
-    #! type predicate with this number.
-    CREATE scan-word swap builtin-class ; parsing
-
 : builtin-type ( n -- symbol )
     unit classes get hash ;
-
-M: object class ( obj -- class )
-    #! Analogous to the type primitive. Pushes the builtin
-    #! class of an object.
-    type builtin-type ;
index 26bd8e3f620048588207c1411f3dc0f0f0de97ce..67e144243b80e97602f043b5a32c80c27fd6ed54 100644 (file)
@@ -1,41 +1,9 @@
-! :folding=indent:collapseFolds=1:
-
-! $Id$
-!
 ! Copyright (C) 2005 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.
+! See http://factor.sf.net/license.txt for BSD license.
 
 IN: generic
-USE: errors
-USE: hashtables
-USE: kernel
-USE: lists
-USE: namespaces
-USE: parser
-USE: strings
-USE: words
-USE: vectors
-USE: math
+USING: errors hashtables kernel lists math parser strings
+vectors words ;
 
 ! Complement metaclass, contains all objects not in a certain class.
 SYMBOL: complement
@@ -71,11 +39,3 @@ complement [
     [ complement-predicate define-compound ] keep
     dupd "complement" set-word-property
     complement define-class ;
-
-: COMPLEMENT: ( -- class predicate definition )
-    #! Followed by a class name, then a complemented class.
-    CREATE
-    dup intern-symbol
-    dup predicate-word
-    [ dupd unit "predicate" set-word-property ] keep
-    scan-word define-complement ; parsing
index a7f39e2e728dbdd004fe9ebfd17cf93b8e759f9d..ff59d445f466376a748a0bcd44a4690a28236ac3 100644 (file)
@@ -92,30 +92,11 @@ namespaces parser strings words vectors math math-internals ;
 : single-combination ( obj vtable -- )
     >r dup type r> dispatch ; inline
 
-: GENERIC:
-    #! GENERIC: bar creates a generic word bar. Add methods to
-    #! the generic word using M:.
-    [ single-combination ]
-    \ GENERIC: CREATE define-generic ; parsing
-
 : arithmetic-combination ( n n vtable -- )
     #! Note that the numbers remain on the stack, possibly after
     #! being coerced to a maximal type.
     >r arithmetic-type r> dispatch ; inline
 
-: 2GENERIC:
-    #! 2GENERIC: bar creates a generic word bar. Add methods to
-    #! the generic word using M:. 2GENERIC words dispatch on
-    #! arithmetic types and should not be used for non-numerical
-    #! types.
-    [ arithmetic-combination ]
-    \ 2GENERIC: CREATE define-generic ; parsing
-
-: M: ( -- class generic [ ] )
-    #! M: foo bar begins a definition of the bar generic word
-    #! specialized to the foo type.
-    scan-word scan-word [ define-method ] [ ] ; parsing
-
 ! Maps lists of builtin type numbers to class objects.
 SYMBOL: classes
 
@@ -162,5 +143,3 @@ SYMBOL: object
     classes get set-hash ;
 
 classes get [ <namespace> classes set ] unless
-
-GENERIC: class ( obj -- class )
index d6c9f6c5d9ca20ba959999e2eeafdbb60a06c026..b88c09b54c1889ee2049fe9af010b2679368c3b3 100644 (file)
@@ -1,33 +1,7 @@
-! :folding=indent:collapseFolds=1:
-
-! $Id$
-!
-! Copyright (C) 2005 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.
-
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
 IN: generic
-USE: kernel
-USE: words
+USING: kernel words ;
 
 ! Null metaclass with no instances.
 SYMBOL: null
index 78025996976a574a8ae85d03f0960b691c909965..0e7231551ce796860afc8b12be758ae01905a3d8 100644 (file)
@@ -1,41 +1,7 @@
-! :folding=indent: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.
-
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
 IN: generic
-USE: errors
-USE: hashtables
-USE: kernel
-USE: lists
-USE: namespaces
-USE: parser
-USE: strings
-USE: words
-USE: vectors
-USE: math
+USING: kernel lists math vectors words ;
 
 ! Catch-all metaclass for providing a default method.
 SYMBOL: object
index d9f0989aebfa1168974732d27e9ba0cf384020eb..520dcca2b198bfbc18f557e76e744ab5c8b5bbec 100644 (file)
@@ -1,40 +1,8 @@
-! :folding=indent:collapseFolds=1:
-
-! $Id$
-!
 ! Copyright (C) 2004, 2005 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.
-
+! See http://factor.sf.net/license.txt for BSD license.
 IN: generic
-USE: errors
-USE: hashtables
-USE: kernel
-USE: lists
-USE: namespaces
-USE: parser
-USE: strings
-USE: words
-USE: vectors
+USING: errors hashtables kernel lists namespaces parser strings
+words vectors ;
 
 ! Predicate metaclass for generalized predicate dispatch.
 SYMBOL: predicate
@@ -78,13 +46,3 @@ predicate [
     [ \ dup , append, , [ drop f ] , \ ifte , ] make-list
     define-compound
     predicate "metaclass" set-word-property ;
-
-: PREDICATE: ( -- class predicate definition )
-    #! Followed by a superclass name, then a class name.
-    scan-word
-    CREATE dup intern-symbol
-    dup rot "superclass" set-word-property
-    dup predicate-word
-!    2dup swap "predicate" set-word-property
-    [ dupd unit "predicate" set-word-property ] keep
-    [ define-predicate ] [ ] ; parsing
index 4d564f3feb107548eec4dd08fdb32e15db2f73f0..a6256c775b937ce020c897f7dec4fcf8a6bb39e6 100644 (file)
@@ -4,6 +4,10 @@ IN: generic
 USING: words parser kernel namespaces lists strings
 kernel-internals math hashtables errors vectors ;
 
+: class ( obj -- class )
+    #! The class of an object.
+    dup tuple? [ 2 slot ] [ type builtin-type ] ifte ;
+
 : make-tuple ( class -- tuple )
     dup "tuple-size" word-property <tuple>
     [ 0 swap set-array-nth ] keep ;
@@ -106,19 +110,6 @@ kernel-internals math hashtables errors vectors ;
     dup r> define-slots "slot-words" set-word-property
     default-constructor ;
 
-: TUPLE:
-    #! Followed by a tuple name, then slot names, then ;
-    scan
-    string-mode on
-    [ string-mode off define-tuple ]
-    f ; parsing
-
-: C:
-    #! Followed by a tuple name, then constructor code, then ;
-    #! Constructor code executes with the empty tuple on the
-    #! stack.
-    scan-word [ define-constructor ] f ; parsing
-
 : tuple-delegate ( tuple -- obj )
     dup tuple? [
         dup class "delegate-field" word-property dup [
@@ -223,8 +214,6 @@ M: tuple hashcode ( vec -- n )
         1 swap array-nth hashcode
     ] ifte ;
 
-M: tuple class ( obj -- class ) 2 slot ;
-
 tuple [
     ( generic vtable definition class -- )
     2drop add-tuple-dispatch
index bca22d385978caedd45c0e21eafa68e53c23da2d..453cf34ac72b9034ab0492c78324d2e91bac3243 100644 (file)
@@ -1,40 +1,8 @@
-! :folding=indent: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.
-
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
 IN: generic
-USE: errors
-USE: hashtables
-USE: kernel
-USE: lists
-USE: namespaces
-USE: parser
-USE: strings
-USE: words
-USE: vectors
+USING: errors hashtables kernel lists namespaces parser strings
+words vectors ;
 
 ! Union metaclass for dispatch on multiple classes.
 SYMBOL: union
@@ -80,11 +48,3 @@ union [ 2drop t ] "class<" set-word-property
     [ union-predicate define-compound ] keep
     dupd "members" set-word-property
     union define-class ;
-
-: UNION: ( -- class predicate definition )
-    #! Followed by a class name, then a list of union members.
-    CREATE
-    dup intern-symbol
-    dup predicate-word
-    [ dupd unit "predicate" set-word-property ] keep
-    [ define-union ] [ ] ; parsing
diff --git a/library/syntax/generic.factor b/library/syntax/generic.factor
new file mode 100644 (file)
index 0000000..6aa102e
--- /dev/null
@@ -0,0 +1,68 @@
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
+
+! Bootstrapping trick; see doc/bootstrap.txt.
+IN: !syntax
+USING: syntax generic kernel lists namespaces parser words ;
+
+: GENERIC:
+    #! GENERIC: bar creates a generic word bar. Add methods to
+    #! the generic word using M:.
+    [ single-combination ]
+    \ GENERIC: CREATE define-generic ; parsing
+
+: 2GENERIC:
+    #! 2GENERIC: bar creates a generic word bar. Add methods to
+    #! the generic word using M:. 2GENERIC words dispatch on
+    #! arithmetic types and should not be used for non-numerical
+    #! types.
+    [ arithmetic-combination ]
+    \ 2GENERIC: CREATE define-generic ; parsing
+
+: BUILTIN:
+    #! Followed by type name and type number. Define a built-in
+    #! type predicate with this number.
+    CREATE scan-word swap builtin-class ; parsing
+
+: COMPLEMENT: ( -- class predicate definition )
+    #! Followed by a class name, then a complemented class.
+    CREATE
+    dup intern-symbol
+    dup predicate-word
+    [ dupd unit "predicate" set-word-property ] keep
+    scan-word define-complement ; parsing
+
+: UNION: ( -- class predicate definition )
+    #! Followed by a class name, then a list of union members.
+    CREATE
+    dup intern-symbol
+    dup predicate-word
+    [ dupd unit "predicate" set-word-property ] keep
+    [ define-union ] [ ] ; parsing
+
+: PREDICATE: ( -- class predicate definition )
+    #! Followed by a superclass name, then a class name.
+    scan-word
+    CREATE dup intern-symbol
+    dup rot "superclass" set-word-property
+    dup predicate-word
+    [ dupd unit "predicate" set-word-property ] keep
+    [ define-predicate ] [ ] ; parsing
+
+: TUPLE:
+    #! Followed by a tuple name, then slot names, then ;
+    scan
+    string-mode on
+    [ string-mode off define-tuple ]
+    f ; parsing
+
+: M: ( -- class generic [ ] )
+    #! M: foo bar begins a definition of the bar generic word
+    #! specialized to the foo type.
+    scan-word scan-word [ define-method ] [ ] ; parsing
+
+: C:
+    #! Followed by a tuple name, then constructor code, then ;
+    #! Constructor code executes with the empty tuple on the
+    #! stack.
+    scan-word [ define-constructor ] f ; parsing
diff --git a/library/tools/heap-stats.factor b/library/tools/heap-stats.factor
deleted file mode 100644 (file)
index 90dd574..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-! Copyright (C) 2004, 2005 Slava Pestov.
-! See http://factor.sf.net/license.txt for BSD license.
-IN: memory
-USING: errors generic kernel lists math namespaces prettyprint
-stdio unparser vectors words ;
-
-! Printing an overview of heap usage.
-
-: kb. 1024 /i unparse write " KB" write ;
-
-: (room.) ( free total -- )
-    2dup swap - swap ( free used total )
-    kb. " total " write
-    kb. " used " write
-    kb. " free" print ;
-
-: room. ( -- )
-    room
-    "Data space: " write (room.)
-    "Code space: " write (room.) ;
-
-! Some words for iterating through the heap.
-
-: (each-object) ( quot -- )
-    next-object dup [
-        swap dup slip (each-object)
-    ] [
-        2drop
-    ] ifte ; inline
-
-: each-object ( quot -- )
-    #! Applies the quotation to each object in the image.
-    [
-        begin-scan (each-object)
-    ] [
-        end-scan rethrow
-    ] catch ; inline
-
-: instances ( class -- list )
-    #! Return a list of all instances of a built-in or tuple
-    #! class in the image.
-    [
-        [
-            dup class pick = [ , ] [ drop ] ifte
-        ] each-object drop
-    ] make-list ;
-
-: heap-stat. ( type instances bytes -- )
-    dup 0 = [
-        3drop
-    ] [
-        rot builtin-type word-name write ": " write
-        unparse write " bytes, " write
-        unparse write " instances" print
-    ] ifte ;
-
-: heap-stats. ( -- )
-    #! Print heap allocation breakdown.
-    0 heap-stats [ dupd uncons heap-stat. 1 + ] each drop ;
diff --git a/library/tools/memory.factor b/library/tools/memory.factor
new file mode 100644 (file)
index 0000000..3657e71
--- /dev/null
@@ -0,0 +1,75 @@
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
+IN: memory
+USING: errors generic kernel lists math namespaces prettyprint
+stdio unparser vectors words ;
+
+! Printing an overview of heap usage.
+
+: kb. 1024 /i unparse write " KB" write ;
+
+: (room.) ( free total -- )
+    2dup swap - swap ( free used total )
+    kb. " total " write
+    kb. " used " write
+    kb. " free" print ;
+
+: room. ( -- )
+    room
+    "Data space: " write (room.)
+    "Code space: " write (room.) ;
+
+! Some words for iterating through the heap.
+
+: (each-object) ( quot -- )
+    next-object dup [
+        swap dup slip (each-object)
+    ] [
+        2drop
+    ] ifte ; inline
+
+: each-object ( quot -- )
+    #! Applies the quotation to each object in the image.
+    [
+        begin-scan (each-object)
+    ] [
+        end-scan rethrow
+    ] catch ; inline
+
+: instances ( class -- list )
+    #! Return a list of all instances of a built-in or tuple
+    #! class in the image.
+    [
+        [
+            dup class pick = [ , ] [ drop ] ifte
+        ] each-object drop
+    ] make-list ;
+
+: vector+ ( n index vector -- )
+    [ vector-nth + ] 2keep set-vector-nth ;
+
+: heap-stat-step ( counts sizes obj -- )
+    [ dup size swap type rot vector+ ] keep
+    1 swap type rot vector+ ;
+
+: zero-vector ( n -- vector )
+    [ drop 0 ] vector-project ;
+
+: heap-stats ( -- stats )
+    #! Return a list of instance count/total size pairs.
+    num-types zero-vector num-types zero-vector
+    [ >r 2dup r> heap-stat-step ] each-object
+    swap vector>list swap vector>list zip ;
+
+: heap-stat. ( type instances bytes -- )
+    dup 0 = [
+        3drop
+    ] [
+        rot builtin-type word-name write ": " write
+        unparse write " bytes, " write
+        unparse write " instances" print
+    ] ifte ;
+
+: heap-stats. ( -- )
+    #! Print heap allocation breakdown.
+    0 heap-stats [ dupd uncons heap-stat. 1 + ] each drop ;
index 5b9de43071709a2895fe59f00bc615c03d76c143..1dfe2050343743a22eb524f386d243580b3c7a30 100644 (file)
@@ -127,6 +127,5 @@ typedef unsigned char BYTE;
 #include "relocate.h"
 #include "ffi.h"
 #include "debug.h"
-#include "scan.h"
 
 #endif /* __FACTOR_H__ */
index 21b739e82ecc35478ef4e7e574d28cf71db9e20b..c8a8bf55a6f6819e1b6ca6b07d46851d39428cc2 100644 (file)
@@ -118,5 +118,57 @@ void primitive_allot_profiling(void)
 
 void primitive_address(void)
 {
-       dpush(tag_bignum(s48_ulong_to_bignum(dpop())));
+       drepl(tag_bignum(s48_ulong_to_bignum(dpeek())));
+}
+
+void primitive_size(void)
+{
+       drepl(tag_fixnum(object_size(dpeek())));
+}
+
+void primitive_begin_scan(void)
+{
+       primitive_gc();
+       heap_scan_ptr = active.base;
+       heap_scan_end = active.here;
+       heap_scan = true;
+}
+
+void primitive_next_object(void)
+{
+       CELL value = get(heap_scan_ptr);
+       CELL obj = heap_scan_ptr;
+       CELL size, type;
+
+       if(!heap_scan)
+               general_error(ERROR_HEAP_SCAN,F);
+
+       if(heap_scan_ptr >= heap_scan_end)
+       {
+               dpush(F);
+               return;
+       }
+       
+       if(headerp(value))
+       {
+               size = align8(untagged_object_size(heap_scan_ptr));
+               type = untag_header(value);
+       }
+       else
+       {
+               size = CELLS * 2;
+               type = CONS_TYPE;
+       }
+
+       heap_scan_ptr += size;
+
+       if(type < HEADER_TYPE)
+               dpush(RETAG(obj,type));
+       else
+               dpush(RETAG(obj,OBJECT_TYPE));
+}
+
+void primitive_end_scan(void)
+{
+       heap_scan = false;
 }
index 8b1c357197a722eaec6c823127a2e078b3c2b8f0..cb7657b6b88245a5351a88c69ef5bf2b39d70aad 100644 (file)
@@ -66,9 +66,16 @@ bool in_zone(ZONE* z, CELL pointer);
 void primitive_room(void);
 void primitive_allot_profiling(void);
 void primitive_address(void);
-void primitive_memory_cell(void);
-void primitive_memory_4(void);
-void primitive_memory_1(void);
-void primitive_set_memory_cell(void);
-void primitive_set_memory_4(void);
-void primitive_set_memory_1(void);
+void primitive_size(void);
+
+/* A heap walk allows useful things to be done, like finding all
+references to an object for debugging purposes. */
+CELL heap_scan_ptr;
+
+/* End of heap when walk was started; prevents infinite loop if
+walk consing */
+CELL heap_scan_end;
+
+void primitive_begin_scan(void);
+void primitive_next_object(void);
+void primitive_end_scan(void);
index f84b55328c8769814f7a483e2849ce6211bb83d5..5964a17712d4d197f5e3c212e5f7997f4b166d92 100644 (file)
@@ -158,7 +158,6 @@ void* primitives[] = {
        primitive_set_alien_2,
        primitive_alien_1,
        primitive_set_alien_1,
-       primitive_heap_stats,
        primitive_throw,
        primitive_string_to_memory,
        primitive_memory_to_string,
@@ -181,7 +180,8 @@ void* primitives[] = {
        primitive_to_tuple,
        primitive_begin_scan,
        primitive_next_object,
-       primitive_end_scan
+       primitive_end_scan,
+       primitive_size
 };
 
 CELL primitive_to_xt(CELL primitive)
diff --git a/native/scan.c b/native/scan.c
deleted file mode 100644 (file)
index 94581f5..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-#include "factor.h"
-
-void primitive_begin_scan(void)
-{
-       primitive_gc();
-       heap_scan_ptr = active.base;
-       heap_scan_end = active.here;
-       heap_scan = true;
-}
-
-void primitive_next_object(void)
-{
-       CELL value = get(heap_scan_ptr);
-       CELL obj = heap_scan_ptr;
-       CELL size, type;
-
-       if(!heap_scan)
-               general_error(ERROR_HEAP_SCAN,F);
-
-       if(heap_scan_ptr >= heap_scan_end)
-       {
-               dpush(F);
-               return;
-       }
-       
-       if(headerp(value))
-       {
-               size = align8(untagged_object_size(heap_scan_ptr));
-               type = untag_header(value);
-       }
-       else
-       {
-               size = CELLS * 2;
-               type = CONS_TYPE;
-       }
-
-       heap_scan_ptr += size;
-
-       if(type < HEADER_TYPE)
-               dpush(RETAG(obj,type));
-       else
-               dpush(RETAG(obj,OBJECT_TYPE));
-}
-
-void primitive_end_scan(void)
-{
-       heap_scan = false;
-}
-
-void primitive_heap_stats(void)
-{
-       int instances[TYPE_COUNT], bytes[TYPE_COUNT];
-       int i;
-       CELL list = F;
-
-       for(i = 0; i < TYPE_COUNT; i++)
-               instances[i] = 0;
-
-       for(i = 0; i < TYPE_COUNT; i++)
-               bytes[i] = 0;
-
-       begin_heap_scan();
-
-       for(;;)
-       {
-               CELL size, type;
-               heap_step(&size,&type);
-
-               if(walk_donep())
-                       break;
-
-               instances[type]++;
-               bytes[type] += size;
-       }
-
-       for(i = TYPE_COUNT - 1; i >= 0; i--)
-       {
-               list = cons(
-                       cons(tag_fixnum(instances[i]),tag_fixnum(bytes[i])),
-                       list);
-       }
-
-       dpush(list);
-}
diff --git a/native/scan.h b/native/scan.h
deleted file mode 100644 (file)
index a213dad..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/* A heap walk allows useful things to be done, like finding all
-references to an object for debugging purposes. */
-CELL heap_scan_ptr;
-
-/* End of heap when walk was started; prevents infinite loop if
-walk consing */
-CELL heap_scan_end;
-
-/* Begin iterating through the heap. This is not re-entrant. */
-INLINE void begin_heap_scan(void)
-{
-       heap_scan_ptr = active.base;
-}
-
-INLINE CELL heap_step(CELL* size, CELL* type)
-{
-       CELL value = get(heap_scan_ptr);
-       CELL obj = heap_scan_ptr;
-
-       if(headerp(value))
-       {
-               *size = align8(untagged_object_size(heap_scan_ptr));
-               *type = untag_header(value);
-       }
-       else
-       {
-               *size = CELLS * 2;
-               *type = CONS_TYPE;
-       }
-
-       heap_scan_ptr += *size;
-
-       if(*type < HEADER_TYPE)
-               obj = RETAG(obj,*type);
-       else
-               obj = RETAG(obj,OBJECT_TYPE);
-
-       return obj;
-}
-
-INLINE bool walk_donep(void)
-{
-       return (heap_scan_ptr >= active.here);
-}
-
-void primitive_heap_stats(void);
-void primitive_instances(void);
-
-void primitive_begin_scan(void);
-void primitive_next_object(void);
-void primitive_end_scan(void);