the runtime includes the libraries from Moby, although they do not use them yet.
This commit is contained in:
parent
61fa1f691e
commit
0add763beb
12
NOTES
12
NOTES
|
@ -657,3 +657,15 @@ Other things to consider:
|
|||
restrictions.
|
||||
|
||||
Can resources be input-port sources?
|
||||
|
||||
|
||||
----------------------------------------------------------------------
|
||||
|
||||
I've at least imported the libraries from Moby so that they're loaded
|
||||
in the same runtime. However, there are some ugly things happening
|
||||
here: for some reason, there's a circular dependency between types and
|
||||
helpers. That dependency needs to be cut! I've added a workaround
|
||||
for now, using the link library to delay initialization until the
|
||||
modules are present, but this is an unsatisfactory solution. We
|
||||
really shouldn't get into this problem in the first place... I must
|
||||
do a lot of code cleanup once things stabilize...
|
|
@ -1,6 +1,23 @@
|
|||
#lang racket/base
|
||||
|
||||
;; Function to get the runtime library.
|
||||
;;
|
||||
;; The resulting Javascript will produce a file that loads:
|
||||
;;
|
||||
;;
|
||||
;; jquery at the the toplevel
|
||||
;; HashTable at the toplevel
|
||||
;; jsnums at the toplevel
|
||||
;;
|
||||
;; followed by:
|
||||
;;
|
||||
;; plt.link
|
||||
;; plt.helpers
|
||||
;; plt.types
|
||||
;; plt.primitives
|
||||
;; plt.runtime
|
||||
|
||||
|
||||
|
||||
(require racket/contract
|
||||
racket/runtime-path
|
||||
|
@ -10,7 +27,27 @@
|
|||
(provide/contract [get-runtime (-> string?)])
|
||||
|
||||
(define-runtime-path jquery.js "runtime-src/jquery-1.6.1.min.js")
|
||||
(define-runtime-path runtime.js "mini-runtime.js")
|
||||
(define-runtime-path hashtable.js "runtime-src/jshashtable-2.1_src.js")
|
||||
(define-runtime-path jsnums.js "runtime-src/js-numbers.js")
|
||||
(define-runtime-path link.js "runtime-src/link.js")
|
||||
(define-runtime-path helpers.js "runtime-src/helpers.js")
|
||||
(define-runtime-path types.js "runtime-src/types.js")
|
||||
(define-runtime-path primitives.js "runtime-src/primitives.js")
|
||||
(define-runtime-path runtime.js "runtime-src/runtime.js")
|
||||
|
||||
|
||||
;; The order matters here. link needs to come near the top, because
|
||||
;; the other modules below have some circular dependencies that are resolved
|
||||
;; by link.
|
||||
(define files (list jquery.js
|
||||
hashtable.js
|
||||
jsnums.js
|
||||
link.js
|
||||
helpers.js
|
||||
types.js
|
||||
primitives.js
|
||||
runtime.js))
|
||||
|
||||
|
||||
|
||||
(define (path->string p)
|
||||
|
@ -19,11 +56,8 @@
|
|||
(port->string ip))))
|
||||
|
||||
|
||||
(define text (string-append
|
||||
(path->string jquery.js)
|
||||
(path->string runtime.js)))
|
||||
|
||||
|
||||
(define text (apply string-append
|
||||
(map path->string files)))
|
||||
|
||||
|
||||
(define (get-runtime)
|
||||
|
|
|
@ -1,11 +1,32 @@
|
|||
if (! this['plt']) { this['plt'] = {}; }
|
||||
|
||||
// Helpers library: includes a bunch of helper functions that will be used
|
||||
//
|
||||
//
|
||||
// FIXME: there's a circularity between this module and types, and that circularly
|
||||
// should not be there!
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
// File of helper functions for primitives and world.
|
||||
|
||||
var helpers = {};
|
||||
|
||||
(function() {
|
||||
(function(scope) {
|
||||
var helpers = {};
|
||||
scope.helpers = helpers;
|
||||
|
||||
|
||||
// types refers to plt.types, and will be initialized later.
|
||||
var types = scope['types'];
|
||||
scope.link.ready('types',
|
||||
function() {
|
||||
types = scope['types'];
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var format = function(formatStr, args, functionName) {
|
||||
var throwFormatError = function() {
|
||||
|
@ -581,7 +602,10 @@ var helpers = {};
|
|||
|
||||
helpers.heir = heir;
|
||||
|
||||
})();
|
||||
|
||||
|
||||
|
||||
scope.link.announceReady('helpers');
|
||||
})(this['plt']);
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
56
js-assembler/runtime-src/link.js
Normal file
56
js-assembler/runtime-src/link.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Lightweight linking of the modules.
|
||||
// There are circular dependencies across the modules unfortunately, so we
|
||||
// need a mechanism for letting them link to each other.
|
||||
if (! this['plt']) { this['plt'] = {}; }
|
||||
(function(scope) {
|
||||
var link = {};
|
||||
scope['link'] = link;
|
||||
|
||||
|
||||
// link.ready: (string (string -> void)) -> void
|
||||
// When the name announces that it's ready, calls the function f.
|
||||
link.ready = function(name, f) {
|
||||
readyWaiters[name] = readyWaiters[name] || [];
|
||||
readyWaiters[name].push(f);
|
||||
|
||||
if (linkIsReady[name]) {
|
||||
notifySingle(f, name);
|
||||
}
|
||||
};
|
||||
|
||||
// link.announceReady: string -> void
|
||||
// Lets the world know that the name is ready.
|
||||
link.announceReady = function(name) {
|
||||
var i;
|
||||
linkIsReady[name] = true;
|
||||
notifyAll(name);
|
||||
};
|
||||
|
||||
|
||||
|
||||
// notifyAll: string -> void
|
||||
// Tell all listeners that the name is ready.
|
||||
var notifyAll = function(name) {
|
||||
var waiters = readyWaiters[name] || [], i;
|
||||
for (i = 0 ; i < waiters.length; i++) {
|
||||
notifySingle(waiters[i], name);
|
||||
}
|
||||
readyWaiters[name] = [];
|
||||
};
|
||||
|
||||
|
||||
// Tell a single listener that the name is ready.
|
||||
var notifySingle = function(f, name) {
|
||||
setTimeout(function() { f(name); },
|
||||
0);
|
||||
};
|
||||
|
||||
|
||||
// linkIsReady: (Hashtable String Boolean)
|
||||
var linkIsReady = {};
|
||||
|
||||
// readyWaiters: (Hashtable String (Arrayof (String -> Void)))
|
||||
var readyWaiters = {};
|
||||
|
||||
|
||||
})(this['plt']);
|
|
@ -1,4 +1,5 @@
|
|||
var primitive = {};
|
||||
if (! this['plt']) { this['plt'] = {}; }
|
||||
|
||||
|
||||
/**
|
||||
|
||||
|
@ -13,26 +14,59 @@ That way, we can do a simple grep.
|
|||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
var CALL = types.internalCall;
|
||||
|
||||
var PAUSE = types.internalPause;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(function(scope) {
|
||||
var primitives = {};
|
||||
scope.primitives = primitives;
|
||||
var PRIMITIVES = {};
|
||||
|
||||
var PrimProc = types.PrimProc;
|
||||
var CasePrimitive = types.CasePrimitive;
|
||||
var makeOptionPrimitive = types.makeOptionPrimitive;
|
||||
|
||||
var types = scope.types;
|
||||
var helpers = scope.helpers;
|
||||
|
||||
var CALL, PAUSE, PrimProc, CasePrimitive, makeOptionPrimitive, procArityContains;
|
||||
var assocListToHash, raise;
|
||||
var isList, isListOf;
|
||||
var check;
|
||||
var checkListOf;
|
||||
|
||||
CALL = types.internalCall;
|
||||
PAUSE = types.internalPause;
|
||||
PrimProc = types.PrimProc;
|
||||
CasePrimitive = types.CasePrimitive;
|
||||
makeOptionPrimitive = types.makeOptionPrimitive;
|
||||
|
||||
procArityContains = helpers.procArityContains;
|
||||
assocListToHash = helpers.assocListToHash;
|
||||
raise = helpers.raise;
|
||||
isList = helpers.isList;
|
||||
isListOf = helpers.isListOf;
|
||||
check = helpers.check;
|
||||
checkListOf = helpers.checkListOf;
|
||||
|
||||
scope.link.ready('types',
|
||||
function() {
|
||||
types = scope.types;
|
||||
CALL = types.internalCall;
|
||||
PAUSE = types.internalPause;
|
||||
PrimProc = types.PrimProc;
|
||||
CasePrimitive = types.CasePrimitive;
|
||||
makeOptionPrimitive = types.makeOptionPrimitive;
|
||||
});
|
||||
scope.link.ready('helpers',
|
||||
function() {
|
||||
helpers = scope.helpers;
|
||||
procArityContains = helpers.procArityContains;
|
||||
assocListToHash = helpers.assocListToHash;
|
||||
raise = helpers.raise;
|
||||
isList = helpers.isList;
|
||||
isListOf = helpers.isListOf;
|
||||
check = helpers.check;
|
||||
checkListOf = helpers.checkListOf;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -153,7 +187,6 @@ var normalizeArity = function(arity) {
|
|||
};
|
||||
|
||||
|
||||
var procArityContains = helpers.procArityContains;
|
||||
|
||||
|
||||
|
||||
|
@ -295,10 +328,6 @@ var isImmutable = function(x) {
|
|||
|
||||
|
||||
|
||||
var assocListToHash = helpers.assocListToHash;
|
||||
|
||||
var raise = helpers.raise;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -421,9 +450,6 @@ var isChar = types.isChar;
|
|||
var isString = types.isString;
|
||||
var isPair = types.isPair;
|
||||
var isEmpty = function(x) { return x === types.EMPTY; };
|
||||
var isList = helpers.isList;
|
||||
var isListOf = helpers.isListOf;
|
||||
|
||||
var isVector = types.isVector;
|
||||
var isBox = types.isBox;
|
||||
var isHash = types.isHash;
|
||||
|
@ -487,8 +513,6 @@ var arrayEach = function(arr, f) {
|
|||
}
|
||||
}
|
||||
|
||||
//var throwCheckError = helpers.throwCheckError;
|
||||
var check = helpers.check;
|
||||
|
||||
var checkList = function(x, functionName, position, args) {
|
||||
if ( !isList(x) ) {
|
||||
|
@ -501,8 +525,6 @@ var checkList = function(x, functionName, position, args) {
|
|||
}
|
||||
}
|
||||
|
||||
var checkListOf = helpers.checkListOf;
|
||||
|
||||
var checkListOfLength = function(lst, n, functionName, position, args) {
|
||||
if ( !isList(lst) || (length(lst) < n) ) {
|
||||
helpers.throwCheckError([functionName,
|
||||
|
@ -4636,10 +4658,10 @@ PARAMZ['exception-handler-key'] = types.exceptionHandlerKey;
|
|||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////
|
||||
|
||||
// getPrimitive: string (string | undefined) -> scheme-value
|
||||
primitive.getPrimitive = function(name, resolvedModuleName) {
|
||||
primitives.getPrimitive = function(name, resolvedModuleName) {
|
||||
if (resolvedModuleName === undefined) {
|
||||
return PRIMITIVES[name];
|
||||
}
|
||||
|
@ -4666,7 +4688,7 @@ primitive.getPrimitive = function(name, resolvedModuleName) {
|
|||
return PRIMITIVES[name];
|
||||
};
|
||||
|
||||
primitive.isPrimitive = function(x) {
|
||||
primitives.isPrimitive = function(x) {
|
||||
return x instanceof PrimProc;
|
||||
};
|
||||
|
||||
|
@ -4674,5 +4696,6 @@ primitive.isPrimitive = function(x) {
|
|||
|
||||
|
||||
|
||||
})();
|
||||
scope.link.announceReady('primitives');
|
||||
})(this['plt']);
|
||||
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
if(this['plt'] === undefined) {
|
||||
this['plt'] = {};
|
||||
}
|
||||
|
||||
if(this['plt'] === undefined) { this['plt'] = {}; }
|
||||
|
||||
// All of the values here are namespaced under "plt.runtime".
|
||||
|
||||
(function() {
|
||||
this['plt']['runtime'] = {};
|
||||
var exports = this['plt']['runtime'];
|
||||
(function(scope) {
|
||||
var runtime = {};
|
||||
scope['runtime'] = runtime;
|
||||
|
||||
|
||||
|
||||
|
@ -1343,8 +1340,8 @@
|
|||
|
||||
// Executes all programs that have been labeled as a main module
|
||||
var invokeMains = function(machine, succ, fail) {
|
||||
plt.runtime.ready(function() {
|
||||
machine = machine || plt.runtime.currentMachine;
|
||||
runtime.ready(function() {
|
||||
machine = machine || runtime.currentMachine;
|
||||
succ = succ || function() {};
|
||||
fail = fail || function() {};
|
||||
var mainModules = machine.mainModules.slice();
|
||||
|
@ -1368,7 +1365,7 @@
|
|||
|
||||
|
||||
// Exports
|
||||
|
||||
var exports = runtime;
|
||||
exports['currentMachine'] = new Machine();
|
||||
exports['invokeMains'] = invokeMains;
|
||||
|
||||
|
@ -1433,4 +1430,6 @@
|
|||
|
||||
exports['HaltError'] = HaltError;
|
||||
|
||||
}).call(this);
|
||||
|
||||
scope.link.announceReady('runtime');
|
||||
})(this['plt']);
|
|
@ -1,15 +1,30 @@
|
|||
if (! this['plt']) { this['plt'] = {}; }
|
||||
|
||||
// FIXME: there's a circularity between this module and helpers, and that circularly
|
||||
// should not be there!
|
||||
|
||||
|
||||
(function (scope) {
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// helper functions
|
||||
|
||||
//var jsnums = require('./js-numbers');
|
||||
|
||||
|
||||
var types = {};
|
||||
scope['types'] = types;
|
||||
|
||||
|
||||
(function () {
|
||||
// helpers refers to plt.helpers.
|
||||
var helpers = scope['helpers'];
|
||||
|
||||
|
||||
var getEqHashCode, makeLowLevelEqHash;
|
||||
// makeLowLevelEqHash: -> hashtable
|
||||
// Constructs an eq hashtable that uses Moby's getEqHashCode function.
|
||||
var makeLowLevelEqHash;
|
||||
|
||||
scope.link.ready('helpers', function() {
|
||||
helpers = scope['helpers'];
|
||||
getEqHashCode = helpers.getEqHashCode;
|
||||
makeLowLevelEqHash = helpers.makeLowLevelEqHash;
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
var appendChild = function(parent, child) {
|
||||
|
@ -21,7 +36,7 @@ var appendChild = function(parent, child) {
|
|||
|
||||
|
||||
|
||||
getEqHashCode = helpers.getEqHashCode;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1075,10 +1090,6 @@ String.prototype.toDisplayedString = function(cache) {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// makeLowLevelEqHash: -> hashtable
|
||||
// Constructs an eq hashtable that uses Moby's getEqHashCode function.
|
||||
var makeLowLevelEqHash = helpers.makeLowLevelEqHash;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -2528,5 +2539,7 @@ types.isRenderEffect = RenderEffect.predicate;
|
|||
|
||||
types.readerGraph = readerGraph;
|
||||
|
||||
})();
|
||||
|
||||
scope.link.announceReady('types');
|
||||
})(this['plt']);
|
||||
|
||||
|
|
|
@ -213,9 +213,15 @@ var comet = function() {
|
|||
sendRequest("/eval",
|
||||
function(req) {
|
||||
// debug:
|
||||
if (window.console && typeof(console.log) === 'function') { console.log(req.responseText); }
|
||||
|
||||
//if (window.console && typeof(console.log) === 'function') {
|
||||
// console.log(req.responseText);
|
||||
//}
|
||||
try {
|
||||
var invoke = eval(req.responseText)();
|
||||
} catch (e) {
|
||||
if (window.console && window.console.log && e.stack) { window.console.log(e.stack); }
|
||||
throw e;
|
||||
}
|
||||
var output = [];
|
||||
var startTime, endTime;
|
||||
var params = { currentDisplayer: function(v) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user