From c91efd8c4adc50172e831c9cf22cc66cdc3fa6ad Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Mon, 25 Jul 2016 23:06:24 +1200 Subject: [PATCH] Working on exception handling. --- scheme.4th | 2 +- throw-catch.4th | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 throw-catch.4th diff --git a/scheme.4th b/scheme.4th index 8bc44d3..d93e722 100644 --- a/scheme.4th +++ b/scheme.4th @@ -3,7 +3,7 @@ scheme definitions include term-colours.4th include defer-is.4th -include catch-throw.4th +include throw-catch.4th defer read defer eval diff --git a/throw-catch.4th b/throw-catch.4th new file mode 100644 index 0000000..6cea956 --- /dev/null +++ b/throw-catch.4th @@ -0,0 +1,38 @@ +\ Words implementing exception handling + +: catch + execute + type ; + +: throw ( addr -- ) + begin + R> 2dup 1- ' catch = + while + drop + repeat + + >R +; + +: return-depth + RSP@ RSP0 - 1- ; + +: stack-trace + RSP0 1+ begin + dup RSP@ < + while + dup @ 1- @ >name cr .name + 1+ + repeat + + drop +; + +: trace + cr ." ---" cr + ." Return stack depth:" return-depth . cr + ." Stack trace:" + stack-trace + cr ." ---" cr + key drop +; -- 2.20.1