]> gitweb.factorcode.org Git - factor.git/commitdiff
started type inference, and some bug fixes
authorSlava Pestov <slava@factorcode.org>
Thu, 23 Dec 2004 03:16:46 +0000 (03:16 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 23 Dec 2004 03:16:46 +0000 (03:16 +0000)
23 files changed:
TODO.FACTOR.txt
factor/jedit/FactorShell.java
factor/jedit/FactorSideKickParser.java
factor/parser/BeginMethod.java
library/generic/builtin.factor
library/inference/branches.factor
library/inference/inference.factor
library/inference/words.factor
library/io/stream.factor
library/test/errors.factor
library/test/io/io.factor
library/tools/debugger.factor
library/vectors.factor
native/bignum.c
native/bignum.h
native/compiler.c
native/error.c
native/error.h
native/run.c
native/sbuf.c
native/string.c
native/unix/read.c
native/vector.c

index dc8105334799c772b2ad9608a6c5f9076e2085b0..1b3f3ad8c465d5207626c83bb7b8c396c89df23d 100644 (file)
@@ -54,6 +54,7 @@
 \r
 + misc:\r
 \r
+- stream server can hang because of exception handler limitations\r
 - each-with map-with\r
 - step: print NEXT word to execute, not word that JUST executed\r
 - perhaps /i should work with all numbers\r
index 31d5bd345bb5e99ee01b575791754bd30574701f..760ff0aa26fb57961d66f6632ec11223da720883 100644 (file)
@@ -247,11 +247,16 @@ public class FactorShell extends Shell
                        Cons pair = FactorPlugin.getExternalInstance()
                                .parseObject(w.getText());
 
-                       String write = (String)pair.car;
-                       AttributeSet attrs = new ListenerAttributeSet(
-                               (Cons)pair.next().car);
-
-                       output.writeAttrs(attrs,write);
+                       if(pair.car instanceof String)
+                       {
+                               String write = (String)pair.car;
+                               AttributeSet attrs = new ListenerAttributeSet(
+                                       (Cons)pair.next().car);
+       
+                               output.writeAttrs(attrs,write);
+                       }
+                       else
+                               Log.log(Log.ERROR,this,"Malformed write packet: " + pair);
                }
                
                void packetLoop(Output output) throws Exception
index 997e993e4aaa53bb22af5d6c1f9f5b0af7791282..a2464d2ec90ec363dd8192a7d257a5d62f771f12 100644 (file)
@@ -184,9 +184,9 @@ public class FactorSideKickParser extends SideKickParser
                                FactorWord word = def.word;
 
                                /* word lines are indexed from 1 */
-                               int startLine = Math.min(
+                               int startLine = Math.max(0,Math.min(
                                        buffer.getLineCount() - 1,
-                                       word.line - 1);
+                                       word.line - 1));
                                int startLineLength = buffer.getLineLength(startLine);
                                int startCol = Math.min(word.col,startLineLength);
 
@@ -194,7 +194,7 @@ public class FactorSideKickParser extends SideKickParser
                                        + startCol;
 
                                if(last != null)
-                                       last.end = buffer.createPosition(start - 1);
+                                       last.end = buffer.createPosition(Math.max(0,start - 1));
 
                                last = new FactorAsset(word,buffer.createPosition(start));
                                d.root.add(new DefaultMutableTreeNode(last));
index 24a54aeab7bf73a77c6b97d0d660419153029465..969101b8d31aa447c136a678b3b7c071344e78e3 100644 (file)
@@ -48,7 +48,7 @@ public class BeginMethod extends FactorParsingDefinition
                if(type == null)
                        return;
 
-               FactorWord generic = reader.nextWord(true);
+               FactorWord generic = reader.nextWord(false);
                if(generic == null)
                        return;
 
index 2624b4ace32f9717d20cb71937d9879ff55e660a..d6452cd7ca01b84cb8aa60d86615f0b0e05c555b 100644 (file)
@@ -79,4 +79,9 @@ builtin 50 "priority" set-word-property
 : type-name ( n -- string )
     builtin-type word-name ;
 
