]> gitweb.factorcode.org Git - factor.git/commitdiff
added new tuple metaclass, eventually to replace the traits metaclass
authorSlava Pestov <slava@factorcode.org>
Sat, 29 Jan 2005 21:39:30 +0000 (21:39 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 29 Jan 2005 21:39:30 +0000 (21:39 +0000)
23 files changed:
TODO.FACTOR.txt
factor/parser/Using.java
library/bootstrap/boot-stage2.factor
library/bootstrap/boot.factor
library/bootstrap/primitives.factor
library/generic/builtin.factor
library/generic/generic.factor
library/generic/traits.factor
library/generic/tuple.factor [new file with mode: 0644]
library/kernel.factor
library/namespaces.factor
library/primitives.factor
library/test/benchmark/vectors.factor
native/array.c
native/array.h
native/factor.h
native/gc.c
native/hashtable.c
native/primitives.c
native/relocate.c
native/types.c
native/types.h
native/vector.c

index 705daa5a9969855c27c1d4f71783a85826a6bcbd..be31f5fcbd60c5538243673c8b082bd237fae138 100644 (file)
@@ -39,6 +39,7 @@
 - maple-like: press enter at old commands to evaluate there\r
 - completion in the listener\r
 - special completion for USE:/IN:\r
+- support USING:\r
 \r
 + i/o:\r
 \r
index 9f36bfc4704a6e88fcea6267fb5873f53f909181..b4af3a3d353257196f55e306b2a950ef0d8c4624 100644 (file)
@@ -3,7 +3,7 @@
 /*
  * $Id$
  *
- * Copyright (C) 2004 Slava Pestov.
+ * 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:
@@ -44,7 +44,7 @@ public class Using extends FactorParsingDefinition
                for(;;)
                {
                        Object next = reader.next(false,false);
-                       if(next == null)
+                       if(next == FactorScanner.EOF)
                                reader.getScanner().error("Expected ;");
                        if(next.equals(";"))
                                break;
index d7cc3a86e38a74688063e7eca634b30e24d55bb6..2ba7557c7b50da88418f471c32bccf46b82d5dd1 100644 (file)
@@ -1,37 +1,6 @@
-! :folding=indent:collapseFolds=1:\r
-\r
-! $Id$\r
-!\r
 ! Copyright (C) 2004, 2005 Slava Pestov.\r
-! \r
-! Redistribution and use in source and binary forms, with or without\r
-! modification, are permitted provided that the following conditions are met:\r
-! \r
-! 1. Redistributions of source code must retain the above copyright notice,\r
-!    this list of conditions and the following disclaimer.\r
-! \r
-! 2. Redistributions in binary form must reproduce the above copyright notice,\r
-!    this list of conditions and the following disclaimer in the documentation\r
-!    and/or other materials provided with the distribution.\r
-! \r
-! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
-! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\r
-! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE\r
-! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
-! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
-! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
-! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
-! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
-! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r
-! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
-IN: init\r
-USE: kernel\r
-USE: lists\r
-USE: parser\r
-USE: stdio\r
-USE: words\r
-USE: namespaces\r
+! See http://factor.sf.net/license.txt for BSD license.\r
+USING: kernel lists parser stdio words namespaces ;\r
 \r
 "Cold boot in progress..." print\r
 \r
@@ -44,6 +13,7 @@ USE: namespaces
     "/library/generic/union.factor"\r
     "/library/generic/complement.factor"\r
     "/library/generic/traits.factor"\r
+    "/library/generic/tuple.factor"\r
 \r
     "/version.factor"\r
     "/library/stack.factor"\r
index 981d27daa9aa37ad2096d2e0802050c9dc770628..64de946fe1c176157390f23fe960f4aa32be7094 100644 (file)
@@ -1,39 +1,7 @@
-! :folding=none: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.
-
-USE: lists
-USE: image
-USE: parser
-USE: namespaces
-USE: stdio
-USE: kernel
-USE: vectors
-USE: words
-USE: hashtables
+! See http://factor.sf.net/license.txt for BSD license.
+USING: lists image parser namespaces stdio kernel vectors
+words hashtables ;
 
 "/library/bootstrap/primitives.factor" run-resource
 
@@ -88,6 +56,7 @@ USE: hashtables
     "/library/generic/union.factor" parse-resource append,
     "/library/generic/complement.factor" parse-resource append,
     "/library/generic/traits.factor" parse-resource append,
+    "/library/generic/tuple.factor" parse-resource append,
 
     "/library/bootstrap/init.factor" parse-resource append,
     "/library/syntax/parse-syntax.factor" parse-resource append,
index 8484cc844abdc730b2aebc58f05d05bc9d9595da..744f4e75769110bcaede018fb144ea9c79e863a4 100644 (file)
@@ -1,40 +1,8 @@
-! :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.
-
+! Copyright (C) 2004, 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
 IN: image
-USE: kernel
-USE: lists
-USE: math
-USE: namespaces
-USE: parser
-USE: words
-USE: vectors
-USE: hashtables
-USE: generic
+USING: kernel lists math namespaces parser words vectors
+hashtables generic ;
 
 ! Bring up a bare cross-compiling vocabulary.
 "syntax" vocab
@@ -226,6 +194,7 @@ vocabularies get [
     [[ "kernel-internals" "grow-array" ]]
     [[ "hashtables" "<hashtable>" ]]
     [[ "kernel-internals" "<array>" ]]
+    [[ "kernel-internals" "<tuple>" ]]
 ] [
     unswons create swap 1 + [ f define ] keep
 ] each drop
index 9d53bb2f143e922d7e26498e355bdd84432aa5ab..d61dc5369d429b9b68a2be1f96fd425bd4720588 100644 (file)
@@ -83,7 +83,7 @@ builtin [ 2drop t ] "class<" set-word-property
 : builtin-type ( n -- symbol )
     unit classes get hash ;
 
-: class ( obj -- class )
+M: object class ( obj -- class )
     #! Analogous to the type primitive. Pushes the builtin
     #! class of an object.
     type builtin-type ;
index 24cac9d7334fc481e25082bb2b1f09eb1011e230..83410dc1efc909b1cca459f4fe3aba3c2bf86c34 100644 (file)
@@ -1,50 +1,11 @@
-! :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: kernel-internals
-USE: lists
-USE: namespaces
-USE: parser
-USE: strings
-USE: words
-USE: vectors
-USE: math
-USE: math-internals
-USE: unparser
+USING: errors hashtables kernel kernel-internals lists
+namespaces parser strings words vectors math math-internals ;
 
 ! A simple single-dispatch generic word system.
 
-! "if I say I'd rather eat cheese than shit... doesn't mean
-! those are the only two things I can eat." - Tac
-
 : predicate-word ( word -- word )
     word-name "?" cat2 "in" get create ;
 
@@ -60,7 +21,7 @@ USE: unparser
 ! The class of an object with traits is determined by the object
 ! identity of the traits method map.
 ! - metaclass: a metaclass is a symbol with a handful of word
-! properties: "define-method" "builtin-types" "priority"
+! properties: "builtin-types" "priority"
 
 ! Metaclasses have priority -- this induces an order in which
 ! methods are added to the vtable.
@@ -107,12 +68,13 @@ USE: unparser
         >r 2dup r> unswons add-method
     ] each nip ;
 
-: define-generic ( word vtable -- )
+: make-generic ( word vtable -- )
     over "combination" word-property cons define-compound ;
 
-: (define-method) ( definition class generic -- )
+: define-method ( class generic definition -- )
+    -rot
     [ "methods" word-property set-hash ] keep dup <vtable>
-    define-generic ;
+    make-generic ;
 
 : init-methods ( word -- )
      dup "methods" word-property [
@@ -122,15 +84,14 @@ USE: unparser
      ] ifte ;
 
 ! Defining generic words
-: (GENERIC) ( combination definer -- )
+: define-generic ( combination definer word -- )
     #! Takes a combination parameter. A combination is a
     #! quotation that takes some objects and a vtable from the
     #! stack, and calls the appropriate row of the vtable.
-    CREATE
     [ swap "definer" set-word-property ] keep
     [ swap "combination" set-word-property ] keep
     dup init-methods
-    dup <vtable> define-generic ;
+    dup <vtable> make-generic ;
 
 : single-combination ( obj vtable -- )
     >r dup type r> dispatch ; inline
@@ -138,7 +99,8 @@ USE: unparser
 : GENERIC:
     #! GENERIC: bar creates a generic word bar. Add methods to
     #! the generic word using M:.
-    [ single-combination ] \ GENERIC: (GENERIC) ; parsing
+    [ single-combination ]
+    \ GENERIC: CREATE define-generic ; parsing
 
 : arithmetic-combination ( n n vtable -- )
     #! Note that the numbers remain on the stack, possibly after
@@ -150,19 +112,13 @@ USE: unparser
     #! the generic word using M:. 2GENERIC words dispatch on
     #! arithmetic types and should not be used for non-numerical
     #! types.
-    [ arithmetic-combination ] \ 2GENERIC: (GENERIC) ; parsing
-
-: define-method ( class -- quotation )
-    #! In a vain attempt at something resembling a "meta object
-    #! protocol", we call the "define-method" word property with
-    #! stack ( class generic definition -- ).
-    metaclass "define-method" word-property
-    [ [ -rot (define-method) ] ] unless* ;
+    [ 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  dup define-method  scan-word swap [ ] ; parsing
+    scan-word scan-word [ define-method ] [ ] ; parsing
 
 ! Maps lists of builtin type numbers to class objects.
 SYMBOL: classes
@@ -210,3 +166,5 @@ SYMBOL: object
     classes get set-hash ;
 
 classes get [ <namespace> classes set ] unless
+
+GENERIC: class ( obj -- class )
index 2bafb8053cdb3df83a8f72703602822246013a31..12c2c88cf2950e35d0882e2eaf56a4fbd1399275 100644 (file)
@@ -67,7 +67,7 @@ SYMBOL: delegate
 ] "add-method" set-word-property
 
 \ traits [
-    drop vector "builtin-type" word-property unit
+    drop hashtable "builtin-type" word-property unit
 ] "builtin-supertypes" set-word-property
 
 \ traits 10 "priority" set-word-property
diff --git a/library/generic/tuple.factor b/library/generic/tuple.factor
new file mode 100644 (file)
index 0000000..e622455
--- /dev/null
@@ -0,0 +1,91 @@
+! Copyright (C) 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
+IN: generic
+USING: words parser kernel namespaces lists strings
+kernel-internals math hashtables errors ;
+
+: make-tuple ( class -- )
+    dup "tuple-size" word-property <tuple>
+    [ 0 swap set-array-nth ] keep ;
+
+: define-tuple-generic ( tuple word def -- )
+    over >r \ single-combination \ GENERIC: r> define-generic
+    define-method ;
+
+: define-accessor ( word name n -- )
+    >r [ >r dup word-name , "-" , r> , ] make-string
+    "in" get create  r> [ slot ] cons define-tuple-generic ;
+
+: define-mutator ( word name n -- )
+    >r [ "set-" , >r dup word-name , "-" , r> , ] make-string
+    "in" get create  r> [ set-slot ] cons define-tuple-generic ;
+
+: define-field ( word name n -- )
+    3dup define-accessor define-mutator ;
+
+: tuple-predicate ( word -- )
+    #! Make a foo? word for testing the tuple class at the top
+    #! of the stack.
+    dup predicate-word swap
+    [ swap dup tuple? [ class eq? ] [ 2drop f ] ifte ] cons
+    define-compound ;
+
+: define-tuple ( word fields -- )
+    2dup length 1 + "tuple-size" set-word-property
+    dup length [ 3 + ] project zip
+    [ uncons define-field ] each-with ;
+
+: TUPLE:
+    #! Followed by a tuple name, then field names, then ;
+    CREATE
+    dup intern-symbol
+    dup tuple-predicate
+    dup define-promise
+    dup tuple "metaclass" set-word-property
+    string-mode on
+    [ string-mode off define-tuple ]
+    f ; parsing
+
+: constructor-word ( word -- word )
+    word-name "<" swap ">" cat3 "in" get create ;
+
+: tuple-constructor ( word def -- )
+    over constructor-word >r
+    [ swap literal, \ make-tuple , append, ] make-list
+    r> swap define-compound ;
+
+: TC:
+    #! Followed by a tuple name, then constructor code, then ;
+    #! Constructor code executes with the empty tuple on the
+    #! stack.
+    scan-word [ tuple-constructor ] f ; parsing
+
+: tuple-dispatch ( object selector -- object quot )
+    over class over "methods" word-property hash* dup [
+        nip cdr ( method is defined )
+    ] [
+       ! drop delegate rot hash [
+       !     swap tuple-dispatch ( check delegate )
+       ! ] [
+            [ undefined-method ] ( no delegate )
+       ! ] ifte*
+    ] ifte ;
+
+: add-tuple-dispatch ( word vtable -- )
+    >r unit [ car tuple-dispatch call ] cons tuple r>
+    set-vtable ;
+
+M: tuple class ( obj -- class ) 2 slot ;
+
+tuple [
+    ( generic vtable definition class -- )
+    2drop add-tuple-dispatch
+] "add-method" set-word-property
+
+tuple [
+    drop tuple "builtin-type" word-property unit
+] "builtin-supertypes" set-word-property
+
+tuple 10 "priority" set-word-property
+
+tuple [ 2drop t ] "class<" set-word-property
index d5e298a28e42fd3b25471db1e3c568914cd3a5da..6002ab66c5e7d7ff8ca207dabea2523a8ec22871 100644 (file)
@@ -7,6 +7,8 @@ IN: kernel-internals USING: generic kernel vectors ;
     #! call it directly.
     vector-array array-nth call ;
 
+BUILTIN: tuple 18
+
 IN: kernel
 
 GENERIC: hashcode ( obj -- n )
@@ -32,7 +34,7 @@ M: object clone ;
 
 : num-types ( -- n )
     #! One more than the maximum value from type primitive.
-    18 ;
+    19 ;
 
 : ? ( cond t f -- t/f )
     #! Push t if cond is true, otherwise push f.
index 93a4f9930790e963a8677c5176b2a82798b3a599..1519c2fdd06b5f8fa66b0346fc5f9c9a9a9b5a14 100644 (file)
@@ -141,3 +141,8 @@ SYMBOL: list-buffer
 
 : append, ( list -- )
     [ , ] each ;
+
+: literal, ( word -- )
+    #! Append some code that pushes the word on the stack. Used
+    #! when building quotations.
+    unit , \ car , ;
index 3594354fa5bd9dc09afd58f2776146cb6e699240..3a9f4d3b8063a454f783df37d692caab725adb04 100644 (file)
@@ -184,6 +184,7 @@ hashtables ;
     [ grow-array             [ [ integer array ] [ object ] ] ]
     [ <hashtable>            [ [ number ] [ hashtable ] ] ]
     [ <array>                [ [ number ] [ array ] ] ]
+    [ <tuple>                [ [ number ] [ tuple ] ] ]
 ] [
     2unlist dup string? [
         "stack-effect" set-word-property
index 8d6a767991bd2ea918264c24da3ca88e1f6107f7..2afe57094602e66b8a839991f6d482750e0f328d 100644 (file)
@@ -20,4 +20,4 @@ USE: test
 : vector-benchmark ( n -- )
     0 <vector> over fill-vector rot copy-vector ; compiled
 
-[ ] [ 4000000 vector-benchmark ] unit-test
+[ ] [ 400000 vector-benchmark ] unit-test
index 191d234470f8c01c1d7fa2f440c2d035cdda3cae..d7e7b9751023bfdd822ec7cc3be807ea0cd523e5 100644 (file)
@@ -10,11 +10,11 @@ F_ARRAY* allot_array(CELL type, CELL capacity)
 }
 
 /* untagged */
-F_ARRAY* array(CELL capacity, CELL fill)
+F_ARRAY* array(CELL type, CELL capacity, CELL fill)
 {
        int i;
 
-       F_ARRAY* array = allot_array(ARRAY_TYPE, capacity);
+       F_ARRAY* array = allot_array(type, capacity);
 
        for(i = 0; i < capacity; i++)
                put(AREF(array,i),fill);
@@ -28,7 +28,16 @@ void primitive_array(void)
        if(capacity < 0)
                general_error(ERROR_NEGATIVE_ARRAY_SIZE,tag_fixnum(capacity));
        maybe_garbage_collection();
-       dpush(tag_object(array(capacity,F)));
+       dpush(tag_object(array(ARRAY_TYPE,capacity,F)));
+}
+
+void primitive_tuple(void)
+{
+       F_FIXNUM capacity = to_fixnum(dpop());
+       if(capacity < 0)
+               general_error(ERROR_NEGATIVE_ARRAY_SIZE,tag_fixnum(capacity));
+       maybe_garbage_collection();
+       dpush(tag_object(array(TUPLE_TYPE,capacity,F)));
 }
 
 F_ARRAY* grow_array(F_ARRAY* array, CELL capacity, CELL fill)
@@ -43,7 +52,7 @@ F_ARRAY* grow_array(F_ARRAY* array, CELL capacity, CELL fill)
 
        new_array = allot_array(untag_header(array->header),capacity);
 
-       memcpy(new_array + 1,array + 1,array->capacity * CELLS);
+       memcpy(new_array + 1,array + 1,curr_cap * CELLS);
 
        for(i = curr_cap; i < capacity; i++)
                put(AREF(new_array,i),fill);
index 28d71a4b4134648f2839b7582078d56d8050fc4f..7f048c0f0ff9eb6cc1a388b40659777358af49a4 100644 (file)
@@ -11,8 +11,9 @@ INLINE F_ARRAY* untag_array(CELL tagged)
 }
 
 F_ARRAY* allot_array(CELL type, CELL capacity);
