From 752bc5350ebb65ecbb7af00017a0ff4bc8a1a080 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 18 Jul 2011 10:28:39 -0400 Subject: [PATCH] on-tick appears to be doing something useful --- examples/counting-world-program.rkt | 5 +-- js-assembler/runtime-src/baselib-functions.js | 35 ++++++++++--------- world/kernel.js | 21 +++++------ 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/examples/counting-world-program.rkt b/examples/counting-world-program.rkt index 7250a61..47c3fcc 100644 --- a/examples/counting-world-program.rkt +++ b/examples/counting-world-program.rkt @@ -8,8 +8,9 @@ handler "big bang should follow:" -(big-bang 0 - (on-tick add1 1) +(big-bang 1 + ;;(on-tick add1 1) + (on-tick (lambda (w) (* w 2)) 1) ;;(stop-when (lambda (w) (> w 10))) ) diff --git a/js-assembler/runtime-src/baselib-functions.js b/js-assembler/runtime-src/baselib-functions.js index 0970d53..e6961e5 100644 --- a/js-assembler/runtime-src/baselib-functions.js +++ b/js-assembler/runtime-src/baselib-functions.js @@ -138,19 +138,22 @@ // internallCallDuringPause: call a Racket procedure and get its results. // The use assumes the machine is in a running-but-paused state. 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")); } if (isPrimitiveProcedure(proc)) { - var args = []; - for (var i = 4; i < arguments.length; i++) { - args.push(arguments[i]); + var oldArgcount = MACHINE.argcount; + MACHINE.argcount = arguments.length - 4; + for (var i = 0; i < arguments.length - 4; i++) { + MACHINE.env.push(arguments[arguments.length - 1 - i]); } - var result = v.apply(null, args); - succ(result); - } else if (isClosure(v)) { - + var result = proc.call(null, MACHINE); + for (var i = 0; i < arguments.length - 4; i++) { + MACHINE.env.pop(); + } + success(result); + } else if (isClosure(proc)) { var oldVal = MACHINE.val; var oldArgcount = MACHINE.argcount; var oldProc = MACHINE.proc; @@ -163,7 +166,7 @@ MACHINE.val = oldVal; MACHINE.argcount = oldArgcount; MACHINE.proc = oldProc; - succ(returnValue); + success(returnValue); }); }; afterGoodInvoke.multipleValueReturn = function(MACHINE) { @@ -176,17 +179,17 @@ MACHINE.val = oldVal; MACHINE.argcount = oldArgcount; MACHINE.proc = oldProc; - succ.apply(null, returnValues); + success.apply(null, returnValues); }); }; MACHINE.control.push( new plt.baselib.frames.CallFrame(afterGoodInvoke, null)); - MACHINE.argcount = args.length; - for (var i = 0; i < args.length; i++) { - MACHINE.env.push(args[i]); + MACHINE.argcount = arguments.length - 4; + for (var i = 0; i < arguments.length - 4; i++) { + MACHINE.env.push(arguments[arguments.length - 1 - i]); } - MACHINE.proc = v; + MACHINE.proc = proc; MACHINE.params['currentErrorHandler'] = function(MACHINE, e) { MACHINE.params['currentErrorHandler'] = oldErrorHandler; MACHINE.val = oldVal; @@ -194,12 +197,12 @@ MACHINE.proc = oldProc; fail(e); }; - plt.runtime.trampoline(MACHINE, v.label); + plt.runtime.trampoline(MACHINE, proc.label); } else { fail(plt.baselib.exceptions.makeExnFail( plt.baselib.format.format( "Not a procedure: ~e", - v))); + proc))); } }; diff --git a/world/kernel.js b/world/kernel.js index d3bb875..2c96064 100644 --- a/world/kernel.js +++ b/world/kernel.js @@ -157,18 +157,19 @@ var OnTick = function(handler, aDelay) { OnTick.prototype = plt.baselib.heir(WorldConfigOption.prototype); OnTick.prototype.toRawHandler = function(MACHINE) { + var that = this; var worldFunction = function(world, k) { - k(world + 1); -// plt.baselib.functions.internalCallDuringPause( -// MACHINE, -// this.handler, -// function(v) { -// k(v); -// }, + plt.baselib.functions.internalCallDuringPause( + MACHINE, + that.handler, + function(v) { + k(v); + }, -// function(err) { -// console.log(err); -// }); + function(err) { + console.log(err); + }, + world); }; return rawJsworld.on_tick(this.delay, worldFunction); };