mit-scheme-devel
[Top][All Lists]
Advanced

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

[MIT-Scheme-devel] C callbacks into Scheme [was Re: sqlite3]


From: Taylor R Campbell
Subject: [MIT-Scheme-devel] C callbacks into Scheme [was Re: sqlite3]
Date: Fri, 17 May 2013 18:40:00 +0000
User-agent: IMAIL/1.21; Edwin/3.116; MIT-Scheme/9.1.1

Here's an initial (unfinished) sketch of an implementation of what I
described yesterday.  I haven't tested it, so I don't know whether it
works at all, but it has two major problems first anyway:

1. The semantics of throws out of callbacks should presumably be to
longjmp (and unwind the dstack so that C has a chance to clean up
after itself), but there is nothing to do that right now.

(We could refuse to throw out of callbacks, but then what?  We signal
an error and the poor luser will try to abort to the REPL, to no
avail.)

2. The C procedure scheme_callback expects that when the interpreter
returns, via RC_END_OF_COMPUTATION, it will be MICROCODE-CALLBACK that
is returning, but anything else could return via RC_END_OF_COMPUTATION
too.

For (1), using DYNAMIC-WIND in MICROCODE-CALLBACK to intercept throws
out of the callback isn't quite enough -- the consing it does might
trigger a GC interrupt which might trigger an abort to the REPL before
we have set up the DYNAMIC-WIND state to intercept throws.

Maybe the right thing would be to (a) add a new return code meaning
`return from microcode callback' and (b) teach unpack_control_point or
its callers to longjmp if the bottommost return code is that one.
This scheme would need some way of knowing how many longjmps are
necessary, though, and it's not immediately obvious how to do that.

For (2), all I can think of is either to hope it doesn't screw us up,
or to convert everything that currently uses RC_END_OF_COMPUTATION to
use scheme_callback instead.

Attachment: callback.c
Description: Text document

Attachment: callback.scm
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]