on-tick appears to be doing something useful

This commit is contained in:
Danny Yoo 2011-07-18 10:28:39 -04:00
parent 815a632be1
commit 752bc5350e
3 changed files with 33 additions and 28 deletions

View File

@ -8,8 +8,9 @@ handler
"big bang should follow:" "big bang should follow:"
(big-bang 0 (big-bang 1
(on-tick add1 1) ;;(on-tick add1 1)
(on-tick (lambda (w) (* w 2)) 1)
;;(stop-when (lambda (w) (> w 10))) ;;(stop-when (lambda (w) (> w 10)))
) )

View File

@ -138,19 +138,22 @@
// internallCallDuringPause: call a Racket procedure and get its results. // internallCallDuringPause: call a Racket procedure and get its results.
// The use assumes the machine is in a running-but-paused state. // The use assumes the machine is in a running-but-paused state.
var internalCallDuringPause = function(MACHINE, proc, success, fail) { var internalCallDuringPause = function(MACHINE, proc, success, fail) {
if (! plt.baselib.arity.isArityMatching(proc.arity, args.length)) { if (! plt.baselib.arity.isArityMatching(proc.arity, arguments.length - 4)) {
return fail(plt.baselib.exceptions.makeExnFailContractArity("arity mismatch")); return fail(plt.baselib.exceptions.makeExnFailContractArity("arity mismatch"));
} }
if (isPrimitiveProcedure(proc)) { if (isPrimitiveProcedure(proc)) {
var args = []; var oldArgcount = MACHINE.argcount;
for (var i = 4; i < arguments.length; i++) { MACHINE.argcount = arguments.length - 4;
args.push(arguments[i]); for (var i = 0; i < arguments.length - 4; i++) {
MACHINE.env.push(arguments[arguments.length - 1 - i]);
} }
var result = v.apply(null, args); var result = proc.call(null, MACHINE);
succ(result); for (var i = 0; i < arguments.length - 4; i++) {
} else if (isClosure(v)) { MACHINE.env.pop();
}
success(result);
} else if (isClosure(proc)) {
var oldVal = MACHINE.val; var oldVal = MACHINE.val;
var oldArgcount = MACHINE.argcount; var oldArgcount = MACHINE.argcount;
var oldProc = MACHINE.proc; var oldProc = MACHINE.proc;
@ -163,7 +166,7 @@
MACHINE.val = oldVal; MACHINE.val = oldVal;
MACHINE.argcount = oldArgcount; MACHINE.argcount = oldArgcount;
MACHINE.proc = oldProc; MACHINE.proc = oldProc;
succ(returnValue); success(returnValue);
}); });
}; };
afterGoodInvoke.multipleValueReturn = function(MACHINE) { afterGoodInvoke.multipleValueReturn = function(MACHINE) {
@ -176,17 +179,17 @@
MACHINE.val = oldVal; MACHINE.val = oldVal;
MACHINE.argcount = oldArgcount; MACHINE.argcount = oldArgcount;
MACHINE.proc = oldProc; MACHINE.proc = oldProc;
succ.apply(null, returnValues); success.apply(null, returnValues);
}); });
}; };
MACHINE.control.push( MACHINE.control.push(
new plt.baselib.frames.CallFrame(afterGoodInvoke, null)); new plt.baselib.frames.CallFrame(afterGoodInvoke, null));
MACHINE.argcount = args.length; MACHINE.argcount = arguments.length - 4;
for (var i = 0; i < args.length; i++) { for (var i = 0; i < arguments.length - 4; i++) {
MACHINE.env.push(args[i]); MACHINE.env.push(arguments[arguments.length - 1 - i]);
} }
MACHINE.proc = v; MACHINE.proc = proc;
MACHINE.params['currentErrorHandler'] = function(MACHINE, e) { MACHINE.params['currentErrorHandler'] = function(MACHINE, e) {
MACHINE.params['currentErrorHandler'] = oldErrorHandler; MACHINE.params['currentErrorHandler'] = oldErrorHandler;
MACHINE.val = oldVal; MACHINE.val = oldVal;
@ -194,12 +197,12 @@
MACHINE.proc = oldProc; MACHINE.proc = oldProc;
fail(e); fail(e);
}; };
plt.runtime.trampoline(MACHINE, v.label); plt.runtime.trampoline(MACHINE, proc.label);
} else { } else {
fail(plt.baselib.exceptions.makeExnFail( fail(plt.baselib.exceptions.makeExnFail(
plt.baselib.format.format( plt.baselib.format.format(
"Not a procedure: ~e", "Not a procedure: ~e",
v))); proc)));
} }
}; };

View File

@ -157,18 +157,19 @@ var OnTick = function(handler, aDelay) {
OnTick.prototype = plt.baselib.heir(WorldConfigOption.prototype); OnTick.prototype = plt.baselib.heir(WorldConfigOption.prototype);
OnTick.prototype.toRawHandler = function(MACHINE) { OnTick.prototype.toRawHandler = function(MACHINE) {
var that = this;
var worldFunction = function(world, k) { var worldFunction = function(world, k) {
k(world + 1); plt.baselib.functions.internalCallDuringPause(
// plt.baselib.functions.internalCallDuringPause( MACHINE,
// MACHINE, that.handler,
// this.handler, function(v) {
// function(v) { k(v);
// k(v); },
// },
// function(err) { function(err) {
// console.log(err); console.log(err);
// }); },
world);
}; };
return rawJsworld.on_tick(this.delay, worldFunction); return rawJsworld.on_tick(this.delay, worldFunction);
}; };