X-Git-Url: http://christophe.rhodes.io/gitweb/?p=swankr.git;a=blobdiff_plain;f=swank.R;h=f3a85ccc6a8b0d770b9273180bb179e717fc736d;hp=b7c4df35cb28e8a6e4a6359ae448958cc48aaedf;hb=19a4e9d454ec87e4374c5e92d69b47c7548fb5af;hpb=f96797f439428627da5c5435a03ad8fb0828e5cb diff --git a/swank.R b/swank.R index b7c4df3..f3a85cc 100644 --- a/swank.R +++ b/swank.R @@ -18,8 +18,9 @@ serve <- function(io) { mainLoop <- function(io) { while(TRUE) { - tryCatch(dispatch(io, readPacket(io)), - swankTopLevel=function(c) NULL) + withRestarts(tryCatch(dispatch(io, readPacket(io)), + swankTopLevel=function(c) NULL), + abort="return to SLIME's toplevel") } } @@ -49,24 +50,27 @@ emacsRex <- function(io, sldbState, form, pkg, thread, id, level=0) { ok <- TRUE }, error=function(c) { newSldbState <- makeSldbState(c, if(is.null(sldbState)) 0 else sldbState$level+1, id) - sldbLoop(io, newSldbState, id) })}, + withRestarts(sldbLoop(io, newSldbState, id), abort=paste("return to sldb level", newSldbState$level)) })}, finally=sendToEmacs(io, list(quote(`:return`), if(ok) list(quote(`:ok`), value) else list(quote(`:abort`)), id))) } makeSldbState <- function(condition, level, id) { calls <- rev(sys.calls())[-1] frames <- rev(sys.frames())[-1] - ret <- list(condition=condition, level=level, id=id, calls=calls, frames=frames) + restarts <- rev(computeRestarts(condition))[-1] + ret <- list(condition=condition, level=level, id=id, restarts=restarts, calls=calls, frames=frames) class(ret) <- c("sldbState", class(ret)) ret } sldbLoop <- function(io, sldbState, id) { - sendToEmacs(io, c(list(quote(`:debug`), id, sldbState$level), debuggerInfoForEmacs(sldbState))) - sendToEmacs(io, list(quote(`:debug-activate`), id, sldbState$level, FALSE)) - while(TRUE) { - dispatch(io, readPacket(io), sldbState) - } + tryCatch({ + sendToEmacs(io, c(list(quote(`:debug`), id, sldbState$level), debuggerInfoForEmacs(sldbState))) + sendToEmacs(io, list(quote(`:debug-activate`), id, sldbState$level, FALSE)) + while(TRUE) { + dispatch(io, readPacket(io), sldbState) + } + }, finally=sendToEmacs(io, c(list(quote(`:debug-return`), id, sldbState$level, FALSE)))) } debuggerInfoForEmacs <- function(sldbState, from=0, to=NULL) { @@ -78,7 +82,7 @@ debuggerInfoForEmacs <- function(sldbState, from=0, to=NULL) { function (x) { ret <- list(frameNumber, paste(format(x), sep="", collapse=" ")); frameNumber <<- 1+frameNumber; ret }}) } computeRestartsForEmacs <- function () { - lapply(computeRestarts(sldbState$condition), + lapply(sldbState$restarts, function(x) { ## this is all a little bit internalsy restartName <- x[[1]][[1]] @@ -270,7 +274,7 @@ printToString <- function(val) { `swank:invoke-nth-restart-for-emacs` <- function(io, sldbState, level, n) { if(sldbState$level == level) { - invokeRestart(computeRestarts()[[n+1]]) + invokeRestart(sldbState$restarts[[n+1]]) } }