chasing initialization bug
This commit is contained in:
parent
bf2213d2b4
commit
b9e7ae57e6
|
@ -225,6 +225,7 @@ MACHINE.modules[~s] =
|
||||||
|
|
||||||
|
|
||||||
(define (on-last-src)
|
(define (on-last-src)
|
||||||
|
(fprintf op "console.log('module loaded'); plt.runtime.setReadyTrue();")
|
||||||
(fprintf op "SUCCESS();"))
|
(fprintf op "SUCCESS();"))
|
||||||
|
|
||||||
|
|
||||||
|
@ -246,6 +247,7 @@ MACHINE.modules[~s] =
|
||||||
|
|
||||||
(fprintf op "var invoke = (function(MACHINE, SUCCESS, FAIL, PARAMS) {")
|
(fprintf op "var invoke = (function(MACHINE, SUCCESS, FAIL, PARAMS) {")
|
||||||
(fprintf op " plt.runtime.ready(function() {")
|
(fprintf op " plt.runtime.ready(function() {")
|
||||||
|
(fprintf op "console.log('loading module'); plt.runtime.setReadyFalse();")
|
||||||
(make (list (make-MainModuleSource source-code))
|
(make (list (make-MainModuleSource source-code))
|
||||||
packaging-configuration)
|
packaging-configuration)
|
||||||
(fprintf op " });");
|
(fprintf op " });");
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
// its argument stack space.
|
// its argument stack space.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// coerseToJavaScript: racket function -> JavaScript function
|
// coerseToJavaScript: racket function -> JavaScript function
|
||||||
// Given a closure or primitive, produces an
|
// Given a closure or primitive, produces an
|
||||||
|
@ -196,4 +199,6 @@
|
||||||
|
|
||||||
exports.isFunction = isFunction;
|
exports.isFunction = isFunction;
|
||||||
|
|
||||||
|
exports.coerseToJavaScript = coerseToJavaScript;
|
||||||
|
|
||||||
})(this['plt'].baselib);
|
})(this['plt'].baselib);
|
|
@ -1785,25 +1785,33 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
|
|
||||||
(function(scope) {
|
(function(scope) {
|
||||||
scope.ready = function(f) {
|
scope.ready = function(f) {
|
||||||
|
console.log('request');
|
||||||
if (runtimeIsReady) {
|
if (runtimeIsReady) {
|
||||||
notifyWaiter(f);
|
notifyWaiter(f);
|
||||||
} else {
|
} else {
|
||||||
readyWaiters.push(f);
|
readyWaiters.push(f);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
scope.setReadyTrue = function() {
|
scope.setReadyTrue = function() {
|
||||||
var i;
|
console.log("runtime is ready");
|
||||||
runtimeIsReady = true;
|
runtimeIsReady = true;
|
||||||
for (i = 0; i < readyWaiters.length; i++) {
|
while(runtimeIsReady && readyWaiters.length > 0) {
|
||||||
notifyWaiter(readyWaiters[i]);
|
notifyWaiter(readyWaiters.shift());
|
||||||
}
|
}
|
||||||
readyWaiters = [];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
scope.setReadyFalse = function() {
|
||||||
|
console.log("disabled runtime");
|
||||||
|
runtimeIsReady = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var runtimeIsReady = false;
|
var runtimeIsReady = false;
|
||||||
var readyWaiters = [];
|
var readyWaiters = [];
|
||||||
var notifyWaiter = function(w) {
|
var notifyWaiter = function(w) {
|
||||||
setTimeout(w, 0);
|
console.log('notifying waiter');
|
||||||
|
w();
|
||||||
};
|
};
|
||||||
})(this);
|
})(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;
|
var exports = runtime;
|
||||||
exports['currentMachine'] = new Machine();
|
exports['currentMachine'] = new Machine();
|
||||||
exports['invokeMains'] = invokeMains;
|
exports['invokeMains'] = invokeMains;
|
||||||
|
exports['lookupInMains'] = lookupInMains;
|
||||||
|
|
||||||
|
|
||||||
// installing new primitives
|
// installing new primitives
|
||||||
|
@ -1854,7 +1874,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||||
// Private: the runtime library will set this flag to true when
|
// Private: the runtime library will set this flag to true when
|
||||||
// the library has finished loading.
|
// the library has finished loading.
|
||||||
exports['setReadyTrue'] = setReadyTrue;
|
exports['setReadyTrue'] = setReadyTrue;
|
||||||
|
exports['setReadyFalse'] = setReadyFalse;
|
||||||
|
|
||||||
exports['Machine'] = Machine;
|
exports['Machine'] = Machine;
|
||||||
exports['Frame'] = Frame;
|
exports['Frame'] = Frame;
|
||||||
|
|
5
tests/coersing/Makefile
Normal file
5
tests/coersing/Makefile
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
all:
|
||||||
|
../../whalesong get-javascript fact.rkt > fact.js
|
||||||
|
../../whalesong get-runtime > runtime.js
|
11
tests/coersing/fact.rkt
Normal file
11
tests/coersing/fact.rkt
Normal file
|
@ -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")
|
28
tests/coersing/index.html
Normal file
28
tests/coersing/index.html
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<script src="runtime.js"></script>
|
||||||
|
<script src="fact.js"></script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
plt.runtime.invokeMains();
|
||||||
|
|
||||||
|
plt.runtime.ready(function() {
|
||||||
|
var myFact = plt.runtime.lookupInMains('fact');
|
||||||
|
myFact(function(v) {
|
||||||
|
alert(v.toString());
|
||||||
|
},
|
||||||
|
function(err) {
|
||||||
|
alert(err);
|
||||||
|
},
|
||||||
|
1000);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user