corrected the weirdness with saving the old argcount before restarting computation. Now the makeRestartFunction handles this low-level detail for us.

This commit is contained in:
Danny Yoo 2011-09-29 18:14:52 -04:00
parent 2251e7bf0e
commit c8f1ef07d4
5 changed files with 7 additions and 22 deletions

View File

@ -286,13 +286,11 @@ EXPORTS['bitmap/url'] =
1, 1,
function(MACHINE) { function(MACHINE) {
var url = checkString(MACHINE, 'bitmap/url', 0); var url = checkString(MACHINE, 'bitmap/url', 0);
var oldArgcount = MACHINE.a;
PAUSE( PAUSE(
function(restart) { function(restart) {
var rawImage = new Image(); var rawImage = new Image();
rawImage.onload = function() { rawImage.onload = function() {
restart(function(MACHINE) { restart(function(MACHINE) {
MACHINE.a = oldArgcount;
finalizeClosureCall( finalizeClosureCall(
MACHINE, MACHINE,
makeFileImage(url.toString(), makeFileImage(url.toString(),

View File

@ -432,8 +432,14 @@
}, },
0); 0);
}; };
// Creates a restarting function, that reschedules f in a context
// with the old argcount in place.
// Meant to be used only by the trampoline.
var makeRestartFunction = function(MACHINE) { var makeRestartFunction = function(MACHINE) {
var oldArgcount = MACHINE.a;
return function(f) { return function(f) {
MACHINE.a = oldArgcount;
return scheduleTrampoline(MACHINE, f); return scheduleTrampoline(MACHINE, f);
}; };
}; };

View File

@ -71,7 +71,7 @@ EXPORTS['specialize!'] = makeClosure(
1, 1,
function(MACHINE) { function(MACHINE) {
var resource = checkResource(MACHINE, 'specialize!', 0); var resource = checkResource(MACHINE, 'specialize!', 0);
var oldArgcount = MACHINE.a;
if (isImagePath(getResourceKey(resource).toString())) { if (isImagePath(getResourceKey(resource).toString())) {
return PAUSE( return PAUSE(
function(restart) { function(restart) {
@ -81,7 +81,6 @@ EXPORTS['specialize!'] = makeClosure(
delete(rawImage.onerror); delete(rawImage.onerror);
injectImageMethods(resource, rawImage); injectImageMethods(resource, rawImage);
restart(function(MACHINE) { restart(function(MACHINE) {
MACHINE.a = oldArgcount;
return finalizeClosureCall(MACHINE, resource); return finalizeClosureCall(MACHINE, resource);
}); });
}; };
@ -91,7 +90,6 @@ EXPORTS['specialize!'] = makeClosure(
// on any kind of image-loading error, fail out and // on any kind of image-loading error, fail out and
// just return the resource unchanged. // just return the resource unchanged.
restart(function(MACHINE) { restart(function(MACHINE) {
MACHINE.a = oldArgcount;
return finalizeClosureCall(MACHINE, resource); return finalizeClosureCall(MACHINE, resource);
}); });
} }

View File

@ -1083,7 +1083,6 @@
// bigBang. // bigBang.
var bigBang = function(MACHINE, world, handlers) { var bigBang = function(MACHINE, world, handlers) {
var oldArgcount = MACHINE.a;
var oldCurrentBigBangRecord = currentBigBangRecord; var oldCurrentBigBangRecord = currentBigBangRecord;
var running = true; var running = true;
@ -1117,7 +1116,6 @@
running = false; running = false;
stopEventHandlers(); stopEventHandlers();
restart(function(MACHINE) { restart(function(MACHINE) {
MACHINE.a = oldArgcount;
MACHINE.params.currentOutputPort = oldOutputPort; MACHINE.params.currentOutputPort = oldOutputPort;
currentBigBangRecord = oldCurrentBigBangRecord; currentBigBangRecord = oldCurrentBigBangRecord;
finalizeClosureCall(MACHINE, world); finalizeClosureCall(MACHINE, world);
@ -1543,12 +1541,10 @@
1, 1,
function(MACHINE) { function(MACHINE) {
var viewable = MACHINE.e[MACHINE.e.length - 1]; var viewable = MACHINE.e[MACHINE.e.length - 1];
var oldArgcount = MACHINE.a;
PAUSE(function(restart) { PAUSE(function(restart) {
coerseToView(viewable, coerseToView(viewable,
function(v) { function(v) {
restart(function(MACHINE) { restart(function(MACHINE) {
MACHINE.a = oldArgcount;
finalizeClosureCall(MACHINE, finalizeClosureCall(MACHINE,
new InitialViewHandler(v)); new InitialViewHandler(v));
}); });
@ -1571,12 +1567,10 @@
1, 1,
function(MACHINE) { function(MACHINE) {
var viewable = MACHINE.e[MACHINE.e.length - 1]; var viewable = MACHINE.e[MACHINE.e.length - 1];
var oldArgcount = MACHINE.a;
PAUSE(function(restart) { PAUSE(function(restart) {
coerseToMockView(viewable, coerseToMockView(viewable,
function(v) { function(v) {
restart(function(MACHINE) { restart(function(MACHINE) {
MACHINE.a = oldArgcount;
finalizeClosureCall(MACHINE, v); finalizeClosureCall(MACHINE, v);
}); });
}, },
@ -1897,13 +1891,11 @@
2, 2,
function(MACHINE) { function(MACHINE) {
var view = checkMockView(MACHINE, 'view-append-child', 0); var view = checkMockView(MACHINE, 'view-append-child', 0);
var oldArgcount = MACHINE.a;
var x = MACHINE.e[MACHINE.e.length - 2]; var x = MACHINE.e[MACHINE.e.length - 2];
PAUSE(function(restart) { PAUSE(function(restart) {
coerseToDomNode(x, coerseToDomNode(x,
function(dom) { function(dom) {
restart(function(MACHINE) { restart(function(MACHINE) {
MACHINE.a = oldArgcount;
var updatedView = view.appendChild(dom); var updatedView = view.appendChild(dom);
finalizeClosureCall(MACHINE, updatedView); finalizeClosureCall(MACHINE, updatedView);
}); });
@ -1927,13 +1919,11 @@
2, 2,
function(MACHINE) { function(MACHINE) {
var view = checkMockView(MACHINE, 'view-insert-right', 0); var view = checkMockView(MACHINE, 'view-insert-right', 0);
var oldArgcount = MACHINE.a;
var x = MACHINE.e[MACHINE.e.length - 2]; var x = MACHINE.e[MACHINE.e.length - 2];
PAUSE(function(restart) { PAUSE(function(restart) {
coerseToDomNode(x, coerseToDomNode(x,
function(dom) { function(dom) {
restart(function(MACHINE) { restart(function(MACHINE) {
MACHINE.a = oldArgcount;
var updatedView = view.insertRight(dom); var updatedView = view.insertRight(dom);
finalizeClosureCall(MACHINE, updatedView); finalizeClosureCall(MACHINE, updatedView);
}); });
@ -1959,13 +1949,11 @@
2, 2,
function(MACHINE) { function(MACHINE) {
var view = checkMockView(MACHINE, 'view-insert-left', 0); var view = checkMockView(MACHINE, 'view-insert-left', 0);
var oldArgcount = MACHINE.a;
var x = MACHINE.e[MACHINE.e.length - 2]; var x = MACHINE.e[MACHINE.e.length - 2];
PAUSE(function(restart) { PAUSE(function(restart) {
coerseToDomNode(x, coerseToDomNode(x,
function(dom) { function(dom) {
restart(function(MACHINE) { restart(function(MACHINE) {
MACHINE.a = oldArgcount;
var updatedView = view.insertLeft(dom); var updatedView = view.insertLeft(dom);
finalizeClosureCall(MACHINE, updatedView); finalizeClosureCall(MACHINE, updatedView);
}); });

View File

@ -24,9 +24,6 @@ var finalizeClosureCall = plt.baselib.functions.finalizeClosureCall;
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
var bigBang = function(MACHINE, initW, handlers) { var bigBang = function(MACHINE, initW, handlers) {
var oldArgcount = MACHINE.a;
var outerToplevelNode = $('<span/>').css('padding', '0px').get(0); var outerToplevelNode = $('<span/>').css('padding', '0px').get(0);
MACHINE.params.currentOutputPort.writeDomNode(MACHINE, outerToplevelNode); MACHINE.params.currentOutputPort.writeDomNode(MACHINE, outerToplevelNode);
var toplevelNode = $('<span/>').css('padding', '0px').appendTo(outerToplevelNode).get(0); var toplevelNode = $('<span/>').css('padding', '0px').appendTo(outerToplevelNode).get(0);
@ -65,9 +62,7 @@ var bigBang = function(MACHINE, initW, handlers) {
function(finalWorldValue) { function(finalWorldValue) {
// state.removeBreakRequestedListener(onBreak); // state.removeBreakRequestedListener(onBreak);
restart(function(MACHINE) { restart(function(MACHINE) {
MACHINE.a = oldArgcount;
finalizeClosureCall( finalizeClosureCall(
MACHINE, MACHINE,
finalWorldValue); finalWorldValue);