+: class ( obj -- class )
+    #! Analogous to the type primitive. Pushes the builtin
+    #! class of an object.
+    type builtin-type ;
+
 global [ num-types <vector> types set ] bind
index 8d833c0cebee83cc558790a3647e8705bef6413b..02e818ab51fd52b665a40007376d1cb73d08bad9 100644 (file)
@@ -38,33 +38,48 @@ USE: vectors
 USE: words
 USE: hashtables
 
-: unify-d-in ( list -- d-in )
-    0 swap [ [ d-in get ] bind [ max ] when* ] each ;
-
-: balanced? ( list -- ? )
-    [ [ d-in get meta-d get and ] bind ] subset
-    [ [ d-in get meta-d get vector-length - ] bind ] map all=? ;
-
 : longest-vector ( list -- length )
     [ vector-length ] map [ > ] top ;
 
-: unify-result ( obj obj -- obj )
+: unify-lengths ( list -- list )
+    #! Pad all vectors to the same length. If one vector is
+    #! shorter, pad it with unknown results at the bottom.
+    dup longest-vector swap [ dupd ensure nip ] map nip ;
+
+: unify-classes ( class class -- class )
+    #! Return a class that both classes are subclasses of.
+    2dup = [ drop ] [ 2drop object ] ifte ;
+
+: unify-results ( obj obj -- obj )
     #! Replace values with unknown result if they differ,
     #! otherwise retain them.
-    2dup = [ drop ] [ 2drop <computed-value> ] ifte ;
+    2dup = [
+        drop
+    ] [
+        value-class swap value-class unify-classes <computed>
+    ] ifte ;
 
 : unify-stacks ( list -- stack )
     #! Replace differing literals in stacks with unknown
     #! results.
-    uncons [ [ unify-result ] vector-2map ] each ;
+    uncons [ [ unify-results ] vector-2map ] each ;
 
-: unify-lengths ( list -- list )
-    #! Pad all vectors to the same length. If one vector is
-    #! shorter, pad it with unknown results at the bottom.
-    dup longest-vector swap [ dupd ensure nip ] map nip ;
+: unify-d-in ( list -- d-in )
+    [ [ d-in get ] bind ] map unify-lengths unify-stacks ;
+
+: filter-terminators ( list -- list )
+    [ [ d-in get meta-d get and ] bind ] subset ;
+
+: balanced? ( list -- ? )
+    [
+        [
+            d-in get vector-length
+            meta-d get vector-length -
+        ] bind
+    ] map all=? ;
 
 : unify-datastacks ( list -- datastack )
-    [ [ meta-d get ] bind ] map [ ] subset
+    [ [ meta-d get ] bind ] map
     unify-lengths unify-stacks ;
 
 : check-lengths ( list -- )
@@ -73,11 +88,11 @@ USE: hashtables
     ] unless ;
 
 : unify-callstacks ( list -- datastack )
-    [ [ meta-r get ] bind ] map [ ] subset
+    [ [ meta-r get ] bind ] map
     dup check-lengths unify-stacks ;
 
 : unify ( list -- )
