]> gitweb.factorcode.org Git - factor.git/commitdiff
array refactoring; started hashtable refactoring
authorSlava Pestov <slava@factorcode.org>
Wed, 26 Jan 2005 00:40:57 +0000 (00:40 +0000)
committerSlava Pestov <slava@factorcode.org>
Wed, 26 Jan 2005 00:40:57 +0000 (00:40 +0000)
27 files changed:
Makefile
TODO.FACTOR.txt
examples/grad-demo.factor [new file with mode: 0644]
examples/mandel.factor
library/arrays.factor [new file with mode: 0644]
library/bootstrap/boot-stage2.factor
library/bootstrap/boot.factor
library/bootstrap/init-stage2.factor
library/bootstrap/primitives.factor
library/hashtables.factor
library/inference/branches.factor
library/inference/types.factor
library/kernel.factor
library/namespaces.factor
library/primitives.factor
library/test/vectors.factor
library/ui/console.factor
library/vectors.factor
native/array.h
native/gc.c
native/image.c
native/memory.c
native/primitives.c
native/primitives.h
native/unix/signal.c
native/vector.c
native/vector.h

index 417c47a299f2f2ac842a694b9ce6539237c38df2..879eca23bcc6705dd556c2584f978adee0f2ad28 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 CC = gcc
-DEFAULT_CFLAGS = -Wall -g $(SITE_CFLAGS)
+DEFAULT_CFLAGS = -Wall -Os -fomit-frame-pointer $(SITE_CFLAGS)
 DEFAULT_LIBS = -lm
 
 STRIP = strip
@@ -68,7 +68,7 @@ solaris:
 
 f: $(OBJS)
        $(CC) $(LIBS) $(CFLAGS) -o $@ $(OBJS)
-       #$(STRIP) $@
+       $(STRIP) $@
 
 clean:
        rm -f $(OBJS)
index c7c527da708e5e8233254dc805c92bea2db8d22d..3ec887c84fe6d219907a72a45aa2f3a557b6ae77 100644 (file)
@@ -17,6 +17,9 @@
 \r
 + ffi:\r
 \r
+- value type structs\r
+- unicode strings\r
+- out parameters\r
 - figure out how to load an image referring to missing libraries\r
 - is signed -vs- unsigned pointers an issue?\r
 - bitfields in C structs\r
 + kernel:\r
 \r
 - ppc register decls\r
-- do partial objects cause problems?\r
-- remove sbufs\r
 - cat, reverse-cat primitives\r
 - first-class hashtables\r
 \r
 + misc:\r
 \r
+- make-vector and make-string should not need a reverse step\r
 - perhaps /i should work with all numbers\r
 - jedit ==> jedit-word, jedit takes a file name\r
 - browser responder for word links in HTTPd\r
diff --git a/examples/grad-demo.factor b/examples/grad-demo.factor
new file mode 100644 (file)
index 0000000..efacf32
--- /dev/null
@@ -0,0 +1,45 @@
+! Gradient rendering demo.
+!
+! To run this code, bootstrap Factor like so:
+!
+! ./f boot.image.le32
+!     -libraries:sdl:name=libSDL.so
+!     -libraries:sdl-gfx:name=libSDL_gfx.so
+!     -libraries:sdl-ttf:name=libSDL_ttf.so
+!
+! (But all on one line)
+!
+! Then, start Factor as usual (./f factor.image) and enter this
+! at the listener:
+!
+! "examples/grad-demo.factor" run-file
+
+IN: grad-demo
+USE: streams
+USE: sdl
+USE: sdl-event
+USE: sdl-gfx
+USE: sdl-video
+USE: sdl-ttf
+USE: namespaces
+USE: math
+USE: kernel
+USE: test
+USE: compiler
+USE: strings
+USE: alien
+USE: prettyprint
+USE: lists
+
+: draw-grad ( -- )
+    [ over rgb ] with-pixels ; compiled
+
+: grad-demo ( -- )
+    640 480 0 SDL_HWSURFACE [
+        TTF_Init
+        [ draw-grad ] with-surface
+        <event> event-loop
+        SDL_Quit
+    ] with-screen ;
+
+grad-demo
index a4384c2878e72bcf1e60eb060ee03a222682ce06..5ee2fcaf6f8f5ca7427a0d8e680d156c0f44f715 100644 (file)
@@ -32,7 +32,7 @@ USE: test
 
 : scale 255 * >fixnum ;
 
