adding stop-when
This commit is contained in:
parent
66327c28ee
commit
6b498d1e7a
|
@ -11,7 +11,7 @@ handler
|
||||||
(big-bang 1
|
(big-bang 1
|
||||||
(on-tick add1 1)
|
(on-tick add1 1)
|
||||||
;;(on-tick (lambda (w) (* w 2)) 1)
|
;;(on-tick (lambda (w) (* w 2)) 1)
|
||||||
;;(stop-when (lambda (w) (> w 10)))
|
(stop-when (lambda (w) (> w 10)))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -270,15 +270,17 @@ EXPORTS['image-url'] =
|
||||||
1,
|
1,
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var url = checkString(MACHINE, 'image-url', 0);
|
var url = checkString(MACHINE, 'image-url', 0);
|
||||||
|
var oldArgcount = MACHINE.argcount;
|
||||||
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) {
|
||||||
finalizeClosureCall(
|
MACHINE.argcount = oldArgcount;
|
||||||
MACHINE,
|
finalizeClosureCall(
|
||||||
makeFileImage(url.toString(),
|
MACHINE,
|
||||||
rawImage));
|
makeFileImage(url.toString(),
|
||||||
|
rawImage));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
rawImage.onerror = function(e) {
|
rawImage.onerror = function(e) {
|
||||||
|
|
|
@ -456,6 +456,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
if(--MACHINE.callsBeforeTrampoline < 0) {
|
if(--MACHINE.callsBeforeTrampoline < 0) {
|
||||||
throw arguments.callee;
|
throw arguments.callee;
|
||||||
}
|
}
|
||||||
|
var oldArgcount = MACHINE.argcount;
|
||||||
|
|
||||||
var elt = MACHINE.env[MACHINE.env.length - 1];
|
var elt = MACHINE.env[MACHINE.env.length - 1];
|
||||||
var outputPort =
|
var outputPort =
|
||||||
MACHINE.params.currentOutputPort;
|
MACHINE.params.currentOutputPort;
|
||||||
|
@ -463,6 +465,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
outputPort.writeDomNode(MACHINE, toDomNode(elt, 'print'));
|
outputPort.writeDomNode(MACHINE, toDomNode(elt, 'print'));
|
||||||
outputPort.writeDomNode(MACHINE, toDomNode("\n", 'display'));
|
outputPort.writeDomNode(MACHINE, toDomNode("\n", 'display'));
|
||||||
}
|
}
|
||||||
|
MACHINE.argcount = oldArgcount;
|
||||||
return finalizeClosureCall(MACHINE, VOID);
|
return finalizeClosureCall(MACHINE, VOID);
|
||||||
},
|
},
|
||||||
1,
|
1,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
var PAUSE = plt.runtime.PAUSE;
|
var PAUSE = plt.runtime.PAUSE;
|
||||||
var makeClosure = plt.baselib.functions.makeClosure;
|
var makeClosure = plt.baselib.functions.makeClosure;
|
||||||
var makeRational = plt.baselib.numbers.makeRational;
|
var makeRational = plt.baselib.numbers.makeRational;
|
||||||
var finalizeClosureCall = plt.baselib.functions.finalizeClosureCall;
|
|
||||||
var makePrimitiveProcedure = plt.baselib.functions.makePrimitiveProcedure;
|
var makePrimitiveProcedure = plt.baselib.functions.makePrimitiveProcedure;
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +41,6 @@ EXPORTS['big-bang'] =
|
||||||
var initialWorldValue = MACHINE.env[MACHINE.env.length - 1];
|
var initialWorldValue = MACHINE.env[MACHINE.env.length - 1];
|
||||||
var handlers = [];
|
var handlers = [];
|
||||||
for (var i = 1; i < MACHINE.argcount; i++) {
|
for (var i = 1; i < MACHINE.argcount; i++) {
|
||||||
// FIXME: typecheck for configuration options
|
|
||||||
handlers.push(checkHandler(MACHINE, 'big-bang', i));
|
handlers.push(checkHandler(MACHINE, 'big-bang', i));
|
||||||
}
|
}
|
||||||
bigBang(MACHINE, initialWorldValue, handlers);
|
bigBang(MACHINE, initialWorldValue, handlers);
|
||||||
|
@ -74,20 +72,18 @@ EXPORTS['to-draw'] =
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var f = checkProcedure1(MACHINE, "on-tick", 0);
|
var f = checkProcedure1(MACHINE, "on-tick", 0);
|
||||||
return new OnDraw(f);
|
return new OnDraw(f);
|
||||||
// FILL ME IN
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EXPORTS['stop-when'] =
|
EXPORTS['stop-when'] =
|
||||||
makePrimitiveProcedure(
|
makePrimitiveProcedure(
|
||||||
'stop-when',
|
'stop-when',
|
||||||
1,
|
1,
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var f = checkProcedure1(MACHINE, "on-tick", 0);
|
var f = checkProcedure1(MACHINE, "on-tick", 0);
|
||||||
// FILL ME IN
|
return new StopWhen(f);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ var finalizeClosureCall = plt.baselib.functions.finalizeClosureCall;
|
||||||
|
|
||||||
var bigBang = function(MACHINE, initW, handlers) {
|
var bigBang = function(MACHINE, initW, handlers) {
|
||||||
|
|
||||||
|
var oldArgcount = MACHINE.argcount;
|
||||||
|
|
||||||
var toplevelNode = $('<div/>').css('border', '2').appendTo(document.body);
|
var toplevelNode = $('<div/>').css('border', '2').appendTo(document.body);
|
||||||
|
|
||||||
var configs = [];
|
var configs = [];
|
||||||
|
@ -59,6 +61,7 @@ var bigBang = function(MACHINE, initW, handlers) {
|
||||||
|
|
||||||
|
|
||||||
restart(function(MACHINE) {
|
restart(function(MACHINE) {
|
||||||
|
MACHINE.argcount = oldArgcount;
|
||||||
finalizeClosureCall(
|
finalizeClosureCall(
|
||||||
MACHINE,
|
MACHINE,
|
||||||
finalWorldValue);
|
finalWorldValue);
|
||||||
|
@ -222,9 +225,30 @@ DefaultOnDraw.prototype.toRawHandler = function(MACHINE) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var StopWhen = function(handler) {
|
||||||
|
WorldConfigOption.call(this, 'stop-when');
|
||||||
|
this.handler = handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
StopWhen.prototype = plt.baselib.heir(WorldConfigOption.prototype);
|
||||||
|
|
||||||
|
StopWhen.prototype.toRawHandler = function(MACHINE) {
|
||||||
|
var that = this;
|
||||||
|
var worldFunction = function(world, k) {
|
||||||
|
plt.baselib.functions.internalCallDuringPause(
|
||||||
|
MACHINE,
|
||||||
|
that.handler,
|
||||||
|
function(v) {
|
||||||
|
k(v);
|
||||||
|
},
|
||||||
|
|
||||||
|
function(err) {
|
||||||
|
console.log(err);
|
||||||
|
},
|
||||||
|
world);
|
||||||
|
}
|
||||||
|
return rawJsworld.stop_when(worldFunction);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user