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)))] (symbol->string (ModuleLocator-name modname)))]
[(eq? pred 'linked?) [(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)))])) (symbol->string (ModuleLocator-name modname)))]))
@ -521,4 +522,4 @@
(let ([t (VariableReference-toplevel varref)]) (let ([t (VariableReference-toplevel varref)])
(format "(new RT.VariableReference(M.e[M.e.length-~a],~a))" (format "(new RT.VariableReference(M.e[M.e.length-~a],~a))"
(add1 (ToplevelRef-depth t)) (add1 (ToplevelRef-depth t))
(ToplevelRef-pos t)))) (ToplevelRef-pos t))))

View File

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

View File

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

View File

@ -252,6 +252,11 @@
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.
this.installedModules = {}; // String -> (-> ModuleRecord)
// These are the modules that have been invoked.
this.modules = {}; // String -> ModuleRecord this.modules = {}; // String -> ModuleRecord
this.mainModules = []; // Arrayof String this.mainModules = []; // Arrayof String
this.params = { this.params = {
@ -1156,7 +1161,7 @@
// Other module loader implementations may do more interesting // Other module loader implementations may do more interesting
// things here, such as loading off the disk, or from the network. // things here, such as loading off the disk, or from the network.
var defaultModuleLoader = function(M, moduleName, success, fail) { var defaultModuleLoader = function(M, moduleName, success, fail) {
if (M.modules[moduleName] instanceof ModuleRecord) { if (M.installedModules[moduleName] !== undefined) {
return success(); return success();
} else { } else {
return fail(); return fail();
@ -1172,7 +1177,7 @@
var loadScript = baselib.loadscript.loadScript; var loadScript = baselib.loadscript.loadScript;
return function(M, moduleName, success, fail) { return function(M, moduleName, success, fail) {
if (M.modules[moduleName] instanceof ModuleRecord) { if (M.installedModules[moduleName] !== undefined) {
return success(); return success();
} else { } else {
// The manifest should map module names to // The manifest should map module names to

View File

@ -8,6 +8,9 @@
<body> <body>
<h1>Repl experiment</h1> <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> <div id="output" style="width:500px; height:300px; border:1px solid black; overflow:scroll"></div>
<br/> <br/>
<input id="repl" type="text" style="width:500px"></input><img id="break" src="break.png"/> <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 repl = $("#repl");
var output = $("#output"); var output = $("#output");
var breakButton = $("#break"); var breakButton = $("#break");
var resetButton = $("#reset");
breakButton.hide(); breakButton.hide();
breakButton.click(function() { interruptEvaluation(); }); 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. // We then want to initialize the language module.
M.params.currentDisplayer = function(MACHINE, domNode) { var initializeLanguage = function(afterLanguageInitialization) {
$(domNode).appendTo(output); // Load up the language.
output.get(0).scrollTop = output.get(0).scrollHeight; M.modules['whalesong/wescheme/lang/semantics.rkt'] =
}; M.installedModules['whalesong/wescheme/lang/semantics.rkt']();
M.params.currentErrorDisplayer = function(MACHINE, domNode) { var semanticsModule =
$(domNode).css("color", "red").appendTo(output); M.modules['whalesong/wescheme/lang/semantics.rkt'];
output.get(0).scrollTop = output.get(0).scrollHeight; semanticsModule.invoke(
}; M,
function() {
M.params.currentNamespace = semanticsModule.getNamespace();
// We then want to initialize the language module. afterLanguageInitialization();
var initializeLanguage = function(afterLanguageInitialization) { },
// Load up the language. function(M, err) {
var semanticsModule = // Nothing should work if we can't get this to work.
M.modules['whalesong/wescheme/lang/semantics.rkt']; console.log(M);
semanticsModule.invoke( console.log(err);
M, console.log(err.stack);
alert("uh oh!: language could not be loaded.");
});
};
repl.attr('disabled', 'true');
repl.val('Please wait, initializing...');
initializeLanguage(
function() { function() {
M.params.currentNamespace = semanticsModule.getNamespace(); repl.val('');
afterLanguageInitialization(); repl.removeAttr('disabled');
}, // Hook up a simple one-line REPL with enter triggering evaluation.
function(M, err) { repl.keypress(function(e) {
// Nothing should work if we can't get this to work. if (e.which == 13 && !repl.attr('disabled')) {
console.log(M); var src = repl.val();
console.log(err); $(this).val("");
console.log(err.stack); repl.attr('disabled', 'true');
alert("uh oh!: language could not be loaded."); 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. // CPS'ed for-each.
var forEachK = function(elts, f, after) { var forEachK = function(elts, f, after) {