diff --git a/basis/compiler/tests/linkage-errors.factor b/basis/compiler/tests/linkage-errors.factor index 98a07899f3..ca9b694644 100644 --- a/basis/compiler/tests/linkage-errors.factor +++ b/basis/compiler/tests/linkage-errors.factor @@ -10,7 +10,7 @@ FUNCTION: void this_does_not_exist ( ) ; [ this_does_not_exist ] try [ this_does_not_exist ] [ - { "kernel-error" 9 $[ "this_does_not_exist" string>symbol ] f } + ${ "kernel-error" ERROR-UNDEFINED-SYMBOL "this_does_not_exist" string>symbol f } = ] must-fail-with @@ -31,10 +31,10 @@ FUNCTION: void no_such_function ( ) ; [ no_such_function ] try [ no_such_function ] [ - { - "kernel-error" 9 - $[ "no_such_function" string>symbol ] - $[ "no_such_library" load-library ] + ${ + "kernel-error" ERROR-UNDEFINED-SYMBOL + "no_such_function" string>symbol + "no_such_library" load-library } = ] must-fail-with diff --git a/basis/debugger/debugger.factor b/basis/debugger/debugger.factor index debe579b93..8ff06fda29 100755 --- a/basis/debugger/debugger.factor +++ b/basis/debugger/debugger.factor @@ -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 ; diff --git a/basis/math/floats/env/env-tests.factor b/basis/math/floats/env/env-tests.factor index df4e9e3d11..3de8c2bf0a 100755 --- a/basis/math/floats/env/env-tests.factor +++ b/basis/math/floats/env/env-tests.factor @@ -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? ] ; diff --git a/core/kernel/kernel-tests.factor b/core/kernel/kernel-tests.factor index 4afbf9a837..9776b23f25 100644 --- a/core/kernel/kernel-tests.factor +++ b/core/kernel/kernel-tests.factor @@ -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 ] 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 ] must-fail diff --git a/core/kernel/kernel.factor b/core/kernel/kernel.factor index 01e3e5929d..413e7fc67e 100644 --- a/core/kernel/kernel.factor +++ b/core/kernel/kernel.factor @@ -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 diff --git a/core/strings/strings-tests.factor b/core/strings/strings-tests.factor index 3334ef0066..fea72f1e08 100644 --- a/core/strings/strings-tests.factor +++ b/core/strings/strings-tests.factor @@ -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 diff --git a/extra/decimals/decimals-tests.factor b/extra/decimals/decimals-tests.factor index 5bd0fb0fa3..20f86eae40 100644 --- a/extra/decimals/decimals-tests.factor +++ b/extra/decimals/decimals-tests.factor @@ -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 diff --git a/vm/errors.hpp b/vm/errors.hpp index 7a026053d5..b30a188980 100644 --- a/vm/errors.hpp +++ b/vm/errors.hpp @@ -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,