From 3a7507bab9deb43d0cd6bbd3f920c80cbd7830a9 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Thu, 15 Mar 2012 16:53:47 -0400 Subject: [PATCH] removing debug messages; adjusting the numeric tower to send errors it sees to the current machine --- js-assembler/runtime-src/baselib-exceptions.js | 18 ++++++++++++------ js-assembler/runtime-src/baselib-numbers.js | 10 ++++++++++ js-assembler/runtime-src/baselib-primitives.js | 3 +++ js-assembler/runtime-src/runtime.js | 11 ----------- js/world/test-geo.rkt | 4 ++-- web-world/js-impl.js | 17 ++--------------- 6 files changed, 29 insertions(+), 34 deletions(-) diff --git a/js-assembler/runtime-src/baselib-exceptions.js b/js-assembler/runtime-src/baselib-exceptions.js index 609e14b..e446c61 100644 --- a/js-assembler/runtime-src/baselib-exceptions.js +++ b/js-assembler/runtime-src/baselib-exceptions.js @@ -69,12 +69,13 @@ e = new RacketError(Exn.accessor(e, 0), e); } - if (window.console !== void(0) && - typeof(window.console.log) === 'function') { - window.console.log(MACHINE); - if (e.stack) { window.console.log(e.stack); } - else { window.console.log(e); } - } + // if (window.console !== void(0) && + // typeof(window.console.log) === 'function') { + // window.console.log(MACHINE); + // if (e.stack) { window.console.log(e.stack); } + // else { window.console.log(e); } + // } + throw e; }; @@ -89,6 +90,10 @@ raise(MACHINE, ExnFailContract.constructor([msg, contMarks])); }; + var raiseDivisionByZeroError = function(MACHINE, msg) { + var contMarks = MACHINE.captureContinuationMarks(); + raise(MACHINE, ExnFailContractDivisionByZero.constructor([msg, contMarks])); + }; var raiseUnboundToplevelError = function(MACHINE, name) { @@ -234,6 +239,7 @@ exceptions.raise = raise; exceptions.raiseFailure = raiseFailure; exceptions.raiseContractError = raiseContractError; + exceptions.raiseDivisionByZeroError = raiseDivisionByZeroError; exceptions.raiseUnboundToplevelError = raiseUnboundToplevelError; exceptions.raiseArgumentTypeError = raiseArgumentTypeError; exceptions.raiseContextExpectedValuesError = raiseContextExpectedValuesError; diff --git a/js-assembler/runtime-src/baselib-numbers.js b/js-assembler/runtime-src/baselib-numbers.js index 949a246..924f8fc 100644 --- a/js-assembler/runtime-src/baselib-numbers.js +++ b/js-assembler/runtime-src/baselib-numbers.js @@ -9,6 +9,16 @@ + // Set the numeric tower to raise errors through our mechanism. + jsnums.onThrowRuntimeError = function(msg, x, y) { + if (msg === '/: division by zero') { + baselib.exceptions.raiseDivisionByZeroError(plt.runtime.currentMachine, msg); + } else { + baselib.exceptions.raiseContractError(plt.runtime.currentMachine, msg); + } + }; + + var isNumber = jsnums.isSchemeNumber; var isReal = jsnums.isReal; var isRational = jsnums.isRational; diff --git a/js-assembler/runtime-src/baselib-primitives.js b/js-assembler/runtime-src/baselib-primitives.js index 2da9a9a..b0cc6fc 100644 --- a/js-assembler/runtime-src/baselib-primitives.js +++ b/js-assembler/runtime-src/baselib-primitives.js @@ -63,9 +63,12 @@ // Exceptions and error handling. var raise = baselib.exceptions.raise; var raiseContractError = baselib.exceptions.raiseContractError; + var raiseDivisionByZeroError = baselib.exceptions.raiseDivisionByZeroError; var raiseArgumentTypeError = baselib.exceptions.raiseArgumentTypeError; var raiseArityMismatchError = baselib.exceptions.raiseArityMismatchError; + + var testArgument = baselib.check.testArgument; var checkOutputPort = baselib.check.checkOutputPort; diff --git a/js-assembler/runtime-src/runtime.js b/js-assembler/runtime-src/runtime.js index 60c2246..e4aa3df 100644 --- a/js-assembler/runtime-src/runtime.js +++ b/js-assembler/runtime-src/runtime.js @@ -197,7 +197,6 @@ this.alreadyReleased = false; if (this.locked === false) { - console.log("lock is clear. Grabbing..."); this.locked = id; onAcquire.call( that, @@ -218,14 +217,12 @@ waiter = that.waiters.shift(); setTimeout( function() { - console.log("trying to re-acquire lock..."); that.acquire(waiter.id, waiter.onAcquire); }, 0); } }); } else { - console.log("lock is currently in play. Need to wait."); this.waiters.push({ id: id, onAcquire: onAcquire } ); } @@ -584,7 +581,6 @@ }); }; var internalCall = function(proc, success, fail) { - console.log("internalCall"); var i; if (restarted) { return; @@ -593,20 +589,15 @@ for (i = 3; i < arguments.length; i++) { args.push(arguments[i]); } - console.log("acquiring lock..."); pauseLock.acquire( void(0), function(release) { var newSuccess = function() { - console.log('newSuccess', arguments, proc, success); success.apply(null, arguments); - console.log("releasing lock..."); release(); }; var newFail = function() { - console.log('newFail', arguments, proc, fail); fail.apply(null, arguments); - console.log("releasing lock..."); release(); }; baselib.functions.internalCallDuringPause.apply( @@ -624,9 +615,7 @@ // General error condition: just exit out // of the trampoline and call the current error handler. that.running = false; - console.log("calling current error handler", that.params.currentErrorHandler); that.params.currentErrorHandler(that, e); - console.log("releasing"); release(); return; } diff --git a/js/world/test-geo.rkt b/js/world/test-geo.rkt index d5605dc..ac593fa 100644 --- a/js/world/test-geo.rkt +++ b/js/world/test-geo.rkt @@ -5,5 +5,5 @@ (big-bang (list 'undefined 'undefined) - (on-geo (lambda (w v lat #;lng) - (list lat #;lng)))) \ No newline at end of file + (on-geo (lambda (w v lat lng) + (list lat lng)))) \ No newline at end of file diff --git a/web-world/js-impl.js b/web-world/js-impl.js index 86ccb79..fd02f2c 100644 --- a/web-world/js-impl.js +++ b/web-world/js-impl.js @@ -1198,7 +1198,6 @@ dispatchEventsInQueue, refreshView; onCleanRestart = function() { - console.log('on clean restart'); running = false; stopEventHandlers( function() { @@ -1211,16 +1210,12 @@ }; onMessyRestart = function(exn) { - console.log('on messy restart'); running = false; - console.log('stopping the event handlers'); stopEventHandlers( function() { - console.log('event handlers stopped'); restart(function(MACHINE) { currentBigBangRecord = oldCurrentBigBangRecord; MACHINE.params.currentOutputPort = oldOutputPort; - console.log('about to raise'); plt.baselib.exceptions.raise(MACHINE, exn); }); }); @@ -1257,7 +1252,6 @@ dispatchEventsInQueue = function(success, fail) { - console.log("dispatchEventsInQueue"); // Apply all the events on the queue, call toDraw, and then stop. // If the world ever satisfies stopWhen, stop immediately and quit. var nextEvent; @@ -1278,7 +1272,6 @@ args = nextEvent.data.slice(0); var onGoodWorldUpdate = function (newWorld) { - console.log("good world update"); world = newWorld; stopWhen(internalCall, world, @@ -1294,29 +1287,23 @@ fail); }; if (isArityMatching(racketWorldCallback.racketArity, 1)) { - console.log("arity match 1"); racketWorldCallback(internalCall, world, onGoodWorldUpdate, fail); } else if (isArityMatching(racketWorldCallback.racketArity, 2)) { - console.log("arity match 2"); racketWorldCallback(internalCall, world, mockView, onGoodWorldUpdate, fail); - } else { //if (isArityMatching(racketWorldCallback.racketArity, 2 + args.length)){ - console.log("arity match 3"); + } else { args = ([internalCall, world, mockView] .concat(args) .concat([onGoodWorldUpdate, fail])); racketWorldCallback.apply(null, args); - }// else { - // fail(makeArityMismatchError(MACHINE, racketWorldCallback, 2+args.length)); - // } + } } else { - console.log("dispatched all events"); dispatchingEvents = false; success(); }