From b9e7ae57e6baeb58637f8c21023dc996e3296d30 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 11 Jul 2011 18:48:33 -0400 Subject: [PATCH] chasing initialization bug --- js-assembler/package.rkt | 2 ++ js-assembler/runtime-src/baselib-functions.js | 5 +++ js-assembler/runtime-src/runtime.js | 32 +++++++++++++++---- tests/coersing/Makefile | 5 +++ tests/coersing/fact.rkt | 11 +++++++ tests/coersing/index.html | 28 ++++++++++++++++ 6 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 tests/coersing/Makefile create mode 100644 tests/coersing/fact.rkt create mode 100644 tests/coersing/index.html diff --git a/js-assembler/package.rkt b/js-assembler/package.rkt index 061e330..dd50850 100644 --- a/js-assembler/package.rkt +++ b/js-assembler/package.rkt @@ -225,6 +225,7 @@ MACHINE.modules[~s] = (define (on-last-src) + (fprintf op "console.log('module loaded'); plt.runtime.setReadyTrue();") (fprintf op "SUCCESS();")) @@ -246,6 +247,7 @@ MACHINE.modules[~s] = (fprintf op "var invoke = (function(MACHINE, SUCCESS, FAIL, PARAMS) {") (fprintf op " plt.runtime.ready(function() {") + (fprintf op "console.log('loading module'); plt.runtime.setReadyFalse();") (make (list (make-MainModuleSource source-code)) packaging-configuration) (fprintf op " });"); diff --git a/js-assembler/runtime-src/baselib-functions.js b/js-assembler/runtime-src/baselib-functions.js index f5b6ae2..0607cd8 100644 --- a/js-assembler/runtime-src/baselib-functions.js +++ b/js-assembler/runtime-src/baselib-functions.js @@ -10,6 +10,9 @@ // its argument stack space. // + + + // coerseToJavaScript: racket function -> JavaScript function // Given a closure or primitive, produces an @@ -196,4 +199,6 @@ exports.isFunction = isFunction; + exports.coerseToJavaScript = coerseToJavaScript; + })(this['plt'].baselib); \ No newline at end of file diff --git a/js-assembler/runtime-src/runtime.js b/js-assembler/runtime-src/runtime.js index 53565f5..3471c34 100644 --- a/js-assembler/runtime-src/runtime.js +++ b/js-assembler/runtime-src/runtime.js @@ -1785,25 +1785,33 @@ if(this['plt'] === undefined) { this['plt'] = {}; } (function(scope) { scope.ready = function(f) { + console.log('request'); if (runtimeIsReady) { notifyWaiter(f); } else { readyWaiters.push(f); } }; + scope.setReadyTrue = function() { - var i; + console.log("runtime is ready"); runtimeIsReady = true; - for (i = 0; i < readyWaiters.length; i++) { - notifyWaiter(readyWaiters[i]); + while(runtimeIsReady && readyWaiters.length > 0) { + notifyWaiter(readyWaiters.shift()); } - readyWaiters = []; }; + scope.setReadyFalse = function() { + console.log("disabled runtime"); + runtimeIsReady = false; + }; + + var runtimeIsReady = false; var readyWaiters = []; var notifyWaiter = function(w) { - setTimeout(w, 0); + console.log('notifying waiter'); + w(); }; })(this); @@ -1831,6 +1839,17 @@ if(this['plt'] === undefined) { this['plt'] = {}; } }); }; + // Looks up a name in any of the machine's main modules. + var lookupInMains = function(name, machine) { + machine = machine || runtime.currentMachine; + for (var i = 0; i < machine.mainModules.length; i++) { + var ns = machine.mainModules[i].getNamespace(); + if(ns.hasOwnProperty(name)) { + return ns[name]; + } + } + }; + ////////////////////////////////////////////////////////////////////// @@ -1842,6 +1861,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; } var exports = runtime; exports['currentMachine'] = new Machine(); exports['invokeMains'] = invokeMains; + exports['lookupInMains'] = lookupInMains; // installing new primitives @@ -1854,7 +1874,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; } // Private: the runtime library will set this flag to true when // the library has finished loading. exports['setReadyTrue'] = setReadyTrue; - + exports['setReadyFalse'] = setReadyFalse; exports['Machine'] = Machine; exports['Frame'] = Frame; diff --git a/tests/coersing/Makefile b/tests/coersing/Makefile new file mode 100644 index 0000000..0c1cfb4 --- /dev/null +++ b/tests/coersing/Makefile @@ -0,0 +1,5 @@ +#!/bin/sh + +all: + ../../whalesong get-javascript fact.rkt > fact.js + ../../whalesong get-runtime > runtime.js diff --git a/tests/coersing/fact.rkt b/tests/coersing/fact.rkt new file mode 100644 index 0000000..29be59c --- /dev/null +++ b/tests/coersing/fact.rkt @@ -0,0 +1,11 @@ +#lang planet dyoo/whalesong +(provide fact) +(define (fact x) + (cond + [(= x 0) + 1] + [else + (* x (fact (sub1 x)))])) + + +(printf "fact invoked\n") \ No newline at end of file diff --git a/tests/coersing/index.html b/tests/coersing/index.html new file mode 100644 index 0000000..4a0f480 --- /dev/null +++ b/tests/coersing/index.html @@ -0,0 +1,28 @@ + + + + + + + + + + + + +