reset appears to be doing something.

This commit is contained in:
Danny Yoo 2013-03-08 17:38:17 -07:00
parent 453b047920
commit af894366d3
2 changed files with 26 additions and 10 deletions

View File

@ -245,6 +245,18 @@
// The MACHINE // The MACHINE
var Machine = function() { var Machine = function() {
// These are the modules that have been installed. They are not
// necessarily invoked yet.
this.installedModules = {}; // String -> (-> ModuleRecord)
this.reset();
};
// Resets the state of the machine. Almost all of the system's
// state is reset, except the installedModules, which should
// persist as an optimization to reduce loading code over and
// over.
Machine.prototype.reset = function() {
this.cbt = STACK_LIMIT_ESTIMATE; // calls before trampoline this.cbt = STACK_LIMIT_ESTIMATE; // calls before trampoline
this.v = void(0); // value register this.v = void(0); // value register
this.p = void(0); // procedure register this.p = void(0); // procedure register
@ -252,9 +264,9 @@
this.e = []; // environment this.e = []; // environment
this.c = []; // control: Arrayof (U Frame CallFrame PromptFrame) this.c = []; // control: Arrayof (U Frame CallFrame PromptFrame)
this.running = false; this.running = false;
// These are the modules that have been installed. They are not
// necessarily invoked yet. // We do not initialize installedModules here because
this.installedModules = {}; // String -> (-> ModuleRecord) // we want that to persist.
// These are the modules that have been invoked. // These are the modules that have been invoked.
this.modules = {}; // String -> ModuleRecord this.modules = {}; // String -> ModuleRecord
@ -313,8 +325,6 @@
'maxNumBouncesBeforeYield': 2000, // self-adjusting 'maxNumBouncesBeforeYield': 2000, // self-adjusting
'currentPrint': defaultCurrentPrint 'currentPrint': defaultCurrentPrint
}; };
this.globals = {}; this.globals = {};
this.primitives = Primitives; this.primitives = Primitives;
@ -322,7 +332,6 @@
this.breakScheduled = false; this.breakScheduled = false;
}; };
// 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() {
this.breakScheduled = true; this.breakScheduled = true;

View File

@ -8,22 +8,27 @@ $(document).ready(function() {
var resetButton = $("#reset"); var resetButton = $("#reset");
breakButton.hide(); breakButton.hide();
breakButton.click(function() { interruptEvaluation(); }); breakButton.click(function() { interruptEvaluation(); });
resetButton.click(function() { setupMachine(); }); resetButton.click(function() { output.empty(); setupMachine(); });
var M; var M;
var sendOutputToBottom = function() {
output.get(0).scrollTop = output.get(0).scrollHeight;
};
var setupMachine = function() { var setupMachine = function() {
M = plt.runtime.currentMachine; M = plt.runtime.currentMachine;
M.reset();
// We configure output to send it to the "output" DOM node. // We configure output to send it to the "output" DOM node.
M.params.currentDisplayer = function(MACHINE, domNode) { M.params.currentDisplayer = function(MACHINE, domNode) {
$(domNode).appendTo(output); $(domNode).appendTo(output);
output.get(0).scrollTop = output.get(0).scrollHeight; sendOutputToBottom();
}; };
M.params.currentErrorDisplayer = function(MACHINE, domNode) { M.params.currentErrorDisplayer = function(MACHINE, domNode) {
$(domNode).css("color", "red").appendTo(output); $(domNode).css("color", "red").appendTo(output);
output.get(0).scrollTop = output.get(0).scrollHeight; sendOutputToBottom();
}; };
@ -32,6 +37,7 @@ $(document).ready(function() {
// Load up the language. // Load up the language.
M.modules['whalesong/wescheme/lang/semantics.rkt'] = M.modules['whalesong/wescheme/lang/semantics.rkt'] =
M.installedModules['whalesong/wescheme/lang/semantics.rkt'](); M.installedModules['whalesong/wescheme/lang/semantics.rkt']();
var semanticsModule = var semanticsModule =
M.modules['whalesong/wescheme/lang/semantics.rkt']; M.modules['whalesong/wescheme/lang/semantics.rkt'];
semanticsModule.invoke( semanticsModule.invoke(
@ -97,6 +103,7 @@ $(document).ready(function() {
.css("color", "red") .css("color", "red")
.appendTo(output); .appendTo(output);
$("<br/>").appendTo(output); $("<br/>").appendTo(output);
sendOutputToBottom();
}; };