in the middle of making reset work.

This commit is contained in:
Danny Yoo 2013-03-08 17:27:32 -07:00
parent 7a21f1f9b4
commit 453b047920
6 changed files with 88 additions and 70 deletions

View File

@ -512,7 +512,8 @@
(symbol->string (ModuleLocator-name modname)))]
[(eq? pred 'linked?)
(format "(M.modules[~s]!==void(0))"
(format "(M.installedModules[~s]!==void(0)&&M.modules[~s]!==undefined)"
(symbol->string (ModuleLocator-name modname))
(symbol->string (ModuleLocator-name modname)))]))

View File

@ -161,21 +161,21 @@
[(LinkModule!? op)
(format "RT.PAUSE(
function(restart){
RT.currentModuleLoader(M,~s,
var modname = ~s;
RT.currentModuleLoader(M,modname,
function(){
restart(function(M){ console.log('resume after loading ~a'); ~a(M); });
M.modules[modname] = M.installedModules[modname]();
restart(~a);
},
function(){
RT.raiseModuleLoadingError(M,~s);
RT.raiseModuleLoadingError(M,modname);
});
});"
(symbol->string (ModuleLocator-name (LinkModule!-path op)))
(symbol->string (ModuleLocator-name (LinkModule!-path op)))
(assemble-label (make-Label (LinkModule!-label op)))
(symbol->string (ModuleLocator-name (LinkModule!-path op))))]
(assemble-label (make-Label (LinkModule!-label op))))]
[(InstallModuleEntry!? op)
(format "M.modules[~s]=new RT.ModuleRecord(~s,~a);"
(format "M.installedModules[~s]=function(){return new RT.ModuleRecord(~s,~a);}"
(symbol->string (ModuleLocator-name (InstallModuleEntry!-path op)))
(symbol->string (InstallModuleEntry!-name op))
(assemble-label (make-Label (InstallModuleEntry!-entry-point op))))]

View File

@ -234,11 +234,12 @@
(make-UninterpretedSource
path
(format "
M.modules[~s] =
new plt.runtime.ModuleRecord(~s,
M.installedModules[~s] = function() {
return new plt.runtime.ModuleRecord(~s,
function(M) {
~a
});
}
"
(symbol->string name)
(symbol->string name)
@ -300,12 +301,14 @@ M.modules[~s] =
(format "
var ~a = function() { ~a };
plt.runtime.PAUSE(function(restart) {
var modName = ~s;
plt.runtime.currentModuleLoader(M,
~s,
modName,
function() {
restart(function(M) {
if (! M.modules[~s].isInvoked) {
M.modules[~s].internalInvoke(M,
M.modules[modName] = M.installedModules[modName]();
if (! M.modules[modName].isInvoked) {
M.modules[modName].internalInvoke(M,
~a,
M.params.currentErrorHandler);
} else {
@ -314,17 +317,14 @@ M.modules[~s] =
})
},
function() {
alert('Could not load ~s');
alert('Could not load ' + modName);
})
}); "
afterName
after
(symbol->string name)
(symbol->string name)
(symbol->string name)
afterName
afterName
(symbol->string name))))
afterName)))

View File

@ -252,6 +252,11 @@
this.e = []; // environment
this.c = []; // control: Arrayof (U Frame CallFrame PromptFrame)
this.running = false;
// These are the modules that have been installed. They are not
// necessarily invoked yet.
this.installedModules = {}; // String -> (-> ModuleRecord)
// These are the modules that have been invoked.
this.modules = {}; // String -> ModuleRecord
this.mainModules = []; // Arrayof String
this.params = {
@ -1156,7 +1161,7 @@
// Other module loader implementations may do more interesting
// things here, such as loading off the disk, or from the network.
var defaultModuleLoader = function(M, moduleName, success, fail) {
if (M.modules[moduleName] instanceof ModuleRecord) {
if (M.installedModules[moduleName] !== undefined) {
return success();
} else {
return fail();
@ -1172,7 +1177,7 @@
var loadScript = baselib.loadscript.loadScript;
return function(M, moduleName, success, fail) {
if (M.modules[moduleName] instanceof ModuleRecord) {
if (M.installedModules[moduleName] !== undefined) {
return success();
} else {
// The manifest should map module names to

View File

@ -8,6 +8,9 @@
<body>
<h1>Repl experiment</h1>
<input id="reset" type="button" value="Reset"/>
<br/>
<div id="output" style="width:500px; height:300px; border:1px solid black; overflow:scroll"></div>
<br/>
<input id="repl" type="text" style="width:500px"></input><img id="break" src="break.png"/>

View File

@ -5,66 +5,75 @@ $(document).ready(function() {
var repl = $("#repl");
var output = $("#output");
var breakButton = $("#break");
var resetButton = $("#reset");
breakButton.hide();
breakButton.click(function() { interruptEvaluation(); });
resetButton.click(function() { setupMachine(); });
var M = plt.runtime.currentMachine;
var M;
var setupMachine = function() {
M = plt.runtime.currentMachine;
// We configure output to send it to the "output" DOM node.
M.params.currentDisplayer = function(MACHINE, domNode) {
$(domNode).appendTo(output);
output.get(0).scrollTop = output.get(0).scrollHeight;
};
M.params.currentErrorDisplayer = function(MACHINE, domNode) {
$(domNode).css("color", "red").appendTo(output);
output.get(0).scrollTop = output.get(0).scrollHeight;
};
// We configure output to send it to the "output" DOM node.
M.params.currentDisplayer = function(MACHINE, domNode) {
$(domNode).appendTo(output);
output.get(0).scrollTop = output.get(0).scrollHeight;
};
M.params.currentErrorDisplayer = function(MACHINE, domNode) {
$(domNode).css("color", "red").appendTo(output);
output.get(0).scrollTop = output.get(0).scrollHeight;
};
// We then want to initialize the language module.
var initializeLanguage = function(afterLanguageInitialization) {
// Load up the language.
var semanticsModule =
M.modules['whalesong/wescheme/lang/semantics.rkt'];
semanticsModule.invoke(
M,
// We then want to initialize the language module.
var initializeLanguage = function(afterLanguageInitialization) {
// Load up the language.
M.modules['whalesong/wescheme/lang/semantics.rkt'] =
M.installedModules['whalesong/wescheme/lang/semantics.rkt']();
var semanticsModule =
M.modules['whalesong/wescheme/lang/semantics.rkt'];
semanticsModule.invoke(
M,
function() {
M.params.currentNamespace = semanticsModule.getNamespace();
afterLanguageInitialization();
},
function(M, err) {
// Nothing should work if we can't get this to work.
console.log(M);
console.log(err);
console.log(err.stack);
alert("uh oh!: language could not be loaded.");
});
};
repl.attr('disabled', 'true');
repl.val('Please wait, initializing...');
initializeLanguage(
function() {
M.params.currentNamespace = semanticsModule.getNamespace();
afterLanguageInitialization();
},
function(M, err) {
// Nothing should work if we can't get this to work.
console.log(M);
console.log(err);
console.log(err.stack);
alert("uh oh!: language could not be loaded.");
repl.val('');
repl.removeAttr('disabled');
// Hook up a simple one-line REPL with enter triggering evaluation.
repl.keypress(function(e) {
if (e.which == 13 && !repl.attr('disabled')) {
var src = repl.val();
$(this).val("");
repl.attr('disabled', 'true');
repl.val("... evaluating...");
breakButton.show();
compileAndEvaluate(src,
function() { repl.removeAttr('disabled');
repl.val("");
breakButton.hide();});
}
});
});
};
repl.attr('disabled', 'true');
repl.val('Please wait, initializing...');
initializeLanguage(
function() {
repl.val('');
repl.removeAttr('disabled');
// Hook up a simple one-line REPL with enter triggering evaluation.
repl.keypress(function(e) {
if (e.which == 13 && !repl.attr('disabled')) {
var src = repl.val();
$(this).val("");
repl.attr('disabled', 'true');
repl.val("... evaluating...");
breakButton.show();
compileAndEvaluate(src,
function() { repl.removeAttr('disabled');
repl.val("");
breakButton.hide();});
}
});
});
setupMachine();
// CPS'ed for-each.
var forEachK = function(elts, f, after) {