From: Tim Vaughan Date: Mon, 25 Jul 2016 11:06:24 +0000 (+1200) Subject: Working on exception handling. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=c91efd8c4adc50172e831c9cf22cc66cdc3fa6ad;p=scheme.forth.jl.git Working on exception handling. --- 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 +;