|
From: Timothy H. <tim...@ma...> - 2002-04-27 17:36:43
|
I just checked in a Jscheme interpreter, it is available through CVS at
jscheme/src/jscheme/demo/jschemeint.scm
This interpreter handles full call/cc as well as tryCatch and throw
and the javadot notation. This is very new code and has not been
thoroughly tested yet. In particular, it does not correctly
self-interpret.
It is based on Marc Feeley's Scheme interpreter in that it compiles
expressions to closures, but each closure has three parameters:
F -- the local and global environments,
FC - the failure continuation (called on any errors that are thrown)
SC - the success continuation
The expressions are compiled using CPS.
The three key procedures used to implement this are the following:
> (define (GENCODEcallcc BODY)
> (lambda (F FC SC)
> (BODY F FC (lambda(k) (k SC)))))
>
> (define (GENCODEtryCatch BODY ELSE)
> (lambda (F FC SC)
> (BODY F (lambda (e) (ELSE F FC (lambda(k) (SC (k e))))) SC)))
>
> (define (GENCODEthrow BODY)
> (lambda (F FC SC)
> (BODY F FC (lambda(k) (FC k)))))
>
It doesn't yet pass the jscheme/SchemeTests.scm test, but it does
let you play with full call/cc, e.g.
> jscheme>> (+ 10 (call/cc (lambda(k) (set! k1 k) (k 15))))
> --> 25
> jscheme>> (k1 30)
> --> 40
and it also has tryCatch and throw
> jscheme >> (tryCatch (+ 5 (throw 'whoa)) (lambda(e) (list 'caught e)))
>
> --> (caught whoa)
> jscheme >> (tryCatch (+ 5 (/ 1 0)) (lambda(e) (list 'error-is e)))
>
> --> (error-is java.lang.ArithmeticException: / by zero)
> jscheme >>
I haven't yet explored the possible interactions between call/cc,
tryCatch, and threads.
I also haven't implemented the dynamic-wind stuff or tryCatchFinally.
Finally, this interpreter is 50 times slower that the normal Scheme
interpreter. I think I can speed this up to about 5-10 times slower,
but at least if someone really needs call/cc they can have access to
it within Jscheme.
I wonder if we can call ourselves a "real" scheme yet....
We're getting closer....
---Tim---
|