Working on exception handling.
authorTim Vaughan <tgvaughan@gmail.com>
Mon, 25 Jul 2016 11:06:24 +0000 (23:06 +1200)
committerTim Vaughan <tgvaughan@gmail.com>
Mon, 25 Jul 2016 11:06:24 +0000 (23:06 +1200)
scheme.4th
throw-catch.4th [new file with mode: 0644]

index 8bc44d3..d93e722 100644 (file)
@@ -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 (file)
index 0000000..6cea956
--- /dev/null
@@ -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
+;