-    dup balanced? [
+    filter-terminators dup balanced? [
         dup unify-d-in d-in set
         dup unify-datastacks meta-d set
         unify-callstacks meta-r set
@@ -90,8 +105,9 @@ USE: hashtables
         save-effect set
         dup value-recursion recursive-state set
         copy-interpreter
+        d-in [ vector-clone ] change
         dataflow-graph off
-        literal infer-quot
+        literal-value infer-quot
         #values values-node
     ] extend ;
 
@@ -99,14 +115,13 @@ USE: hashtables
     #! This is a hack. undefined-method has a stack effect that
     #! probably does not match any other branch of the generic,
     #! so we handle it specially.
-    literal \ undefined-method swap tree-contains? ;
+    literal-value \ undefined-method swap tree-contains? ;
 
 : recursive-branch ( value -- )
     #! Set base case if inference didn't fail.
     [
         f infer-branch [
-            d-in get meta-d get vector-length cons
-            recursive-state get set-base
+            effect recursive-state get set-base
         ] bind
     ] [
         [ drop ] when
@@ -154,8 +169,8 @@ USE: hashtables
 \ ifte [ infer-ifte ] "infer" set-word-property
 
 : vtable>list ( value -- list )
-    dup value-recursion swap literal vector>list
-    [ over <literal-value> ] map nip ;
+    dup value-recursion swap literal-value vector>list
+    [ over <literal> ] map nip ;
 
 : infer-dispatch ( -- )
     #! Infer effects for all branches, unify.
index ace10181e8de9748d6bd3d97fdd1d368110a0eaa..ad3353da8370d55991332d593114b41b3ee9ea4a 100644 (file)
@@ -65,36 +65,38 @@ SYMBOL: save-effect
 
 ! A value has the following slots:
 
-! the literal object, if any.
-SYMBOL: value
-
-! value-type -- the type, if known.
-SYMBOL: value-type
-
-GENERIC: literal ( value -- obj )
+GENERIC: literal-value ( value -- obj )
 GENERIC: value= ( literal value -- ? )
+GENERIC: value-class ( value -- class )
 
-TRAITS: computed-value
-C: computed-value ( -- value )
-    [ gensym value set ] extend ;
-M: computed-value literal ( value -- obj )
+TRAITS: computed
+C: computed ( class -- value )
+    [
+        \ value-class set
+        gensym \ literal-value set
+    ] extend ;
+M: computed literal-value ( value -- obj )
     "Cannot use a computed value literally." throw ;
-M: computed-value value= ( literal value -- ? )
+M: computed value= ( literal value -- ? )
     2drop f ;
-
-TRAITS: literal-value
-C: literal-value ( obj rstate -- value )
-    [ recursive-state set value set ] extend ;
-M: literal-value literal ( value -- obj )
-    [ value get ] bind ;
-M: literal-value value= ( literal value -- ? )
-    literal = ;
+M: computed value-class ( value -- class )
+    [ \ value-class get ] bind ;
+
+TRAITS: literal
+C: literal ( obj rstate -- value )
+    [ recursive-state set \ literal-value set ] extend ;
+M: literal literal-value ( value -- obj )
+    [ \ literal-value get ] bind ;
+M: literal value= ( literal value -- ? )
+    literal-value = ;
+M: literal value-class ( value -- class )
+    literal-value class ;
 
 : value-recursion ( value -- rstate )
     [ recursive-state get ] bind ;
 
-: computed-value-vector ( n --  vector )
-    [ drop <computed-value> ] vector-project ;
+: computed-value-vector ( n -- vector )
+    [ drop object <computed> ] vector-project ;
 
 : add-inputs ( count stack -- stack )
     #! Add this many inputs to the given stack.
@@ -111,19 +113,13 @@ M: literal-value value= ( literal value -- ? )
 
 : ensure-d ( count -- )
     #! Ensure count of unknown results are on the stack.
-    meta-d [ ensure ] change d-in [ + ] change ;
-
-: consume-d ( count -- )
-    #! Remove count of elements.
-    [ pop-d drop ] times ;
-
-: produce-d ( count -- )
-    #! Push count of unknown results.
-    [ <computed-value> push-d ] times ;
+    meta-d [ ensure ] change
+    d-in get swap [ object <computed> over vector-push ] times
+    drop ;
 
 : effect ( -- [ in | out ] )
     #! After inference is finished, collect information.
-    d-in get  meta-d get vector-length cons ;
+    d-in get vector-length meta-d get vector-length cons ;
 
 : <recursive-state> ( -- state )
     <namespace> [
@@ -132,7 +128,7 @@ M: literal-value value= ( literal value -- ? )
 
 : init-inference ( recursive-state -- )
     init-interpreter
-    0 d-in set
+    0 <vector> d-in set
     recursive-state set
     dataflow-graph off
     save-effect on ;
@@ -142,7 +138,7 @@ DEFER: apply-word
 : apply-literal ( obj -- )
     #! Literals are annotated with the current recursive
     #! state.
-    dup recursive-state get <literal-value> push-d
+    dup recursive-state get <literal> push-d
     #push dataflow, [ 1 0 node-outputs ] bind ;
 
 : apply-object ( obj -- )
@@ -206,3 +202,10 @@ DEFER: apply-word
 : dataflow ( quot -- dataflow )
     #! Data flow of a quotation.
     [ (infer) get-dataflow ] with-scope ;
+
+: type-infer ( quot -- [ in-types out-types ] )
+    [
+        (infer)
+        d-in get [ value-class ] vector-map
+        meta-d get [ value-class ] vector-map 2list
+    ] with-scope ;
index da0db56d1d8bf71a8ef8d267dff2c6586aa50199..4064b251d1150c85f068fbdada2186efafd8374e 100644 (file)
@@ -27,6 +27,7 @@
 
 IN: inference
 USE: errors
+USE: generic
 USE: interpreter
 USE: kernel
 USE: lists
@@ -46,8 +47,24 @@ USE: prettyprint
     [ pick swap dataflow-inputs ] keep
     pick 2slip swap dataflow-outputs ; inline
 
+: consume-d ( count -- )
+    #! Remove count of elements.
+    [ pop-d drop ] times ;
+
+: produce-d ( count -- )
+    #! Push count of unknown results.
+    [ object <computed> push-d ] times ;
+
 : (consume/produce) ( param op effect -- )
-    [ unswons consume-d produce-d ] with-dataflow ;
+    [
+        dup cdr cons? [
+            ( new style )
+            
+        ] [
+            ( old style, will go away shortly )
+            unswons consume-d produce-d
+        ] ifte
+    ] with-dataflow ;
 
 : consume/produce ( word [ in | out ] -- )
     #! Add a node to the dataflow graph that consumes and
@@ -138,7 +155,8 @@ USE: prettyprint
     #! If at the location of the recursive call, we're taking
     #! more items from the stack than producing, we have a
     #! diverging recursion.
-    d-in get meta-d get vector-length > [
+    d-in get vector-length
+    meta-d get vector-length > [
         current-word word-name " diverges." cat2 throw
     ] when ;
 
@@ -184,7 +202,7 @@ USE: prettyprint
     gensym dup [
         drop pop-d dup
         value-recursion recursive-state set
-        literal infer-quot
+        literal-value infer-quot
     ] with-block ;
 
 \ call [ infer-call ] "infer" set-word-property
index 15b5b69a5222c43c9c3a2fa3f45c57d0de8845d1..6e89459f19041a94b72fc690771b0ba43e34f6c1 100644 (file)
@@ -39,8 +39,9 @@ GENERIC: fread#      ( count stream -- string )
 GENERIC: fwrite-attr ( string style stream -- )
 GENERIC: fclose      ( stream -- )
 
-: fread1 ( stream -- string )
-    1 swap fread# dup f-or-"" [ 0 swap str-nth ] unless ;
+: fread1 ( stream -- char/f )
+    1 swap fread#
+    dup f-or-"" [ drop f ] [ 0 swap str-nth ] ifte ;
 
 : fwrite ( string stream -- )
     f swap fwrite-attr ;
index e36ebaa11d458a352489d6800ee2efb35b48458c..db0be3163413e4e5aea1b460db0f8068a85feb12 100644 (file)
@@ -24,3 +24,7 @@ USE: stdio
 "!!! The following error is part of the test" print
 
 [ [ "2 car" ] parse ] [ default-error-handler ] catch
+
+[ [ "\"\" { } vector-nth" ] parse ] [ type-check-error ] catch
+
+[ "cons" ] [ [ 1 2 ] type type-error-name ] unit-test
index b3bb2fe0ca2af8624e5e1e458e919b278b886aa7..0d02dba5b3a31c154d2d85bf750e1fdd689ab69d 100644 (file)
@@ -41,3 +41,5 @@ USE: math
 
 ! Make sure we use correct to_c_string form when writing
 [ ] [ "\0" write ] unit-test
+
+[ -1 read# ] unit-test-fails
index 2b8bbba607a792e4291d377e81d68b188bf419c1..441e753efeae2f242c5e4edb49d269c381a78bbf 100644 (file)
@@ -61,13 +61,17 @@ USE: generic
 : type-error-name ( n -- string )
     #! These values are only used by the kernel for error
     #! reporting.
-    [
+    dup [
         [ 100 | "fixnum/bignum" ]
         [ 101 | "fixnum/bignum/ratio" ]
         [ 102 | "fixnum/bignum/ratio/float" ]
         [ 103 | "fixnum/bignum/ratio/float/complex" ]
         [ 104 | "fixnum/string" ]
-    ] assoc [ type-name ] unless* ;
+    ] assoc dup [
+        nip
+    ] [
+        drop type-name
+    ] ifte ;
 
 : type-check-error ( list -- )
     "Type check error" print
@@ -75,11 +79,12 @@ USE: generic
     "Object type: " write type type-error-name print
     "Expected type: " write type-error-name print ;
 
-: array-range-error ( list -- )
-    "Array range check error" print
-    unswons "Object: " write .
-    uncons car "Maximum index: " write .
-    "Requested index: " write . ;
+: range-error ( list -- )
+    "Range check error" print
+    unswons [ "Object: " write . ] when*
+    unswons "Minimum index: " write .
+    unswons "Requested index: " write .
+    car "Maximum index: " write . ;
 
 : float-format-error ( list -- )
     "Invalid floating point literal format: " write . ;
@@ -111,7 +116,7 @@ USE: generic
         io-error
         undefined-word-error
         type-check-error
-        array-range-error
+        range-error
         float-format-error
         signal-error
         negative-array-size-error
index cac9cb666d16417f0ab342830b2e0b6ce6b7d226..ef43e04af3eaac0066eff424225f3f240bcb0b1a 100644 (file)
 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-IN: vectors
+IN: kernel-internals
 USE: generic
+
+BUILTIN: array 8
+
+IN: vectors
 USE: kernel
 USE: lists
 USE: math
 
-BUILTIN: vector  11
+BUILTIN: vector 11
 
 : empty-vector ( len -- vec )
     #! Creates a vector with 'len' elements set to f. Unlike
index f40988497e32db7af219bfccbd7212c813ad3b6a..d64717f2b77cd90f09af7dd6ac9253fd653de91a 100644 (file)
@@ -32,10 +32,41 @@ F_FIXNUM unbox_integer(void)
        return to_integer(dpop());
 }
 
+CELL to_cell(CELL x)
+{
+       F_FIXNUM fixnum;
+       F_ARRAY* bignum;
+
+       switch(type_of(x))
+       {
+       case FIXNUM_TYPE:
+               fixnum = untag_fixnum_fast(x);
+               if(fixnum < 0)
+               {
+                       range_error(F,0,tag_fixnum(fixnum),FIXNUM_MAX);
+                       return -1;
+               }
+               else
+                       return (CELL)fixnum;
+               break;
+       case BIGNUM_TYPE:
+               bignum = to_bignum(dpop());
+               if(BIGNUM_NEGATIVE_P(bignum))
+               {
+                       range_error(F,0,tag_object(bignum),FIXNUM_MAX);
+                       return -1;
+               }
+               else
+                       return s48_bignum_to_long(untag_bignum(x));
+       default:
+               type_error(INTEGER_TYPE,x);
+               return 0;
+       }
+}
 /* FFI calls this */
 CELL unbox_cell(void)
 {
-       return to_integer(dpop());
+       return to_cell(dpop());
 }
 
 F_ARRAY* to_bignum(CELL tagged)
index b884fec7ccb2ac6ff3575d60e2a21e06fe716dcc..4b865ee17a53fd5587dc7736f23a4aae16864a9b 100644 (file)
@@ -14,9 +14,12 @@ INLINE F_ARRAY* untag_bignum(CELL tagged)
 }
 
 F_FIXNUM to_integer(CELL x);
+CELL to_cell(CELL x);
+
 DLLEXPORT void box_integer(F_FIXNUM integer);
 DLLEXPORT void box_cell(CELL cell);
 DLLEXPORT F_FIXNUM unbox_integer(void);
+CELL to_cell(CELL x);
 DLLEXPORT CELL unbox_cell(void);
 F_ARRAY* to_bignum(CELL tagged);
 void primitive_to_bignum(void);
index d6da2b1f394d415d3f34775feb7fb609e414a021..36193c1842bdd206f2c1a52817d6dfc907e98239 100644 (file)
@@ -9,7 +9,7 @@ void init_compiler(void)
 void check_compiled_offset(CELL offset)
 {
        if(offset < compiling.base || offset >= compiling.limit)
-               range_error(F,offset,compiling.limit);
+               range_error(F,0,to_integer(offset),compiling.limit);
 }
 
 void primitive_set_compiled_byte(void)
index acc551e5c23860e8f236191ead73d225548ec7c6..17de1d22b14ae832fb1f159da258a53bf95baee7 100644 (file)
@@ -74,8 +74,10 @@ void type_error(CELL type, CELL tagged)
        general_error(ERROR_TYPE,c);
 }
 
-void range_error(CELL tagged, F_FIXNUM index, CELL max)
+/* index must be tagged */
+void range_error(CELL tagged, CELL min, CELL index, CELL max)
 {
-       CELL c = cons(tagged,cons(tag_integer(index),cons(tag_cell(max),F)));
+       CELL c = cons(tagged,cons(tag_cell(min),
+               cons(index,cons(tag_cell(max),F))));
        general_error(ERROR_RANGE,c);
 }
index 8b65edfd433a08f0045145b5e6e6bc110fa18a57..033d7a275a3caaf71e90210de4437601f8dc3b56 100644 (file)
@@ -30,4 +30,5 @@ void general_error(CELL error, CELL tagged);
 void signal_error(int signal);
 void type_error(CELL type, CELL tagged);
 void primitive_throw(void);
-void range_error(CELL tagged, F_FIXNUM index, CELL max);
+/* index must be tagged */
+void range_error(CELL tagged, CELL min, CELL index, CELL max);
index 5ba92e88fd19c323ed3510fdf4375afbc399a3e7..b61bc920f0600eb6dce533c33b332fcc121838e0 100644 (file)
@@ -112,7 +112,7 @@ void primitive_getenv(void)
 {
        F_FIXNUM e = to_fixnum(dpeek());
        if(e < 0 || e >= USER_ENV)
-               range_error(F,e,USER_ENV);
+               range_error(F,0,tag_fixnum(e),USER_ENV);
        drepl(userenv[e]);
 }
 
@@ -121,6 +121,6 @@ void primitive_setenv(void)
        F_FIXNUM e = to_fixnum(dpop());
        CELL value = dpop();
        if(e < 0 || e >= USER_ENV)
-               range_error(F,e,USER_ENV);
+               range_error(F,0,tag_fixnum(e),USER_ENV);
        userenv[e] = value;
 }
index de8b3a54082d70f88b348168217069b5161cd06d..121c6568efaa5df87b547486be03de19868fab50 100644 (file)
@@ -31,7 +31,7 @@ void primitive_set_sbuf_length(void)
        str = untag_string(sbuf->string);
        length = to_fixnum(dpop());
        if(length < 0)
-               range_error(tag_object(sbuf),length,sbuf->top);
+               range_error(tag_object(sbuf),0,to_fixnum(length),sbuf->top);
        sbuf->top = length;
        if(length > str->capacity)
                sbuf->string = tag_object(grow_string(str,length,F));
@@ -43,7 +43,7 @@ void primitive_sbuf_nth(void)
        CELL index = to_fixnum(dpop());
 
        if(index < 0 || index >= sbuf->top)
-               range_error(tag_object(sbuf),index,sbuf->top);
+               range_error(tag_object(sbuf),0,to_fixnum(index),sbuf->top);
        dpush(string_nth(untag_string(sbuf->string),index));
 }
 
