[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Scheme-reports] Exceptions on JVM [was: Exceptions needs examples]



This is a belated follow-up to a discussion about implementing
r7rs exceptions on the JVM, and specifically:

http://lists.scheme-reports.org/pipermail/scheme-reports/2012-March/001982.html

FYI, I have implemented r6rs/r7rs-style exceptions on Kawa, roughly as
suggested in the message above.  I originally implemented guard using
the macro in R7RS, using with-exception-handler.  I also implemented
a 'simple-guard' using the same syntax as 'guard', but using a cond
inside a (native JVM) try-catch. (I used the guard-aux from r7rs.)
This worked for the test/examples I've seen, but of course
raise-continuable wouldn't get handled by a 'simple-guard'.
So I implemented John Cowan's suggestion: Changed simple-guard
to push a special mark (#!null) on the handler stack, and then
just replaced guard by the simple-guard implementation.

This implementation handles most test-cases - though not Hulmut
Eller's more complex example with dynamic-wind (in the followup
to the above-linked message).

Performance will be a little slower than using "native" exception
handling (try-catch, try-finally, and primitive-throw), but it shouldn't
be too bad.  guard will normally be more efficient than 
with-exception-handler:
guard is roughly a try-catch combined with a cond, though there is slightly
more overhead than that.  (See the code in kawa/lib/exceptions.scm.)
with-exception-handler will normally be able to inline the body 'thunk'
(if it is a lambda expression), but it can't inline the handler.

The source, if anyone is curious, is here:

https://sourceware.org/viewvc/kawa/trunk/kawa/lib/exceptions.scm
https://sourceware.org/viewvc/kawa/trunk/kawa/lib/ExceptionClasses.scm
-- 
	--Per Bothner
per@x   http://per.bothner.com/

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports