moving some type definitions out of runtime, like frame

This commit is contained in:
Danny Yoo 2011-07-05 18:01:55 -04:00
parent 5149c99a12
commit e20f984e26
7 changed files with 90 additions and 61 deletions

View File

@ -40,6 +40,8 @@
js-numbers.js js-numbers.js
baselib.js baselib.js
baselib-frames.js
baselib-unionfind.js baselib-unionfind.js
baselib-equality.js baselib-equality.js
@ -52,7 +54,7 @@
baselib-symbols.js baselib-symbols.js
baselib-strings.js baselib-strings.js
baselib-bytes.js baselib-bytes.js
baselib-hash.js baselib-hashes.js
baselib-regexps.js baselib-regexps.js
baselib-paths.js baselib-paths.js
baselib-boxes.js baselib-boxes.js

View File

@ -73,7 +73,7 @@
// toWrittenString: Any Hashtable -> String // toWrittenString: Any Hashtable -> String
var toWrittenString = function(x, cache) { var toWrittenString = function(x, cache) {
if (! cache) { if (! cache) {
cache = plt.baselib.hash.makeLowLevelEqHash(); cache = plt.baselib.hashes.makeLowLevelEqHash();
} }
if (x === null) { if (x === null) {
return "null"; return "null";
@ -112,7 +112,7 @@
// toDisplayedString: Any Hashtable -> String // toDisplayedString: Any Hashtable -> String
var toDisplayedString = function(x, cache) { var toDisplayedString = function(x, cache) {
if (! cache) { if (! cache) {
cache = plt.baselib.hash.makeLowLevelEqHash(); cache = plt.baselib.hashes.makeLowLevelEqHash();
} }
if (x === null) { if (x === null) {
return "null"; return "null";
@ -153,7 +153,7 @@
var ToDomNodeParameters = function(params) { var ToDomNodeParameters = function(params) {
if (! params) { params = {}; } if (! params) { params = {}; }
this.cache = plt.baselib.hash.makeLowLevelEqHash(); this.cache = plt.baselib.hashes.makeLowLevelEqHash();
for (var k in params) { for (var k in params) {
if (params.hasOwnProperty(k)) { if (params.hasOwnProperty(k)) {
this[k] = params[k]; this[k] = params[k];

View File

@ -0,0 +1,69 @@
// Frame structures.
(function(baselib) {
var exports = {};
baselib.frames = exports;
// A generic frame just holds marks.
var Frame = function() {
// The set of continuation marks.
this.marks = [];
// When we're in the middle of computing with-cont-mark, we
// stash the key in here temporarily.
this.pendingContinuationMarkKey = undefined;
this.pendingApplyValuesProc = undefined;
this.pendingBegin0Count = undefined;
this.pendingBegin0Values = undefined;
};
// Frames must support marks and the temporary variables necessary to
// support with-continuation-mark and with-values.
// Specialized frames support more features:
// A CallFrame represents a call stack frame, and includes the return address
// as well as the function being called.
var CallFrame = function(label, proc) {
this.label = label;
this.proc = proc;
// The set of continuation marks.
this.marks = [];
// When we're in the middle of computing with-cont-mark, we
// stash the key in here temporarily.
this.pendingContinuationMarkKey = undefined;
};
CallFrame.prototype = baselib.heir(Frame.prototype);
// A prompt frame includes a return address, as well as a prompt tag
// for supporting delimited continuations.
var PromptFrame = function(label, tag) {
this.label = label;
this.tag = tag; // ContinuationPromptTag
// The set of continuation marks.
this.marks = [];
// When we're in the middle of computing with-cont-mark, we
// stash the key in here temporarily.
this.pendingContinuationMarkKey = undefined;
};
PromptFrame.prototype = baselib.heir(Frame.prototype);
//////////////////////////////////////////////////////////////////////
exports.Frame = Frame;
exports.CallFrame = CallFrame;
exports.PromptFrame = PromptFrame;
})(this['plt'].baselib);

View File

@ -2,7 +2,7 @@
(function(baselib) { (function(baselib) {
var exports = {}; var exports = {};
baselib.hash = exports; baselib.hashes = exports;

View File

@ -10,7 +10,7 @@
var UnionFind = function() { var UnionFind = function() {
// this.parenMap holds the arrows from an arbitrary pointer // this.parenMap holds the arrows from an arbitrary pointer
// to its parent. // to its parent.
this.parentMap = baselib.hash.makeLowLevelEqHash(); this.parentMap = baselib.hashes.makeLowLevelEqHash();
} }
// find: ptr -> UnionFindNode // find: ptr -> UnionFindNode

View File

@ -49,6 +49,13 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
var makeBox = plt.baselib.boxes.makeBox; var makeBox = plt.baselib.boxes.makeBox;
var isBox = plt.baselib.boxes.isBox; var isBox = plt.baselib.boxes.isBox;
// Frame structures.
var Frame = plt.baselib.frames.Frame;
var CallFrame = plt.baselib.frames.CallFrame;
var PromptFrame = plt.baselib.frames.PromptFrame;
//////////////////////////////////////////////////////////////////////] //////////////////////////////////////////////////////////////////////]
@ -238,55 +245,6 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
// A generic frame just holds marks.
var Frame = function() {
// The set of continuation marks.
this.marks = [];
// When we're in the middle of computing with-cont-mark, we
// stash the key in here temporarily.
this.pendingContinuationMarkKey = undefined;
this.pendingApplyValuesProc = undefined;
this.pendingBegin0Count = undefined;
this.pendingBegin0Values = undefined;
};
// Frames must support marks and the temporary variables necessary to
// support with-continuation-mark and with-values.
// Specialized frames support more features:
// A CallFrame represents a call stack frame, and includes the return address
// as well as the function being called.
var CallFrame = function(label, proc) {
this.label = label;
this.proc = proc;
// When we're in the middle of computing with-cont-mark, we
// stash the key in here temporarily.
this.pendingContinuationMarkKey = undefined;
// The set of continuation marks.
this.marks = [];
};
CallFrame.prototype = heir(Frame.prototype);
// A prompt frame includes a return address, as well as a prompt tag
// for supporting delimited continuations.
var PromptFrame = function(label, tag) {
this.label = label;
this.tag = tag; // ContinuationPromptTag
// The set of continuation marks.
this.marks = [];
// When we're in the middle of computing with-cont-mark, we
// stash the key in here temporarily.
this.pendingContinuationMarkKey = undefined;
};
PromptFrame.prototype = heir(Frame.prototype);

View File

@ -19,10 +19,10 @@ if (! this['plt']) { this['plt'] = {}; }
var getEqHashCode = plt.baselib.hash.getEqHashCode; var getEqHashCode = plt.baselib.hashes.getEqHashCode;
// makeLowLevelEqHash: -> hashtable // makeLowLevelEqHash: -> hashtable
// Constructs an eq hashtable that uses Moby's getEqHashCode function. // Constructs an eq hashtable that uses Moby's getEqHashCode function.
var makeLowLevelEqHash = plt.baselib.hash.makeLowLevelEqHash; var makeLowLevelEqHash = plt.baselib.hashes.makeLowLevelEqHash;
var toWrittenString = plt.baselib.format.toWrittenString; var toWrittenString = plt.baselib.format.toWrittenString;
var toDisplayedString = plt.baselib.format.toDisplayedString; var toDisplayedString = plt.baselib.format.toDisplayedString;
var toDomNode = plt.baselib.format.toDomNode; var toDomNode = plt.baselib.format.toDomNode;
@ -124,7 +124,7 @@ if (! this['plt']) { this['plt'] = {}; }
var makeHashEq = function(lst) { var makeHashEq = function(lst) {
var newHash = new plt.baselib.hash.EqHashTable(); var newHash = new plt.baselib.hashes.EqHashTable();
while ( !isEmpty(lst) ) { while ( !isEmpty(lst) ) {
newHash.hash.put(lst.first.first, lst.first.rest); newHash.hash.put(lst.first.first, lst.first.rest);
lst = lst.rest; lst = lst.rest;
@ -134,7 +134,7 @@ if (! this['plt']) { this['plt'] = {}; }
var makeHashEqual = function(lst) { var makeHashEqual = function(lst) {
var newHash = new plt.baselib.hash.EqualHashTable(); var newHash = new plt.baselib.hashes.EqualHashTable();
while ( !isEmpty(lst) ) { while ( !isEmpty(lst) ) {
newHash.hash.put(lst.first.first, lst.first.rest); newHash.hash.put(lst.first.first, lst.first.rest);
lst = lst.rest; lst = lst.rest;
@ -470,8 +470,8 @@ if (! this['plt']) { this['plt'] = {}; }
types.isVector = function(x) { return x instanceof Vector; }; types.isVector = function(x) { return x instanceof Vector; };
types.isBox = function(x) { return x instanceof plt.baselib.boxes.Box; }; types.isBox = function(x) { return x instanceof plt.baselib.boxes.Box; };
types.isPlaceholder = function(x) { return x instanceof plt.baselib.placeholders.Placeholder; }; types.isPlaceholder = function(x) { return x instanceof plt.baselib.placeholders.Placeholder; };
types.isHash = function(x) { return (x instanceof plt.baselib.hash.EqHashTable || types.isHash = function(x) { return (x instanceof plt.baselib.hashes.EqHashTable ||
x instanceof plt.baselib.hash.EqualHashTable); }; x instanceof plt.baselib.hashes.EqualHashTable); };
types.isByteString = function(x) { return x instanceof plt.baselib.bytes.Bytes; }; types.isByteString = function(x) { return x instanceof plt.baselib.bytes.Bytes; };
types.isStruct = function(x) { return x instanceof Struct; }; types.isStruct = function(x) { return x instanceof Struct; };
types.isColor = Color.predicate; types.isColor = Color.predicate;