]> gitweb.factorcode.org Git - factor.git/commitdiff
Assorted fixes: sort out bignum division by zero, fix some unit tests
authorslava <slava@factorcode.org>
Thu, 14 Dec 2006 07:35:22 +0000 (07:35 +0000)
committerslava <slava@factorcode.org>
Thu, 14 Dec 2006 07:35:22 +0000 (07:35 +0000)
15 files changed:
TODO.txt
core/debugger.facts
core/errors.factor
core/handbook/handbook.facts
core/math/integer.factor
core/math/integer.facts
core/test/collections/hashtables.factor
core/test/kernel.factor
core/test/parser.factor
core/tools/errors.factor
core/tools/word-tools.factor
core/ui/tools/search.factor
vm/bignum.c
vm/run.c
vm/run.h

index 4c1135462be74f2d7e65bf4da561211e35c35f39..78b1e0d41cdbb22ecad9815c6792cd3bd51dde2f 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -3,7 +3,8 @@
 - callback scheduling issue
 - error popup obscures input area
 - ui docs
-- vocab popup: sort
+- test factor on linux/ppc
+- auto-generate error-index
 
 + 0.88:
 
index 66e0323dfe9ab960dbda5da28ce266a3bfb5f82d..555b8d9950df6231024125ffd28b69633c3ca62e 100644 (file)
@@ -37,24 +37,23 @@ HELP: try
 { $description "Calls the quotation. If it throws an error, logs the error to the default stream and restores the data stack." } ;
 
 HELP: expired-error.
-{ $values { "obj" "an error" } }
 { $error-description "Thrown by " { $link alien-address } " and " { $link alien-invoke } " if an " { $link alien } " object passed in as a parameter has expired. Alien objects expire if they are saved an image which is subsequently loaded; this prevents a certain class of programming errors, usually attempts to use uninitialized objects, since holding a C address is meaningless between sessions." }
 { $notes "You can check if an alien object has expired by calling " { $link expired? } "." } ;
 
 HELP: io-error.
-{ $values { "error" "an object" } }
 { $error-description "Thrown by the C streams I/O primitives if an I/O error occurs." } ;
 
 HELP: undefined-word-error.
-{ $values { "obj" "an object" } }
 { $error-description "Thrown if an attempt is made to call a word which was defined by " { $link POSTPONE: DEFER: } "." } ;
 
 HELP: type-check-error.
-{ $values { "obj" "an object" } }
 { $error-description "Thrown by various primitives if one of the inputs does not have the expected type. Generic words throw " { $link no-method } " and " { $link no-math-method } " errors in such cases instead." } ;
 
+HELP: divide-by-zero-error.
+{ $error-description "This error is thrown when " { $link / } " or " { $link /i } " is called with with a zero denominator." }
+{ $see-also "division-by-zero" } ;
+
 HELP: signal-error.