-: scale-rgb ( r g b -- n )
+: scale-rgb ( r g b -- n )
     scale
     swap scale 8 shift bitor
     swap scale 16 shift bitor
@@ -44,10 +44,10 @@ USE: test
 : <color-map> ( nb-cols -- map )
     [
         dup [
-            dup 360 * over 1 + / 360 / sat val
+            dup 360 * pick 1 + / 360 / sat val
             hsv>rgb 1.0 scale-rgb ,
         ] repeat
-    ] make-list list>vector nip ;
+    ] make-vector nip ;
 
 : absq >rect swap sq swap sq + ; inline
 
@@ -72,7 +72,7 @@ SYMBOL: center
     height get 150000 zoom-fact get * / y-inc set
     nb-iter get max-color min <color-map> cols set ;
 
-: c ( #{ i j }# -- c )
+: c ( i j -- c )
     >r
     x-inc get * center get real x-inc get width get 2 / * - + >float
     r>
@@ -89,7 +89,7 @@ SYMBOL: center
     ] with-pixels ; compiled
 
 : mandel ( -- )
-    640 480 32 SDL_HWSURFACE [
+    640 480 0 SDL_HWSURFACE [
         [
             0.8 zoom-fact set
             -0.65 center set
diff --git a/library/arrays.factor b/library/arrays.factor
new file mode 100644 (file)
index 0000000..3026f58
--- /dev/null
@@ -0,0 +1,53 @@
+! :folding=none: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.
+
+IN: kernel-internals
+USE: generic
+USE: math-internals
+USE: kernel
+
+! An array is a range of memory storing pointers to other
+! objects. Arrays are not used directly, and their access words
+! are not bounds checked. Examples of abstractions built on
+! arrays include vectors, hashtables, and tuples.
+
+! These words are unsafe. I'd say "do not call them", but that
+! Java-esque. By all means, do use arrays if you need something
+! low-level... but be aware that vectors are usually a better
+! choice.
+
+BUILTIN: array 8
+
+: array-capacity   ( array -- n )   1 integer-slot ; inline
+: vector-array     ( vec -- array ) 2 slot ; inline
+: set-vector-array ( array vec -- ) 2 set-slot ; inline
+
+: array-nth ( n array -- obj )
+    swap 2 fixnum+ slot ; inline
+
+: set-array-nth ( obj n array -- )
+    swap 2 fixnum+ set-slot ; inline
index 2456ed93f7cdaa62eafc42f82b012bbc636ccf98..fdd77c2046bc073e5e5b6e8c691ac82085bd93c4 100644 (file)
@@ -48,6 +48,7 @@ USE: namespaces
     "/version.factor"\r
     "/library/stack.factor"\r
     "/library/combinators.factor"\r
+    "/library/arrays.factor"\r
     "/library/kernel.factor"\r
     "/library/cons.factor"\r
     "/library/assoc.factor"\r
index 49a272f6c5b6927e2e5458ef1ec8e7e957181371..d991caa7090d298cd0fe6bd3b158a1df719613d7 100644 (file)
@@ -42,6 +42,7 @@ USE: hashtables
     "/version.factor" parse-resource append,
     "/library/stack.factor" parse-resource append,
     "/library/combinators.factor" parse-resource append,
+    "/library/arrays.factor" parse-resource append,
     "/library/kernel.factor" parse-resource append,
     "/library/cons.factor" parse-resource append,
     "/library/assoc.factor" parse-resource append,
index edf3b320468e7280dbdce6ba2543595e8f6e8000..32a38e6ac1449caa09342c71108b1968f0f9387e 100644 (file)
@@ -114,6 +114,5 @@ unparse write " words total" print
 ! Save a bit of space
 global [ stdio off ] bind
 
-garbage-collection
 "factor.image" save-image
 0 exit*
index 2017b45a2359a66f52c538b7e12a9d1a7f298d70..0b45a454ae93f2bf4cff7d45b18d44486338d033 100644 (file)
@@ -59,8 +59,6 @@ vocabularies get [
     [[ "kernel" "ifte" ]]
     [[ "lists" "cons" ]]
     [[ "vectors" "<vector>" ]]
-    [[ "vectors" "vector-nth" ]]
-    [[ "vectors" "set-vector-nth" ]]
     [[ "strings" "str-nth" ]]
     [[ "strings" "str-compare" ]]
     [[ "strings" "str=" ]]
index 33e65a94cfacaf97a61ac1a4e6e77d4c10d2aade..9750f2430e316463c76e9041454601d3be113e2c 100644 (file)
@@ -2,7 +2,7 @@
 
 ! $Id$
 !
-! Copyright (C) 2004 Slava Pestov.
+! 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:
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: hashtables
+IN: kernel-internals
 USE: generic
 USE: kernel
 USE: lists
 USE: math
 USE: vectors
 
+: hash-array vector-array ; inline
+: bucket-count >vector hash-array array-capacity ; inline
+
+: hash-bucket ( n hash -- alist )
+    swap >fixnum swap >vector hash-array array-nth ; inline
+
+: set-hash-bucket ( obj n hash -- )
+    >r >fixnum r> hash-array set-array-nth ; inline
+
+IN: hashtables
+
 ! Note that the length of a hashtable vector must not change
 ! for the lifetime of the hashtable, otherwise problems will
 ! occur. Do not use vector words with hashtables.
@@ -48,13 +59,13 @@ PREDICATE: vector hashtable ( obj -- ? )
 
 : (hashcode) ( key table -- index )
     #! Compute the index of the bucket for a key.
-    >r hashcode r> vector-length rem ; inline
+    >r hashcode r> bucket-count rem ; inline
 
 : hash* ( key table -- [[ key value ]] )
     #! Look up a value in the hashtable. First the bucket is
     #! determined using the hash function, then the association
     #! list therein is searched linearly.
-    2dup (hashcode) swap vector-nth assoc* ;
+    2dup (hashcode) swap hash-bucket assoc* ;
 
 : hash ( key table -- value )
     #! Unlike hash*, this word cannot distinglish between an
@@ -67,9 +78,9 @@ PREDICATE: vector hashtable ( obj -- ? )
         2dup (hashcode)
     r> pick >r
         over >r
-            >r swap vector-nth r> call
+            >r swap hash-bucket r> call
         r>
-    r> set-vector-nth ; inline
+    r> set-hash-bucket ; inline
     
 : set-hash ( value key table -- )
     #! Store the value in the hashtable. Either replaces an
@@ -85,12 +96,6 @@ PREDICATE: vector hashtable ( obj -- ? )
     #! Apply the code to each key/value pair of the hashtable.
     swap [ swap dup >r each r> ] vector-each drop ; inline
 
-: hash-subset ( hash code -- hash )
-    #! Return a new hashtable containing all key/value pairs
-    #! for which the predicate yielded a true value. The
-    #! predicate must have stack effect ( obj -- ? ).
-    swap [ swap dup >r subset r> swap ] vector-map nip ; inline
-
 : hash-keys ( hash -- list )
     #! Push a list of keys in a hashtable.
     [ ] swap [ car swons ] hash-each ;
index c54e1c07a8c05d76968de81c6587d8ec0f3423d3..d78fe2a164cd72767d92a50cc1c521a7e701374f 100644 (file)
@@ -73,7 +73,7 @@ USE: prettyprint
 : unify-stacks ( list -- stack )
     #! Replace differing literals in stacks with unknown
     #! results.
-    unify-lengths vector-transpose [ unify-results ] vector-map ;
+    unify-lengths vector-transpose [ unify-results ] vector-map ; 
 
 : balanced? ( list -- ? )
     #! Check if a list of [[ instack outstack ]] pairs is
@@ -104,7 +104,7 @@ USE: prettyprint
     ] unless* ;
 
 : unify-effects ( list -- )
-    filter-terminators  dup datastack-effect callstack-effect ;
+    filter-terminators dup datastack-effect callstack-effect ;
 
 SYMBOL: cloned
 
index 5e6b19d114afd23df8ebb81f1c3cb6f6f4939084..7acdc8e7b8775ccbf30f95a1a4cfa64305b858d1 100644 (file)
@@ -63,15 +63,15 @@ USE: prettyprint
     \ >string \ string infer-check
 ] "infer" set-word-property
 
-\ slot [
-    [ object fixnum ] ensure-d
-    dataflow-drop, pop-d literal-value
-    peek-d value-class builtin-supertypes dup length 1 = [
-        cons \ slot [ [ object ] [ object ] ] (consume/produce)
-    ] [
-        "slot called without static type knowledge" throw
-    ] ifte
-] "infer" set-word-property
+\ slot [
+    [ object fixnum ] ensure-d
+    dataflow-drop, pop-d literal-value
+    peek-d value-class builtin-supertypes dup length 1 = [
+        cons \ slot [ [ object ] [ object ] ] (consume/produce)
+    ] [
+        "slot called without static type knowledge" throw
+    ] ifte
+] "infer" set-word-property
 
 : type-value-map ( value -- )
     num-types [ dup builtin-type pick swons cons ] project
index fe3753350265ed9b2585a005bf1ea35efc747d50..fb3c4544afc3571cdb658a854672bdd9116b9121 100644 (file)
@@ -31,9 +31,9 @@ USE: kernel
 USE: vectors
 
 : dispatch ( n vtable -- )
-    #! This word is unsafe in compiled code since n is not
-    #! bounds-checked. Do not call it directly.
-    vector-nth call ;
+    #! This word is unsafe since n is not bounds-checked. Do not
+    #! call it directly.
+    vector-array array-nth call ;
 
 IN: kernel
 
index e1632b9c479fdf7791e8476e0f9975641f761c70..362f0f3754643eb2c77ee83eb683f30127e6bb54 100644 (file)
@@ -153,6 +153,11 @@ SYMBOL: list-buffer
     #! was called.
     make-rlist reverse ; inline
 
+: make-vector ( quot -- list )
+    #! Return a vector whose entries are in the same order that
+    #! , was called.
+    make-list list>vector ; inline
+
 : , ( obj -- )
     #! Append an object to the currently constructing list.
     list-buffer cons@ ;
index b37e757da99f68d0efe888135993db517e8e16ee..14fe6e7421f4de18ec170cd3daa4cac62721e302 100644 (file)
@@ -55,8 +55,6 @@ USE: words
     [ ifte                   [ [ object general-list general-list ] [ ] ] ]
     [ cons                   [ [ object object ] [ cons ] ] ]
     [ <vector>               [ [ integer ] [ vector ] ] ]
-    [ vector-nth             [ [ integer vector ] [ object ] ] ]
-    [ set-vector-nth         [ [ object integer vector ] [ ] ] ]
     [ str-nth                [ [ integer string ] [ integer ] ] ]
     [ str-compare            [ [ string string ] [ integer ] ] ]
     [ str=                   [ [ string string ] [ boolean ] ] ]
@@ -222,7 +220,7 @@ USE: words
     [ set-slot               [ [ object object fixnum ] [ ] ] ]
     [ integer-slot           [ [ object fixnum ] [ integer ] ] ]
     [ set-integer-slot       [ [ integer object fixnum ] [ ] ] ]
-    [ grow-array             [ [ integer array ] [ integer ] ] ]
+    [ grow-array             [ [ integer array ] [ object ] ] ]
 ] [
     2unlist dup string? [
         "stack-effect" set-word-property
index 0b901472e34882309fa45e9ae42aedb956b7ba0d..8a8afb976ca5db4eaf5394723de437528a9fc782 100644 (file)
@@ -6,10 +6,12 @@ USE: test
 USE: vectors
 USE: strings
 USE: namespaces
+USE: kernel-internals
 
 [ [ t f t ] vector-length ] unit-test-fails
 [ 3 ] [ { t f t } vector-length ] unit-test
 
+[ -3 { } vector-nth ] unit-test-fails
 [ 3 { } vector-nth ] unit-test-fails
 [ 3 #{ 1 2 }# vector-nth ] unit-test-fails
 
@@ -74,3 +76,9 @@ unit-test
 [ "funny-stack" get vector-pop ] unit-test-fails
 [ ] [ "funky" "funny-stack" get vector-push ] unit-test
 [ "funky" ] [ "funny-stack" get vector-pop ] unit-test
+
+[ t ] [
+    10 <vector> dup vector-array array-capacity
+    >r vector-clone vector-array array-capacity r>
+    =
+] unit-test
index 94188269631bd5e70c26bf6de422f681c4dda070..1b97d2bfafefec3a2bb8fcb783222ca995627b78 100644 (file)
@@ -83,6 +83,9 @@ SYMBOL: input-line
 SYMBOL: console-font
 #! Font height.
 SYMBOL: line-height
+#! If this is on, the console will be redrawn on the next event
+#! refresh cycle.
+SYMBOL: redraw-console
 
 #! The font size is hardcoded here.
 : char-width 8 ;
@@ -174,8 +177,10 @@ SYMBOL: line-height
         0 y set
         clear-display
         draw-lines
-        draw-current
-        draw-input
+        height get y get - line-height get >= [
+            draw-current
+            draw-input
+        ] when
         draw-scrollbar
     ] with-surface ;
 
@@ -186,7 +191,7 @@ SYMBOL: line-height
     lines get vector-push scroll-to-bottom ;
 
 : console-write ( text -- )
-    "\n" split1 [       
+    "\n" split1 [
         swap output-line get sbuf-append
         output-line get empty-buffer add-line
     ] when*
@@ -215,7 +220,7 @@ M: console-stream fflush ( stream -- )
 
 M: console-stream fauto-flush ( stream -- )
     [
-        console get [ draw-console ] bind
+        console get [ redraw-console on ] bind
     ] bind ;
 
 M: console-stream freadln ( stream -- line )
@@ -280,10 +285,10 @@ SYMBOL: keymap
 
 M: key-down-event handle-event ( event -- ? )
     dup keyboard-event>binding keymap get hash [
-        call draw-console
+        call redraw-console on
     ] [
         dup input-key? [
-            keyboard-event-unicode user-input draw-console
+            keyboard-event-unicode user-input redraw-console on
         ] [
             drop
         ] ifte
@@ -296,10 +301,10 @@ SYMBOL: drag-start-line
 
 : scrollbar-click ( y -- )
     dup scrollbar-top < [
-        drop page-scroll-up draw-console
+        drop page-scroll-up redraw-console on
     ] [
         dup scrollbar-bottom > [
-            drop page-scroll-down draw-console
+            drop page-scroll-down redraw-console on
         ] [
             drag-start-y set
             first-line get drag-start-line set
@@ -323,7 +328,7 @@ M: motion-event handle-event ( event -- ? )
         motion-event-y drag-start-y get -
         height get / total-lines * drag-start-line get +
         >fixnum fix-first-line first-line set
-        draw-console
+        redraw-console on
     ] [
         drop
     ] ifte t ;
@@ -332,7 +337,7 @@ M: resize-event handle-event ( event -- ? )
     dup resize-event-w swap resize-event-h
     0 SDL_HWSURFACE SDL_RESIZABLE bitor init-screen
     scroll-to-bottom
-    draw-console t ;
+    redraw-console on t ;
 
 M: quit-event handle-event ( event -- ? )
     drop f ;
@@ -366,6 +371,7 @@ M: alien handle-event ( event -- ? )
     SDL_EnableKeyRepeat drop ;
 
 : console-loop ( -- )
+    redraw-console get [ draw-console redraw-console off ] when
     check-event [ console-loop ] when ;
 
 : console-quit ( -- )
@@ -395,7 +401,7 @@ IN: shells
         ] callcc0
 
         console get [
-            draw-console
+            redraw-console on
             console-loop
             console-quit
         ] bind
index ffa7ce67d8a0dcdba453bce518243aa8c76fb4cd..48f149c7ad88592bf23432bfea4e988b249f7089 100644 (file)
@@ -2,7 +2,7 @@
 
 ! $Id$
 !
-! Copyright (C) 2004 Slava Pestov.
+! 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:
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+IN: vectors
 USE: generic
 USE: kernel
 USE: lists
 USE: math
+USE: kernel-internals
+USE: errors
+USE: math-internals
+
+BUILTIN: vector 11
 
-IN: errors
-DEFER: throw
+: vector-length ( vec -- len ) >vector 1 integer-slot ; inline
 
 IN: kernel-internals
 
-BUILTIN: array 8
+: (set-vector-length) ( len vec -- ) 1 set-integer-slot ; inline
+
+: assert-positive ( fx -- )
+    0 fixnum<
+    [ "Vector index must be positive" throw ] when ; inline
 
-! UNSAFE!
-: array-capacity   ( array -- n )   1 integer-slot ; inline
-: vector-array     ( vec -- array ) 2 slot ; inline
-: set-vector-array ( array vec -- ) 2 set-slot ; inline
+: assert-bounds ( fx vec -- )
+    over assert-positive
+    vector-length fixnum>=
+    [ "Vector index out of bounds" throw ] when ; inline
 
-: grow-vector-array ( len vec -- )
+: grow-capacity ( len vec -- )
+    #! If the vector cannot accomodate len elements, resize it
+    #! to exactly len.
     [ vector-array grow-array ] keep set-vector-array ; inline
 
-: (set-vector-length) ( len vec -- ) 1 set-integer-slot ; inline
+: ensure-capacity ( n vec -- )
+    #! If n is beyond the vector's length, increase the length,
+    #! growing the array if necessary, with an optimistic
+    #! doubling of its size.
+    2dup vector-length fixnum>= [
+        >r 1 fixnum+ r>
+        2dup vector-array array-capacity fixnum> [
+            over 2 fixnum* over grow-capacity
+        ] when
+        (set-vector-length)
+    ] [
+        2drop
+    ] ifte ; inline
 
 IN: vectors
 
-BUILTIN: vector 11
+: vector-nth ( n vec -- obj )
+    swap >fixnum swap >vector
+    2dup assert-bounds vector-array array-nth ;
 
-: vector-length ( vec -- len ) >vector 1 integer-slot ; inline
+: set-vector-nth ( obj n vec -- )
+    swap >fixnum dup assert-positive swap >vector
+    2dup ensure-capacity vector-array
+    set-array-nth ;
 
 : set-vector-length ( len vec -- )
-    >vector over 0 < [
-        "Vector length must be positive" throw 2drop
-    ] [
-        2dup (set-vector-length) grow-vector-array
-    ] ifte ; inline
+    swap >fixnum dup assert-positive swap >vector
+    2dup grow-capacity (set-vector-length) ;
 
 : empty-vector ( len -- vec )
     #! Creates a vector with 'len' elements set to f. Unlike
index 74d56506e7c4001728a21a4f935415b4b6331068..acc77a099177a787c2cc7dce327c95661ffcac70 100644 (file)
@@ -21,17 +21,5 @@ F_ARRAY* shrink_array(F_ARRAY* array, CELL capacity);
 #define ASIZE(pointer) align8(sizeof(F_ARRAY) + \
        ((F_ARRAY*)(pointer))->capacity * CELLS)
 
-/* untagged & unchecked */
-INLINE CELL array_nth(F_ARRAY* array, CELL index)
-{
-       return get(AREF(array,index));
-}
-
-/* untagged & unchecked  */
-INLINE void set_array_nth(F_ARRAY* array, CELL index, CELL value)
-{
-       put(AREF(array,index),value);
-}
-
 void fixup_array(F_ARRAY* array);
 void collect_array(F_ARRAY* array);
index 784677928cf7871e71e767c7f45d929251e75008..b075429cada40de63389b4b02ba057a76f8ed3b8 100644 (file)
@@ -119,7 +119,7 @@ void primitive_gc(void)
        fflush(stderr);
 
        flip_zones();
-       scan = active.here = active.base;
+       scan = active.base;
        collect_roots();
        collect_io_tasks();
        /* collect literal objects referenced from compiled code */
index 75cd0bd0ef530c50980dd9caaf3f028bf43eecda..650d8e67d88374451de41b832b7753a4099d179c 100644 (file)
@@ -115,6 +115,8 @@ bool save_image(char* filename)
 
 void primitive_save_image(void)
 {
-       F_STRING* filename = untag_string(dpop());
+       F_STRING* filename;
+       primitive_gc();
+       filename = untag_string(dpop());
        save_image(to_c_string(filename));
 }
index 8173732863faf64028f2a9979db32b6e18976ebe..62e10b63dc58ffb27478b345a2c3e6b1a1b3082f 100644 (file)
@@ -87,6 +87,7 @@ void flip_zones()
        ZONE z = active;
        active = prior;
        prior = z;
+       active.here = active.base;
 }
 
 bool in_zone(ZONE* z, CELL pointer)
index dd7d6a652a591ec6e7e1505170df1cae9b1512db..07dd50f0343da06d3d3872387624f095453b4cee 100644 (file)
@@ -9,8 +9,6 @@ void* primitives[] = {
        primitive_ifte,
        primitive_cons,
        primitive_vector,
-       primitive_vector_nth,
-       primitive_set_vector_nth,
        primitive_string_nth,
        primitive_string_compare,
        primitive_string_eq,
index 60736374aa5814f19d3e983acd43746304248f1c..353fbfe10a6bdd949c67d4eb405ea34af494af42 100644 (file)
@@ -1,4 +1,4 @@
 extern void* primitives[];
-#define PRIMITIVE_COUNT 195
+#define PRIMITIVE_COUNT 194
 
 CELL primitive_to_xt(CELL primitive);
index 40818072c29b615122f25f5476806cf865afcc22..d65acfe7c1cf7956c9c9ebb7894d89f9009edc97 100644 (file)
@@ -9,6 +9,8 @@ void signal_handler(int signal, siginfo_t* siginfo, void* uap)
                fprintf(stderr,"active.here  = %ld\n",active.here);
                fprintf(stderr,"active.limit = %ld\n",active.limit);
                fflush(stderr);
+               flip_zones();
+               dump_stacks();
                exit(1);
        }
        else
index 921ea3444d519c38c2fea809e40a7c3e6b6a6c16..2b2e4a686651648836e9058c8175b4214e0b73bf 100644 (file)
@@ -22,47 +22,6 @@ void primitive_to_vector(void)
        type_check(VECTOR_TYPE,dpeek());
 }
 
-void primitive_vector_nth(void)
-{
-       F_VECTOR* vector = untag_vector(dpop());
-       CELL index = to_fixnum(dpop());
-
-       if(index < 0 || index >= vector->top)
-               range_error(tag_object(vector),0,tag_fixnum(index),vector->top);
-       dpush(array_nth(untag_array(vector->array),index));
-}
-
-void vector_ensure_capacity(F_VECTOR* vector, CELL index)
-{
-       F_ARRAY* array = untag_array(vector->array);
-       CELL capacity = array->capacity;
-       if(index >= capacity)
-               array = grow_array(array,index * 2 + 1,F);
-       vector->top = index + 1;
-       vector->array = tag_object(array);
-}
-
-void primitive_set_vector_nth(void)
-{
-       F_VECTOR* vector;
-       F_FIXNUM index;
-       CELL value;
-
-       maybe_garbage_collection();
-
-       vector = untag_vector(dpop());
-       index = to_fixnum(dpop());
-       value = dpop();
-
-       if(index < 0)
-               range_error(tag_object(vector),0,tag_fixnum(index),vector->top);
-       else if(index >= vector->top)
-               vector_ensure_capacity(vector,index);
-
-       /* the following does not check bounds! */
-       set_array_nth(untag_array(vector->array),index,value);
-}
-
 void fixup_vector(F_VECTOR* vector)
 {
        data_fixup(&vector->array);
index a851779c16d213851c3e05cca5409eec3562bdc8..cffc5a7ff404906aad37671acd5849c13dfbb758 100644 (file)
@@ -17,8 +17,5 @@ F_VECTOR* vector(F_FIXNUM capacity);
 
 void primitive_vector(void);
 void primitive_to_vector(void);
-void primitive_vector_nth(void);
-void vector_ensure_capacity(F_VECTOR* vector, CELL index);
-void primitive_set_vector_nth(void);
 void fixup_vector(F_VECTOR* vector);
 void collect_vector(F_VECTOR* vector);