@@ -59,7 +59,7 @@ void sbuf_ensure_capacity(F_SBUF* sbuf, F_FIXNUM top)
 void set_sbuf_nth(F_SBUF* sbuf, CELL index, uint16_t value)
 {
        if(index < 0)
-               range_error(tag_object(sbuf),index,sbuf->top);
+               range_error(tag_object(sbuf),0,to_fixnum(index),sbuf->top);
        else if(index >= sbuf->top)
                sbuf_ensure_capacity(sbuf,index + 1);
 
index 9504db93effcf621c3ea636eb2ff441d80de4a10..f3997960913091d6c4995f3bd98d1fe72b653681 100644 (file)
@@ -150,7 +150,7 @@ void primitive_string_nth(void)
        CELL index = to_fixnum(dpop());
 
        if(index < 0 || index >= string->capacity)
-               range_error(tag_object(string),index,string->capacity);
+               range_error(tag_object(string),0,to_fixnum(index),string->capacity);
        dpush(tag_fixnum(string_nth(string,index)));
 }
 
@@ -271,7 +271,7 @@ void primitive_index_of(void)
        index = to_fixnum(dpop());
        if(index < 0 || index > string->capacity)
        {
-               range_error(tag_object(string),index,string->capacity);
+               range_error(tag_object(string),0,to_fixnum(index),string->capacity);
                result = -1; /* can't happen */
        }
        else if(TAG(ch) == FIXNUM_TYPE)