-F_ARRAY* array(CELL capacity, CELL fill);
+F_ARRAY* array(CELL type, CELL capacity, CELL fill);
 void primitive_array(void);
+void primitive_tuple(void);
 F_ARRAY* grow_array(F_ARRAY* array, CELL capacity, CELL fill);
 void primitive_grow_array(void);
 F_ARRAY* shrink_array(F_ARRAY* array, CELL capacity);
index 49f7ed2a60170fe1e2b1d1ddf82db764015948d9..d0749dc2be236fb119308bb64224cf8c5dbe07fe 100644 (file)
@@ -101,8 +101,8 @@ DLLEXPORT CELL cs;
 typedef unsigned char BYTE;
 
 /* Memory areas */
-#define DEFAULT_ARENA (64 * 1024 * 1024)
-#define COMPILE_ZONE_SIZE (64 * 1024 * 1024)
+#define DEFAULT_ARENA (8 * 1024 * 1024)
+#define COMPILE_ZONE_SIZE (8 * 1024 * 1024)
 #define STACK_SIZE (2 * 1024 * 1024)
 
 #include "memory.h"
index 5e2c880970ad64d950d028402d1f87ca4c91678e..6c33083a435dd4b4a3b324fbf1ca7d1b78357cd9 100644 (file)
@@ -69,6 +69,7 @@ INLINE void collect_object(CELL scan)
                collect_word((F_WORD*)scan);
                break;
        case ARRAY_TYPE:
