]> gitweb.factorcode.org Git - factor.git/commitdiff
kernel: symbolic constants for the various kernel errors
authorBjörn Lindqvist <bjourne@gmail.com>
Wed, 4 Jun 2014 14:51:26 +0000 (16:51 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Wed, 4 Jun 2014 21:16:40 +0000 (23:16 +0200)
basis/compiler/tests/linkage-errors.factor
basis/debugger/debugger.factor
basis/math/floats/env/env-tests.factor
core/kernel/kernel-tests.factor
core/kernel/kernel.factor
core/strings/strings-tests.factor
extra/decimals/decimals-tests.factor
vm/errors.hpp

index 98a07899f3f68360e31eca863cddb047bbedc61b..ca9b694644fd24c48f28c2ac11fd849206aa4a83 100644 (file)
@@ -10,7 +10,7 @@ FUNCTION: void this_does_not_exist ( ) ;
 [ this_does_not_exist ] try\r
 \r
 [ this_does_not_exist ] [\r
-    { "kernel-error" 9 $[ "this_does_not_exist" string>symbol ] f }\r
+    ${ "kernel-error" ERROR-UNDEFINED-SYMBOL "this_does_not_exist" string>symbol f }
     =\r
 ] must-fail-with\r
 \r
@@ -31,10 +31,10 @@ FUNCTION: void no_such_function ( ) ;
 [ no_such_function ] try\r
 \r
 [ no_such_function ] [\r
-    {\r
-        "kernel-error" 9\r
-        $[ "no_such_function" string>symbol ]\r
-        $[ "no_such_library" load-library ]\r
+    ${
+        "kernel-error" ERROR-UNDEFINED-SYMBOL
+        "no_such_function" string>symbol
+        "no_such_library" load-library
     }\r
     =\r
 ] must-fail-with\r
index debe579b9369e21a4211a2303f74d1c62f6d4436..8ff06fda294c36b46cde62c2f5385a93b5ec06c9 100755 (executable)
@@ -130,7 +130,7 @@ HOOK: signal-error. os ( obj -- )
 : memory-error. ( error -- )
     "Memory protection fault at address " write third .h ;
 
-: primitive-error. ( error -- ) 
+: primitive-error. ( error -- )
     "Unimplemented primitive" print drop ;
 
 : fp-trap-error. ( error -- )
@@ -143,7 +143,7 @@ PREDICATE: vm-error < array
     dup length 2 < [ drop f ] [
         {
             [ first-unsafe "kernel-error" = ]
-            [ second-unsafe 0 18 between? ]
+            [ second-unsafe 0 kernel-error-count 1 - between? ]
         } 1&&
     ] if ;
 
index df4e9e3d111ef4ea36d1bf94dd5af81cea127155..3de8c2bf0aaf943d51f8a4d1a0250899cfd8f3ea 100755 (executable)
@@ -1,5 +1,5 @@
 USING: kernel math math.floats.env math.floats.env.private
-math.functions math.libm sequences tools.test locals
+math.functions math.libm literals sequences tools.test locals
 compiler.units kernel.private fry compiler.test math.private
 words system memory ;
 IN: math.floats.env.tests
@@ -111,7 +111,7 @@ os linux? cpu x86.64? and [
 ] unit-test
 
 : fp-trap-error? ( error -- ? )
-    2 head { "kernel-error" 17 } = ;
+    2 head ${ "kernel-error" ERROR-FP-TRAP } = ;
 
 : test-traps ( traps inputs quot -- quot' fail-quot )
     append '[ _ _ with-fp-traps ] [ fp-trap-error? ] ;
index 4afbf9a837e37b2bd698a256f0ed6206d692d38b..9776b23f25506d60071340e2b3d547d4e5238bac 100644 (file)
@@ -1,5 +1,5 @@
-USING: arrays byte-arrays kernel kernel.private math memory
-namespaces sequences tools.test math.private quotations
+USING: arrays byte-arrays kernel kernel.private literals math
+memory namespaces sequences tools.test math.private quotations
 continuations prettyprint io.streams.string debugger assocs
 sequences.private accessors locals.backend grouping words
 system alien alien.accessors ;
@@ -14,11 +14,16 @@ IN: kernel.tests
 [ ] [ 1000 [ [ -1 f <array> ] ignore-errors ] times ] unit-test
 
 ! Make sure we report the correct error on stack underflow
-[ clear drop ] [ { "kernel-error" 10 f f } = ] must-fail-with
+[ clear drop ] [
+    ${ "kernel-error" ERROR-DATASTACK-UNDERFLOW f f } =
+] must-fail-with
 
 [ ] [ :c ] unit-test
 
-[ 3 [ { } set-retainstack ] dip ] [ { "kernel-error" 12 f f } = ] must-fail-with
+[
+    3 [ { } set-retainstack ] dip ]
+    [ ${ "kernel-error" ERROR-RETAINSTACK-UNDERFLOW f f } =
+] must-fail-with
 
 [ ] [ :c ] unit-test
 
@@ -35,15 +40,21 @@ IN: kernel.tests
 [ t "no-compile" set-word-prop ] each
 >>
 
-[ overflow-d ] [ { "kernel-error" 11 f f } = ] must-fail-with
+[ overflow-d ] [
+    ${ "kernel-error" ERROR-DATASTACK-OVERFLOW f f } =
+] must-fail-with
 
 [ ] [ :c ] unit-test
 
-[ overflow-d-alt ] [ { "kernel-error" 11 f f } = ] must-fail-with
+[ overflow-d-alt ] [
+    ${ "kernel-error" ERROR-DATASTACK-OVERFLOW f f } =
+] must-fail-with
 
 [ ] [ [ :c ] with-string-writer drop ] unit-test
 
-[ overflow-r ] [ { "kernel-error" 13 f f } = ] must-fail-with
+[ overflow-r ] [
+    ${ "kernel-error" ERROR-RETAINSTACK-OVERFLOW f f } =
+] must-fail-with
 
 [ ] [ :c ] unit-test
 
@@ -53,7 +64,9 @@ IN: kernel.tests
 ! because no facility exists to run memory protection
 ! fault handlers on an alternate callstack.
 os windows? [
-    [ overflow-c ] [ { "kernel-error" 15 f f } = ] must-fail-with
+    [ overflow-c ] [
+        ${ "kernel-error" ERROR-CALLSTACK-OVERFLOW f f } =
+    ] must-fail-with
 ] unless
 
 [ -7 <byte-array> ] must-fail
index 01e3e5929d5df83b6317a2f78a8f6535b0a84a03..413e7fc67e8fe7103bfee3a89af39db3906bbc4d 100644 (file)
@@ -364,3 +364,26 @@ CONSTANT: CONTEXT-OBJ-CONTEXT 2
 CONSTANT: CONTEXT-OBJ-IN-CALLBACK-P 3
 
 PRIVATE>
+
+! Runtime errors must be kept in sync with:
+!   vm/errors.hpp
+CONSTANT: kernel-error-count 19
+CONSTANT: ERROR-EXPIRED 0
+CONSTANT: ERROR-IO      1
+CONSTANT: ERROR-NOT-IMPLEMENTED 2
+CONSTANT: ERROR-TYPE 3
+CONSTANT: ERROR-DIVIDE-BY-ZERO 4
+CONSTANT: ERROR-SIGNAL 5
+CONSTANT: ERROR-ARRAY-SIZE 6
+CONSTANT: ERROR-C-STRING 7
+CONSTANT: ERROR-FFI 8
+CONSTANT: ERROR-UNDEFINED-SYMBOL 9
+CONSTANT: ERROR-DATASTACK-UNDERFLOW 10
+CONSTANT: ERROR-DATASTACK-OVERFLOW 11
+CONSTANT: ERROR-RETAINSTACK-UNDERFLOW 12
+CONSTANT: ERROR-RETAINSTACK-OVERFLOW 13
+CONSTANT: ERROR-CALLSTACK-UNDERFLOW 14
+CONSTANT: ERROR-CALLSTACK-OVERFLOW 15
+CONSTANT: ERROR-MEMORY 16
+CONSTANT: ERROR-FP-TRAP 17
+CONSTANT: ERROR-INTERRUPT 18
index 3334ef006623d75a6290090e4dd2fef93b223c46..fea72f1e08ef6573f31ec91629a888d1839c74a9 100644 (file)
@@ -1,4 +1,4 @@
-USING: continuations kernel math math.order namespaces make
+USING: continuations kernel literals math math.order namespaces make
 strings strings.private sbufs tools.test sequences vectors
 arrays memory prettyprint io.streams.null ;
 IN: strings.tests
@@ -49,7 +49,7 @@ unit-test
 [ 1 "" nth ] must-fail
 [ -6 "hello" nth ] must-fail
 
-[ t ] [ "hello world" dup >vector >string = ] unit-test 
+[ t ] [ "hello world" dup >vector >string = ] unit-test
 
 [ "ab" ] [ 2 "abc" resize-string ] unit-test
 [ "abc\0\0\0" ] [ 6 "abc" resize-string ] unit-test
@@ -58,7 +58,8 @@ unit-test
 [ "\u001234bc\0\0\0" ] [ 6 "\u001234bc" resize-string ] unit-test
 
 ! Random tester found this
-[ 2 -7 resize-string ] [ { "kernel-error" 3 11 -7 } = ] must-fail-with
+[ 2 -7 resize-string ]
+[ ${ "kernel-error" ERROR-TYPE 11 -7 } = ] must-fail-with
 
 ! Make sure 24-bit strings work
 "hello world" "s" set
index 5bd0fb0fa3a3868a63045970540aa95873f2132a..20f86eae405b44fc525ca8a01afcfb6b4aca5e18 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2009 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: continuations decimals grouping kernel locals math
-math.functions math.order math.ratios prettyprint random
+USING: continuations decimals grouping kernel literals locals
+math math.functions math.order math.ratios prettyprint random
 sequences tools.test ;
 IN: decimals.tests
 
@@ -33,11 +33,11 @@ ERROR: decimal-test-failure D1 D2 quot ;
     1000 [
         drop
         [ [ 100 D/ ] [ /f ] test-decimal-op ]
-        [ { "kernel-error" 4 f f } = ] recover
+        [ ${ "kernel-error" ERROR-DIVIDE-BY-ZERO f f } = ] recover
     ] all-integers?
 ] unit-test
 
-[ t ] [ 
+[ t ] [
     { D: 0. D: .0 D: 0.0 D: 00.00 D: . } all-equal?
 ] unit-test
 
index 7a026053d5b0085ff7b5b9a2afa0e819a1f731ee..b30a188980290dd1d150cf4040f47b0cf19f0394 100644 (file)
@@ -1,6 +1,7 @@
 namespace factor {
 
-/* Runtime errors */
+// Runtime errors must be kept in sync with:
+//   core/kernel/kernel.factor
 enum vm_error_type {
   ERROR_EXPIRED = 0,
   ERROR_IO,