@@ -286,10 +286,10 @@ INLINE F_STRING* substring(CELL start, CELL end, F_STRING* string)
        F_STRING* result;
 
        if(start < 0)
-               range_error(tag_object(string),start,string->capacity);
+               range_error(tag_object(string),0,to_fixnum(start),string->capacity);
 
        if(end < start || end > string->capacity)
-               range_error(tag_object(string),end,string->capacity);
+               range_error(tag_object(string),0,to_fixnum(end),string->capacity);
 
        result = allot_string(end - start);
        memcpy(result + 1,
index 1f22f949f26ef188e60c0d2e59e34e6d66f95142..8fa52339d965477b7b61c3718c8bdaf7ee7ac0d7 100644 (file)
@@ -207,12 +207,12 @@ bool can_read_count(F_PORT* port, F_FIXNUM count)
 void primitive_can_read_count(void)
 {
        F_PORT* port;
-       F_FIXNUM len;
+       CELL len;
 
        maybe_garbage_collection();
 
        port = untag_port(dpop());
-       len = to_fixnum(dpop());
+       len = to_cell(dpop());
        box_boolean(can_read_count(port,len));
 }
 
@@ -220,13 +220,13 @@ void primitive_add_read_count_io_task(void)
 {
        CELL callback;
        F_PORT* port;
-       F_FIXNUM count;
+       CELL count;
 
        maybe_garbage_collection();
 
        callback = dpop();
        port = untag_port(dpop());
-       count = to_fixnum(dpop());
+       count = to_cell(dpop());
        add_io_task(IO_TASK_READ_COUNT,
                tag_object(port),F,callback,
                read_io_tasks,&read_fd_count);
@@ -252,12 +252,12 @@ bool perform_read_count_io_task(F_PORT* port)
 void primitive_read_count_8(void)
 {
        F_PORT* port;
-       F_FIXNUM len;
+       CELL len;
 
        maybe_garbage_collection();
 
        port = untag_port(dpop());
-       len = to_fixnum(dpop());
+       len = to_cell(dpop());
        if(port->count != len)
                critical_error("read# counts don't match",tag_object(port));
 
index f796ed500f114968458bcbe1670b91d3406b83fa..edb4529a69975d9cb377a545b90ea10e9369c0d2 100644 (file)
@@ -32,7 +32,7 @@ void primitive_set_vector_length(void)
        array = untag_array(vector->array);
 
        if(length < 0)
-               range_error(tag_object(vector),length,vector->top);
+               range_error(tag_object(vector),0,to_fixnum(length),vector->top);
        vector->top = length;
        if(length > array->capacity)
                vector->array = tag_object(grow_array(array,length,F));
@@ -44,7 +44,7 @@ void primitive_vector_nth(void)
        CELL index = to_fixnum(dpop());
 
        if(index < 0 || index >= vector->top)
-               range_error(tag_object(vector),index,vector->top);
+               range_error(tag_object(vector),0,to_fixnum(index),vector->top);
        dpush(array_nth(untag_array(vector->array),index));
 }
 
@@ -71,7 +71,7 @@ void primitive_set_vector_nth(void)
        value = dpop();
 
        if(index < 0)
-               range_error(tag_object(vector),index,vector->top);
+               range_error(tag_object(vector),0,to_fixnum(index),vector->top);
        else if(index >= vector->top)
                vector_ensure_capacity(vector,index);