+       case TUPLE_TYPE:
                collect_array((F_ARRAY*)scan);
                break;
        case HASHTABLE_TYPE:
index cb27bd4c01d338b91d7c1a90e12efb61fff984ab..25ce2e72bc52516e6af1dc7345bed9bf3f219dd5 100644 (file)
@@ -7,7 +7,7 @@ F_HASHTABLE* hashtable(F_FIXNUM capacity)
                general_error(ERROR_NEGATIVE_ARRAY_SIZE,tag_fixnum(capacity));
        hash = allot_object(HASHTABLE_TYPE,sizeof(F_VECTOR));
        hash->count = tag_fixnum(0);
-       hash->array = tag_object(array(capacity,F));
+       hash->array = tag_object(array(ARRAY_TYPE,capacity,F));
        return hash;
 }
 
index bf0723d7a9140bf4df3c517005bcb94cebc3f7d4..3a426e454c64fd3f55ce16ba2a8994f542163917 100644 (file)
@@ -175,7 +175,8 @@ void* primitives[] = {
        primitive_set_integer_slot,
        primitive_grow_array,
        primitive_hashtable,
-       primitive_array
+       primitive_array,
+       primitive_tuple
 };
 
 CELL primitive_to_xt(CELL primitive)
index c6dfd0e73b935ea3ba863e8012cedee98a0c63bb..63abe8940cbfcd5f185f24db307295e17bc817c4 100644 (file)
@@ -8,6 +8,7 @@ void relocate_object(CELL relocating)
                fixup_word((F_WORD*)relocating);
                break;
        case ARRAY_TYPE:
+       case TUPLE_TYPE:
                fixup_array((F_ARRAY*)relocating);
                break;
        case HASHTABLE_TYPE:
index a4048d22ed2b64d460943024d5079b8491e52531..d034b67be2f6851d2dec748438a6d4db3dd6be65 100644 (file)
@@ -53,6 +53,7 @@ CELL untagged_object_size(CELL pointer)
                break;
        case ARRAY_TYPE:
        case BIGNUM_TYPE:
+       case TUPLE_TYPE:
                size = ASIZE(pointer);
                break;
        case HASHTABLE_TYPE:
index ac481e47dab5d988c1dfef6769a953ba07fd58bf..a5c51fb60a58f9c9e0adf89faa1ee71f79baa926 100644 (file)
@@ -12,7 +12,7 @@
 #define RATIO_TYPE 4
 #define FLOAT_TYPE 5
 #define COMPLEX_TYPE 6
-#define HEADER_TYPE 7
+#define HEADER_TYPE 7 /* anything less than this is a tag */
 #define GC_COLLECTED 7 /* See gc.c */
 
 /*** Header types ***/
@@ -35,8 +35,9 @@ CELL T;
 #define DLL_TYPE 15
 #define ALIEN_TYPE 16
 #define WORD_TYPE 17
+#define TUPLE_TYPE 18
 
-#define TYPE_COUNT 18
+#define TYPE_COUNT 19
 
 INLINE bool headerp(CELL cell)
 {
index 010c1f6b58c6f6ee082a3e5c5ad5727d759ec565..e75b6b4ffc88ae2e4eac7c9d71dd8ba60815755e 100644 (file)
@@ -7,7 +7,7 @@ F_VECTOR* vector(F_FIXNUM capacity)
                general_error(ERROR_NEGATIVE_ARRAY_SIZE,tag_fixnum(capacity));
        vector = allot_object(VECTOR_TYPE,sizeof(F_VECTOR));
        vector->top = tag_fixnum(0);
-       vector->array = tag_object(array(capacity,F));
+       vector->array = tag_object(array(ARRAY_TYPE,capacity,F));
        return vector;
 }