-{ $values { "obj" "an object" } }
 { $error-description
     "Thrown by the runtime when a Unix signal is received. While signal numbers are system-specific, the following are relatively standard:"
     { $list
@@ -66,27 +65,21 @@ HELP: signal-error.
 } ;
 
 HELP: negative-array-size-error.
-{ $values { "obj" "an object" } }
 { $error-description "Thrown by " { $link <array> } ", " { $link <string> } ", " { $link <vector> } " and " { $link <sbuf> } " if a negative capacity is specified." } ;
 
 HELP: c-string-error.
-{ $values { "obj" "an object" } }
 { $error-description "Thrown by " { $link alien-invoke } " and various primitives if a string containing null bytes, or characters with values higher than 255 is passed in where a C string is expected. See " { $link "c-strings" } "." } ;
 
 HELP: ffi-error.
-{ $values { "obj" "an object" } }
 { $error-description "Thrown by " { $link dlopen } " and " { $link dlsym } " if a problem occurs while loading a native library or looking up a symbol. See " { $link "alien" } "." } ;
 
 HELP: heap-scan-error.
-{ $values { "obj" "an object" } }
 { $error-description "Thrown if " { $link next-object } " is called outside of a " { $link begin-scan } "/" { $link end-scan } " pair." } ;
 
 HELP: undefined-symbol-error.
-{ $values { "obj" "an object" } }
 { $error-description "Thrown if a previously-compiled " { $link alien-invoke } " call refers to a native library symbol which no longer exists." } ;
 
 HELP: user-interrupt.
-{ $values { "obj" "an object" } }
 { $error-description "Thrown by the " { $snippet "t" } " command in the FEP." } ;
 
 HELP: datastack-underflow.
index 5f11ff2c6a8f3295f27d3516081ca11920b23dd6..b6af228a58d2ce37cb2d83891a4d9d4a6af99bf5 100644 (file)
@@ -59,7 +59,7 @@ M: condition compute-restarts
 
 PREDICATE: array kernel-error ( obj -- ? )
     dup first \ kernel-error eq? [
-        second 0 18 between?
+        second 0 19 between?
     ] [
         drop f
     ] if ;
index 2a95169e5b3da621af5614aee6956d85f6efbaa7..1e54c843078ca530e5389c33225f743bf6b3eff3 100644 (file)
@@ -66,7 +66,6 @@ ARTICLE: "primitive-index" "Primitive index"
 { $outliner [ all-words [ primitive? ] subset ] } ;
 
 ARTICLE: "error-index" "Error index"
-{ $subsection /0                         }
 { $subsection alien-callback-error       }
 { $subsection alien-invoke-error         }
 { $subsection assert                     }
@@ -84,6 +83,7 @@ ARTICLE: "error-index" "Error index"
 { $subsection condition                  }
 { $subsection datastack-overflow.        }
 { $subsection datastack-underflow.       }
+{ $subsection divide-by-zero-error.      }
 { $subsection empty-queue                }
 { $subsection expired-error.             }
 { $subsection ffi-error.                 }
index 637b6e45398c808d634b90f1379b13b47287bf12..fb2a7a137858a481d7a30bebfc97c1f789271e97 100644 (file)
@@ -42,12 +42,9 @@ IN: math-internals
 : fraction> ( a b -- a/b )
     dup 1 number= [ drop ] [ (fraction>) ] if ; inline
 
-TUPLE: /0 ;
-: /0 ( -- * ) </0> throw ;
-
 M: integer /
     dup zero? [
-        /0
+        /i
     ] [
         dup 0 < [ [ neg ] 2apply ] when
         2dup gcd nip tuck /i >r /i r> fraction>
index 78503adaa753e90feaf47a7684ca1a5ef7f8f1b5..9ebebc571e1b25f10a3b8c574ba6df2002d7d357 100644 (file)
@@ -212,7 +212,3 @@ HELP: bignum-shift ( x y -- z )
 { $values { "x" "a bignum" } { "y" "a bignum" } { "z" "a bignum" } }
 { $description "Primitive version of " { $link shift } "." }
 { $warning "This word does not perform type checking, and passing objects of the wrong type can crash the runtime. User code should call the generic word " { $link shift } " instead." } ;
-
-HELP: /0
-{ $error-description "This error is thrown when " { $link / } " is called with two integer inputs, the denominator being zero." }
-{ $notes "Floating point division by zero does not raise an error at all, whereas integer division by zero in " { $link /i } " typically raises an operating system signal (see " { $link signal-error. } ")." } ;
index b1816c051a3a6d6b3d065ae5d05ac5438689805d..6e2df4ee4fda49f78945a88351733e1f6f906125 100644 (file)
@@ -9,6 +9,7 @@ USE: sequences-internals
 USE: hashtables
 USE: io
 USE: prettyprint
+USE: errors
 
 [ "hi" V{ 1 2 3 } hash ] unit-test-fails
 
index efb36b0409a8aa572667dc53828839174fdd2007..b6cb453eb8b52b4cab99d0aca59749f59bb9f54a 100644 (file)
@@ -25,7 +25,7 @@ sequences test errors math-internals ;
 [ [ \ + = ] ] [ \ + [ = ] curry ] unit-test
 
 ! Make sure we report the correct error on stack underflow
-[ { kernel-error 11 f f } ]
+[ { kernel-error 12 f f } ]
 [ [ clear drop ] catch ] unit-test
 
 [ -7 <byte-array> ] unit-test-fails
index 9df93fb55d18c2f50186eac40b8e1cf8de75739f..2f96bae8dcde9b9b8e208fd23ca056abff7acefe 100644 (file)
@@ -96,7 +96,7 @@ unit-test
             "cont" set
             [
                 "\ + 1 2 3 4" 
-                <string-reader> <interactive-stream>
+                <string-reader>
                 parse-interactive "cont" get continue-with
             ] catch
             "0 :res" eval
index 120f819dcd964eba73dc551a75d0db73af43d1a2..aee7baec814601291f6c6d0e20219012c190308c 100644 (file)
@@ -20,6 +20,9 @@ words definitions ;
     "Object type: " write dup fourth class .
     "Expected type: " write third type>class . ;
 
+: divide-by-zero-error. ( obj -- )
+    "Division by zero" print drop ;
+
 : signal-error. ( obj -- )
     "Operating system signal " write third . ;
 
@@ -70,6 +73,7 @@ DEFER: objc-error. ( alien -- )
         io-error.
         undefined-word-error.
         type-check-error.
+        divide-by-zero-error.
         signal-error.
         negative-array-size-error.
         c-string-error.
@@ -106,9 +110,6 @@ M: no-method error.
 M: no-math-method summary
     drop "No suitable arithmetic method" ;
 
-M: /0 summary
-    drop "Division by zero" ;
-
 M: bad-escape summary
     drop "Invalid escape code" ;
 
index 6c756bc9f98abded16a4f7e5a0a7003432db1843..4df47eaa3e9d38c68709cdad4b4240da0334cab2 100644 (file)
@@ -51,4 +51,4 @@ generic completion ;
     [ word-name ] swap completions ;
 
 : apropos ( str -- )
-    all-words word-completions [ summary ] each ;
+    all-words word-completions [ summary print ] each ;
index 9fea970028e9069fbcdb8401038bd2e54a3cb32d..d84f7bef2fda3e0dd7965d241149cfd06a2c76a4 100644 (file)
@@ -119,7 +119,7 @@ M: live-search focusable-child* live-search-field ;
     "Word search" show-titled-popup ;
 
 : show-vocab-words ( workspace vocab -- )
-    "" over words <word-search>
+    "" over words natural-sort <word-search>
     "Words in " rot append show-titled-popup ;
 
 : show-help-search ( workspace -- )
index 26589d69274ff28b3567d12711d8435c98f65f9a..6f3329a86eaea3dc61e26910cf192abcaabd4760 100644 (file)
@@ -169,7 +169,7 @@ s48_bignum_divide(bignum_type numerator, bignum_type denominator,
 {
   if (BIGNUM_ZERO_P (denominator))
     {
-      raise(SIGFPE);
+      divide_by_zero_error();
       return;
     }
   if (BIGNUM_ZERO_P (numerator))
@@ -241,7 +241,7 @@ s48_bignum_quotient(bignum_type numerator, bignum_type denominator)
 {
   if (BIGNUM_ZERO_P (denominator))
     {
-      raise(SIGFPE);
+      divide_by_zero_error();
       return (BIGNUM_OUT_OF_BAND);
     }
   if (BIGNUM_ZERO_P (numerator))
@@ -294,7 +294,7 @@ s48_bignum_remainder(bignum_type numerator, bignum_type denominator)
 {
   if (BIGNUM_ZERO_P (denominator))
     {
-      raise(SIGFPE);
+      divide_by_zero_error();
       return (BIGNUM_OUT_OF_BAND);
     }
   if (BIGNUM_ZERO_P (numerator))
index 6b47d8629311b78343af6c21e3376b60f2bda453..ca3b476dc9fdb6aebdb553ffb67e866a86a26aa4 100644 (file)
--- a/vm/run.c
+++ b/vm/run.c
@@ -350,7 +350,12 @@ void type_error(CELL type, CELL tagged)
        general_error(ERROR_TYPE,tag_fixnum(type),tagged,true);
 }
 
+void divide_by_zero_error(void)
+{
+       general_error(ERROR_DIVIDE_BY_ZERO,F,F,true);
+}
+
 void memory_error(void)
 {
-       general_error(ERROR_MEMORY,F,F,false);
+       general_error(ERROR_MEMORY,F,F,true);
 }
index dda8f44f2e3b3df1942354a02091eaabe8f33190..033c6389afb1a879bb12c2251ca371cbf892fcfd 100644 (file)
--- a/vm/run.h
+++ b/vm/run.h
@@ -155,6 +155,7 @@ typedef enum
        ERROR_IO,
        ERROR_UNDEFINED_WORD,
        ERROR_TYPE,
+       ERROR_DIVIDE_BY_ZERO,
        ERROR_SIGNAL,
        ERROR_NEGATIVE_ARRAY_SIZE,
        ERROR_C_STRING,
@@ -193,6 +194,7 @@ void general_error(F_ERRORTYPE error, CELL arg1, CELL arg2, bool keep_stacks);
 void memory_protection_error(CELL addr, int signal);
 void signal_error(int signal);
 void type_error(CELL type, CELL tagged);
+void divide_by_zero_error(void);
 void memory_error(void);
 void primitive_throw(void);
 void primitive_die(void);