Correcting issues with break and reset.
This commit is contained in:
parent
8900771b4a
commit
4b84eda6f4
|
@ -203,12 +203,12 @@
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
if (MACHINE.breakScheduled) {
|
if (MACHINE.breakScheduled) {
|
||||||
MACHINE.breakScheduled = false;
|
return fail(baselib.exceptions.makeExnBreak(
|
||||||
return fail(baselib.exceptions.makeExnBreak("User break.",
|
"User break.",
|
||||||
MACHINE.captureContinuationMarks(),
|
MACHINE.captureContinuationMarks(),
|
||||||
// FIXME: capture the continuation as well,
|
// FIXME: capture the continuation as well,
|
||||||
// rather than just hold false.
|
// rather than just hold false.
|
||||||
false));
|
false));
|
||||||
}
|
}
|
||||||
|
|
||||||
var oldArgcount, oldVal, oldProc, oldErrorHandler, oldControlLength, oldEnvLength;
|
var oldArgcount, oldVal, oldProc, oldErrorHandler, oldControlLength, oldEnvLength;
|
||||||
|
|
|
@ -329,12 +329,16 @@
|
||||||
this.globals = {};
|
this.globals = {};
|
||||||
this.primitives = Primitives;
|
this.primitives = Primitives;
|
||||||
this.exclusiveLock = new ExclusiveLock();
|
this.exclusiveLock = new ExclusiveLock();
|
||||||
this.breakScheduled = false;
|
this.breakScheduled = false; // (U boolean function)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Schedule a break the next time the trampoline begins.
|
// Schedule a break the next time the trampoline begins.
|
||||||
Machine.prototype.scheduleBreak = function() {
|
Machine.prototype.scheduleBreak = function(afterBreak) {
|
||||||
this.breakScheduled = true;
|
if (typeof afterBreak === 'function') {
|
||||||
|
this.breakScheduled = afterBreak;
|
||||||
|
} else {
|
||||||
|
this.breakScheduled = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -486,8 +490,12 @@
|
||||||
|
|
||||||
// Checks to see if we need to handle break. If so, returns true.
|
// Checks to see if we need to handle break. If so, returns true.
|
||||||
// Otherwise, returns false.
|
// Otherwise, returns false.
|
||||||
var maybeHandleBreak = function(MACHINE) {
|
//
|
||||||
if (MACHINE.breakScheduled) {
|
// FIXME: This logic is duplicated within one of the catch blocks
|
||||||
|
// in the trampoline. Would be nice to refactor.
|
||||||
|
var maybeHandleBreakOutsideTrampoline = function(MACHINE) {
|
||||||
|
var breakScheduled = MACHINE.breakScheduled;
|
||||||
|
if (breakScheduled) {
|
||||||
MACHINE.breakScheduled = false;
|
MACHINE.breakScheduled = false;
|
||||||
MACHINE.running = false;
|
MACHINE.running = false;
|
||||||
MACHINE.params.currentErrorHandler(
|
MACHINE.params.currentErrorHandler(
|
||||||
|
@ -499,6 +507,9 @@
|
||||||
// FIXME: capture the continuation as well,
|
// FIXME: capture the continuation as well,
|
||||||
// rather than just hold false.
|
// rather than just hold false.
|
||||||
false)));
|
false)));
|
||||||
|
if (typeof breakScheduled === 'function') {
|
||||||
|
setTimeout(breakScheduled, 0);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -507,7 +518,10 @@
|
||||||
var scheduleTrampoline = function(MACHINE, f, release) {
|
var scheduleTrampoline = function(MACHINE, f, release) {
|
||||||
setTimeout(
|
setTimeout(
|
||||||
function() {
|
function() {
|
||||||
if (maybeHandleBreak(MACHINE)) { release(); return; }
|
if (maybeHandleBreakOutsideTrampoline(MACHINE)) {
|
||||||
|
release();
|
||||||
|
return;
|
||||||
|
}
|
||||||
MACHINE._trampoline(f, false, release);
|
MACHINE._trampoline(f, false, release);
|
||||||
},
|
},
|
||||||
0);
|
0);
|
||||||
|
@ -659,13 +673,26 @@
|
||||||
return;
|
return;
|
||||||
} else if (e instanceof HaltError) {
|
} else if (e instanceof HaltError) {
|
||||||
that.running = false;
|
that.running = false;
|
||||||
|
that.breakScheduled = false;
|
||||||
e.onHalt(that);
|
e.onHalt(that);
|
||||||
release();
|
release();
|
||||||
return;
|
return;
|
||||||
|
} else if (e instanceof baselib.exceptions.RacketError &&
|
||||||
|
baselib.exceptions.isExnBreak(e.racketError)) {
|
||||||
|
var oldBreakScheduled = that.breakScheduled;
|
||||||
|
if (typeof oldBreakScheduled === 'function') {
|
||||||
|
setTimeout(oldBreakScheduled, 0);
|
||||||
|
}
|
||||||
|
that.running = false;
|
||||||
|
that.breakScheduled = false;
|
||||||
|
that.params.currentErrorHandler(that, e);
|
||||||
|
release();
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
// General error condition: just exit out
|
// General error condition: just exit out
|
||||||
// of the trampoline and call the current error handler.
|
// of the trampoline and call the current error handler.
|
||||||
that.running = false;
|
that.running = false;
|
||||||
|
that.breakScheduled = false;
|
||||||
that.params.currentErrorHandler(that, e);
|
that.params.currentErrorHandler(that, e);
|
||||||
release();
|
release();
|
||||||
return;
|
return;
|
||||||
|
@ -673,6 +700,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
that.running = false;
|
that.running = false;
|
||||||
|
that.breakScheduled = false;
|
||||||
that.params.currentSuccessHandler(that);
|
that.params.currentSuccessHandler(that);
|
||||||
release();
|
release();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
jQuery(document).ready(function() {
|
jQuery(document).ready(function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
if (! console.log) { console.log = function() { }; }
|
|
||||||
|
// if (! console.log) { console.log = function() { }; }
|
||||||
|
|
||||||
var repl = jQuery("#repl");
|
var repl = jQuery("#repl");
|
||||||
var output = jQuery("#output");
|
var output = jQuery("#output");
|
||||||
var breakButton = jQuery("#break");
|
var breakButton = jQuery("#break");
|
||||||
var resetButton = jQuery("#reset");
|
var resetButton = jQuery("#reset");
|
||||||
breakButton.hide();
|
|
||||||
breakButton.click(function() { interruptEvaluation(); });
|
|
||||||
resetButton.click(function() { output.empty(); setupMachine(); });
|
|
||||||
|
|
||||||
|
|
||||||
// The machine.
|
// The machine.
|
||||||
|
@ -23,6 +22,30 @@ jQuery(document).ready(function() {
|
||||||
{ remote: 'rpc.html' },
|
{ remote: 'rpc.html' },
|
||||||
{ remote: { replCompile: {} } });
|
{ remote: { replCompile: {} } });
|
||||||
|
|
||||||
|
|
||||||
|
var onBreak = function() {
|
||||||
|
if (M.running) {
|
||||||
|
interruptEvaluation(function(){});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var onReset = function() {
|
||||||
|
if (M.running) {
|
||||||
|
M.params.currentDisplayer =
|
||||||
|
function(MACHINE, domNode) {};
|
||||||
|
M.params.currentErrorDisplayer =
|
||||||
|
function(MACHINE, domNode) {};
|
||||||
|
interruptEvaluation(
|
||||||
|
function() {
|
||||||
|
output.empty();
|
||||||
|
setupMachine();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
output.empty();
|
||||||
|
setupMachine();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var setupMachine = function() {
|
var setupMachine = function() {
|
||||||
M = plt.runtime.currentMachine;
|
M = plt.runtime.currentMachine;
|
||||||
|
@ -98,11 +121,11 @@ jQuery(document).ready(function() {
|
||||||
// writeErrorMessage: string -> void
|
// writeErrorMessage: string -> void
|
||||||
// Write out an error message.
|
// Write out an error message.
|
||||||
var writeErrorMessage = function(msg) {
|
var writeErrorMessage = function(msg) {
|
||||||
jQuery("<span/>")
|
M.params.currentErrorDisplayer(M,
|
||||||
.text(''+msg)
|
jQuery("<span/>")
|
||||||
.css("color", "red")
|
.text(''+msg)
|
||||||
.appendTo(output);
|
.css("color", "red"));
|
||||||
jQuery("<br/>").appendTo(output);
|
M.params.currentErrorDisplayer(M, jQuery("<br/>"));
|
||||||
sendOutputToBottom();
|
sendOutputToBottom();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -121,16 +144,19 @@ jQuery(document).ready(function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var interruptEvaluation = function() {
|
var interruptEvaluation = function(afterBreak) {
|
||||||
M.scheduleBreak();
|
if (! M.running) {
|
||||||
|
throw new Error("internal error: trying to interrupt evaluation but nothing is running.");
|
||||||
|
}
|
||||||
|
M.scheduleBreak(afterBreak);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// In evaluation, we'll send compilation requests to the server,
|
// In evaluation, we'll send compilation requests to the server,
|
||||||
// and get back bytecode that we should evaluate.
|
// and get back bytecode that we should evaluate.
|
||||||
var compileAndEvaluate = function(src, after) {
|
var compileAndEvaluate = function(src, after) {
|
||||||
jQuery("<tt/>").text('> ' + src).appendTo(output);
|
M.params.currentDisplayer(M, jQuery("<tt/>").text('> ' + src));
|
||||||
jQuery("<br/>").appendTo(output);
|
M.params.currentDisplayer(M, jQuery("<br/>"));
|
||||||
var onCompile = function(compiledResult) {
|
var onCompile = function(compiledResult) {
|
||||||
if (compiledResult.type === 'repl') {
|
if (compiledResult.type === 'repl') {
|
||||||
return onGoodReplCompile(compiledResult);
|
return onGoodReplCompile(compiledResult);
|
||||||
|
@ -177,7 +203,6 @@ jQuery(document).ready(function() {
|
||||||
after);
|
after);
|
||||||
};
|
};
|
||||||
var onServerError = function(err) {
|
var onServerError = function(err) {
|
||||||
console.log(err);
|
|
||||||
writeErrorMessage("internal server error");
|
writeErrorMessage("internal server error");
|
||||||
after();
|
after();
|
||||||
};
|
};
|
||||||
|
@ -199,5 +224,9 @@ jQuery(document).ready(function() {
|
||||||
// Test: compile a module.
|
// Test: compile a module.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
breakButton.hide();
|
||||||
|
breakButton.click(onBreak);
|
||||||
|
resetButton.click(onReset);
|
||||||
setupMachine();
|
setupMachine();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user