From 061ea53805679e89c97568b950771fc558d034e7 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 18 Jul 2011 10:53:23 -0400 Subject: [PATCH] Changing the coersion example so it can show difference between computing the value and printing it out. --- examples/counting-world-program.rkt | 4 +- js-assembler/runtime-src/baselib-functions.js | 53 +++++++++---------- tests/coersing/index.html | 3 +- world/kernel.js | 2 - 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/examples/counting-world-program.rkt b/examples/counting-world-program.rkt index 47c3fcc..91cb7aa 100644 --- a/examples/counting-world-program.rkt +++ b/examples/counting-world-program.rkt @@ -9,8 +9,8 @@ handler "big bang should follow:" (big-bang 1 - ;;(on-tick add1 1) - (on-tick (lambda (w) (* w 2)) 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 e6961e5..d1bd773 100644 --- a/js-assembler/runtime-src/baselib-functions.js +++ b/js-assembler/runtime-src/baselib-functions.js @@ -44,9 +44,11 @@ try { succ = succ || function(){}; fail = fail || function(){}; - var args = []; - for (var i = 2; i < arguments.length; i++) { - args.push(arguments[i]); + + var oldArgcount = MACHINE.argcount; + MACHINE.argcount = arguments.length - 2; + for (var i = 0; i < arguments.length - 2; i++) { + MACHINE.env.push(arguments[arguments.length - 1 - i]); } // Check arity usage. @@ -55,6 +57,10 @@ } var result = v.apply(null, args); + MACHINE.argcount = oldArgcount; + for (var i = 0; i < arguments.length - 2; i++) { + MACHINE.env.pop(); + } succ(result); } catch (e) { fail(e); @@ -68,13 +74,8 @@ succ = succ || function(){}; fail = fail || function(){}; - var args = [], i; - for (i = 2; i < arguments.length; i++) { - args.push(arguments[i]); - } - // Check arity usage. - if (! plt.baselib.arity.isArityMatching(v.arity, args.length)) { + if (! plt.baselib.arity.isArityMatching(v.arity, arguments.length - 2)) { throw new Error("arity mismatch"); } @@ -110,25 +111,21 @@ }); }; - setTimeout( - function() { - 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.proc = v; - MACHINE.params['currentErrorHandler'] = function(MACHINE, e) { - MACHINE.params['currentErrorHandler'] = oldErrorHandler; - MACHINE.val = oldVal; - MACHINE.argcount = oldArgcount; - MACHINE.proc = oldProc; - fail(e); - }; - plt.runtime.trampoline(MACHINE, v.label); - }, - 0); + MACHINE.control.push( + new plt.baselib.frames.CallFrame(afterGoodInvoke, null)); + MACHINE.argcount = arguments.length - 2; + for (var i = 0; i < arguments.length - 2; i++) { + MACHINE.env.push(arguments[arguments.length - 1 - i]); + } + MACHINE.proc = v; + MACHINE.params['currentErrorHandler'] = function(MACHINE, e) { + MACHINE.params['currentErrorHandler'] = oldErrorHandler; + MACHINE.val = oldVal; + MACHINE.argcount = oldArgcount; + MACHINE.proc = oldProc; + fail(e); + }; + plt.runtime.trampoline(MACHINE, v.label); }; return f; }; diff --git a/tests/coersing/index.html b/tests/coersing/index.html index b873231..9e9559f 100644 --- a/tests/coersing/index.html +++ b/tests/coersing/index.html @@ -13,7 +13,8 @@ plt.runtime.ready(function() { myFactClosure); myFact(function(v) { - $('#answer').text(v.toString()); + $('#answer').text('computed. Printing...'); + setTimeout(function() { $('#answer').text(v.toString()); }, 0); }, function(err) { $('#answer').text(err.message).css("color", "red"); diff --git a/world/kernel.js b/world/kernel.js index 2c96064..4937ec3 100644 --- a/world/kernel.js +++ b/world/kernel.js @@ -191,7 +191,6 @@ OnDraw.prototype = plt.baselib.heir(WorldConfigOption.prototype); OnDraw.prototype.toRawHandler = function(MACHINE) { var worldFunction = function(world, k) { - console.log('about to call the on-draw'); // FIXME: call the handler instead! k(plt.baselib.format.toDomNode(world)); }; @@ -213,7 +212,6 @@ DefaultOnDraw.prototype = plt.baselib.heir(WorldConfigOption.prototype); DefaultOnDraw.prototype.toRawHandler = function(MACHINE) { var that = this; var worldFunction = function(world, k) { - console.log(rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world))); k([that.toplevelNode, rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world))]); };