changing function names in the runtime, documenting.

This commit is contained in:
Danny Yoo 2011-06-17 18:36:41 -04:00
parent 280868efa6
commit a90cebd373
3 changed files with 85 additions and 44 deletions

View File

@ -27,7 +27,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
var isPair = types.isPair; var isPair = types.isPair;
var isList = types.isList; var isList = types.isList;
var isVector = types.isVector; var isVector = types.isVector;
var isEqual = types.isEqual; var equals = types.equals;
var NULL = types.EMPTY; var NULL = types.EMPTY;
@ -1180,7 +1180,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
var secondArg = MACHINE.env[MACHINE.env.length-2]; var secondArg = MACHINE.env[MACHINE.env.length-2];
return isEqual(firstArg, secondArg); return equals(firstArg, secondArg);
}); });
@ -1201,7 +1201,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
if (lst === NULL) { if (lst === NULL) {
return false; return false;
} }
if (isEqual(x, (lst.first))) { if (equals(x, (lst.first))) {
return lst; return lst;
} }
lst = lst.rest; lst = lst.rest;
@ -1484,6 +1484,9 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
exports['unspliceRestFromStack'] = unspliceRestFromStack; exports['unspliceRestFromStack'] = unspliceRestFromStack;
//////////////////////////////////////////////////////////////////////
// Type constructors // Type constructors
// numbers // numbers
@ -1500,7 +1503,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
exports['isOutputPort'] = isOutputPort; exports['isOutputPort'] = isOutputPort;
exports['isOutputStringPort'] = isOutputStringPort; exports['isOutputStringPort'] = isOutputStringPort;
exports['isBox'] = isBox; exports['isBox'] = isBox;
exports['isEqual'] = isEqual; exports['equals'] = equals;
exports['toDomNode'] = toDomNode; exports['toDomNode'] = toDomNode;
exports['toWrittenString'] = toWrittenString; exports['toWrittenString'] = toWrittenString;

View File

@ -102,7 +102,7 @@ if (! this['plt']) { this['plt'] = {}; }
return '#<struct-type:' + this.name + '>'; return '#<struct-type:' + this.name + '>';
}; };
StructType.prototype.isEqual = function(other, aUnionFind) { StructType.prototype.equals = function(other, aUnionFind) {
return this === other; return this === other;
}; };
@ -209,7 +209,7 @@ if (! this['plt']) { this['plt'] = {}; }
}; };
Struct.prototype.isEqual = function(other, aUnionFind) { Struct.prototype.equals = function(other, aUnionFind) {
if ( other.type == undefined || if ( other.type == undefined ||
this.type !== other.type || this.type !== other.type ||
!(other instanceof this.type) ) { !(other instanceof this.type) ) {
@ -217,7 +217,7 @@ if (! this['plt']) { this['plt'] = {}; }
} }
for (var i = 0; i < this._fields.length; i++) { for (var i = 0; i < this._fields.length; i++) {
if (! isEqual(this._fields[i], if (! equals(this._fields[i],
other._fields[i], other._fields[i],
aUnionFind)) { aUnionFind)) {
return false; return false;
@ -318,7 +318,7 @@ if (! this['plt']) { this['plt'] = {}; }
}; };
Bytes.prototype.isEqual = function(other) { Bytes.prototype.equals = function(other) {
if (! (other instanceof Bytes)) { if (! (other instanceof Bytes)) {
return false; return false;
} }
@ -424,9 +424,9 @@ if (! this['plt']) { this['plt'] = {}; }
return parent; return parent;
}; };
Box.prototype.isEqual = function(other, aUnionFind) { Box.prototype.equals = function(other, aUnionFind) {
return ((other instanceof Box) && return ((other instanceof Box) &&
isEqual(this.val, other.val, aUnionFind)); equals(this.val, other.val, aUnionFind));
}; };
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -463,9 +463,9 @@ if (! this['plt']) { this['plt'] = {}; }
return parent; return parent;
}; };
Placeholder.prototype.isEqual = function(other, aUnionFind) { Placeholder.prototype.equals = function(other, aUnionFind) {
return ((other instanceof Placeholder) && return ((other instanceof Placeholder) &&
isEqual(this.val, other.val, aUnionFind)); equals(this.val, other.val, aUnionFind));
}; };
@ -540,7 +540,7 @@ if (! this['plt']) { this['plt'] = {}; }
return this.val; return this.val;
}; };
Char.prototype.isEqual = function(other, aUnionFind){ Char.prototype.equals = function(other, aUnionFind){
return other instanceof Char && this.val == other.val; return other instanceof Char && this.val == other.val;
}; };
@ -565,7 +565,7 @@ if (! this['plt']) { this['plt'] = {}; }
return symbolCache[val]; return symbolCache[val];
}; };
Symbol.prototype.isEqual = function(other, aUnionFind) { Symbol.prototype.equals = function(other, aUnionFind) {
return other instanceof Symbol && return other instanceof Symbol &&
this.val == other.val; this.val == other.val;
}; };
@ -603,7 +603,7 @@ if (! this['plt']) { this['plt'] = {}; }
return keywordCache[val]; return keywordCache[val];
}; };
Keyword.prototype.isEqual = function(other, aUnionFind) { Keyword.prototype.equals = function(other, aUnionFind) {
return other instanceof Keyword && return other instanceof Keyword &&
this.val == other.val; this.val == other.val;
}; };
@ -633,7 +633,7 @@ if (! this['plt']) { this['plt'] = {}; }
Empty.EMPTY = new Empty(); Empty.EMPTY = new Empty();
Empty.prototype.isEqual = function(other, aUnionFind) { Empty.prototype.equals = function(other, aUnionFind) {
return other instanceof Empty; return other instanceof Empty;
}; };
@ -694,12 +694,12 @@ if (! this['plt']) { this['plt'] = {}; }
}; };
// FIXME: can we reduce the recursion on this? // FIXME: can we reduce the recursion on this?
Cons.prototype.isEqual = function(other, aUnionFind) { Cons.prototype.equals = function(other, aUnionFind) {
if (! (other instanceof Cons)) { if (! (other instanceof Cons)) {
return false; return false;
} }
return (isEqual(this.first, other.first, aUnionFind) && return (equals(this.first, other.first, aUnionFind) &&
isEqual(this.rest, other.rest, aUnionFind)); equals(this.rest, other.rest, aUnionFind));
}; };
@ -833,13 +833,13 @@ if (! this['plt']) { this['plt'] = {}; }
this.elts[k] = v; this.elts[k] = v;
}; };
Vector.prototype.isEqual = function(other, aUnionFind) { Vector.prototype.equals = function(other, aUnionFind) {
if (other != null && other != undefined && other instanceof Vector) { if (other != null && other != undefined && other instanceof Vector) {
if (other.length() != this.length()) { if (other.length() != this.length()) {
return false return false
} }
for (var i = 0; i < this.length(); i++) { for (var i = 0; i < this.length(); i++) {
if (! isEqual(this.elts[i], other.elts[i], aUnionFind)) { if (! equals(this.elts[i], other.elts[i], aUnionFind)) {
return false; return false;
} }
} }
@ -948,7 +948,7 @@ if (! this['plt']) { this['plt'] = {}; }
} }
Str.prototype.isEqual = function(other, aUnionFind) { Str.prototype.equals = function(other, aUnionFind) {
if ( !(other instanceof Str || typeof(other) == 'string') ) { if ( !(other instanceof Str || typeof(other) == 'string') ) {
return false; return false;
} }
@ -1025,7 +1025,7 @@ String.makeInstance = function(s) {
// WARNING // WARNING
// WARNING: we are extending the built-in Javascript string class here! // WARNING: we are extending the built-in Javascript string class here!
// WARNING // WARNING
String.prototype.isEqual = function(other, aUnionFind){ String.prototype.equals = function(other, aUnionFind){
return this == other; return this == other;
}; };
@ -1083,7 +1083,7 @@ String.prototype.toDisplayedString = function(cache) {
return ('#hasheq(' + ret.join(' ') + ')'); return ('#hasheq(' + ret.join(' ') + ')');
}; };
EqHashTable.prototype.isEqual = function(other, aUnionFind) { EqHashTable.prototype.equals = function(other, aUnionFind) {
if ( !(other instanceof EqHashTable) ) { if ( !(other instanceof EqHashTable) ) {
return false; return false;
} }
@ -1095,7 +1095,7 @@ String.prototype.toDisplayedString = function(cache) {
var keys = this.hash.keys(); var keys = this.hash.keys();
for (var i = 0; i < keys.length; i++){ for (var i = 0; i < keys.length; i++){
if ( !(other.hash.containsKey(keys[i]) && if ( !(other.hash.containsKey(keys[i]) &&
isEqual(this.hash.get(keys[i]), equals(this.hash.get(keys[i]),
other.hash.get(keys[i]), other.hash.get(keys[i]),
aUnionFind)) ) { aUnionFind)) ) {
return false; return false;
@ -1111,7 +1111,7 @@ String.prototype.toDisplayedString = function(cache) {
return toWrittenString(x); return toWrittenString(x);
}, },
function(x, y) { function(x, y) {
return isEqual(x, y, new UnionFind()); return equals(x, y, new UnionFind());
}); });
this.mutable = true; this.mutable = true;
}; };
@ -1139,7 +1139,7 @@ String.prototype.toDisplayedString = function(cache) {
return ('#hash(' + ret.join(' ') + ')'); return ('#hash(' + ret.join(' ') + ')');
}; };
EqualHashTable.prototype.isEqual = function(other, aUnionFind) { EqualHashTable.prototype.equals = function(other, aUnionFind) {
if ( !(other instanceof EqualHashTable) ) { if ( !(other instanceof EqualHashTable) ) {
return false; return false;
} }
@ -1151,7 +1151,7 @@ String.prototype.toDisplayedString = function(cache) {
var keys = this.hash.keys(); var keys = this.hash.keys();
for (var i = 0; i < keys.length; i++){ for (var i = 0; i < keys.length; i++){
if (! (other.hash.containsKey(keys[i]) && if (! (other.hash.containsKey(keys[i]) &&
isEqual(this.hash.get(keys[i]), equals(this.hash.get(keys[i]),
other.hash.get(keys[i]), other.hash.get(keys[i]),
aUnionFind))) { aUnionFind))) {
return false; return false;
@ -1176,7 +1176,7 @@ String.prototype.toDisplayedString = function(cache) {
return toDomNode(this.val, cache); return toDomNode(this.val, cache);
}; };
JsValue.prototype.isEqual = function(other, aUnionFind) { JsValue.prototype.equals = function(other, aUnionFind) {
return (this.val === other.val); return (this.val === other.val);
}; };
@ -1216,11 +1216,11 @@ String.prototype.toDisplayedString = function(cache) {
return '#<world-config>'; return '#<world-config>';
}; };
WorldConfig.prototype.isEqual = function(other, aUnionFind) { WorldConfig.prototype.equals = function(other, aUnionFind) {
return ( isEqual(this.startup, other.startup, aUnionFind) && return ( equals(this.startup, other.startup, aUnionFind) &&
isEqual(this.shutdown, other.shutdown, aUnionFind) && equals(this.shutdown, other.shutdown, aUnionFind) &&
isEqual(this.shutdownArg, other.shutdownArg, aUnionFind) && equals(this.shutdownArg, other.shutdownArg, aUnionFind) &&
isEqual(this.restartArg, other.restartArg, aUnionFind) ); equals(this.restartArg, other.restartArg, aUnionFind) );
}; };
@ -1333,9 +1333,9 @@ String.prototype.toDisplayedString = function(cache) {
} }
// isEqual: X Y -> boolean // equals: X Y -> boolean
// Returns true if the objects are equivalent; otherwise, returns false. // Returns true if the objects are equivalent; otherwise, returns false.
var isEqual = function(x, y, aUnionFind) { var equals = function(x, y, aUnionFind) {
if (x === y) { return true; } if (x === y) { return true; }
if (isNumber(x) && isNumber(y)) { if (isNumber(x) && isNumber(y)) {
@ -1352,8 +1352,8 @@ String.prototype.toDisplayedString = function(cache) {
if ( typeof(x) == 'object' && if ( typeof(x) == 'object' &&
typeof(y) == 'object' && typeof(y) == 'object' &&
x.isEqual && x.equals &&
y.isEqual) { y.equals) {
if (typeof (aUnionFind) === 'undefined') { if (typeof (aUnionFind) === 'undefined') {
aUnionFind = new UnionFind(); aUnionFind = new UnionFind();
@ -1364,7 +1364,7 @@ String.prototype.toDisplayedString = function(cache) {
} }
else { else {
aUnionFind.merge(x, y); aUnionFind.merge(x, y);
return x.isEqual(y, aUnionFind); return x.equals(y, aUnionFind);
} }
} }
return false; return false;
@ -1384,7 +1384,7 @@ String.prototype.toDisplayedString = function(cache) {
var lifted = function(args) { var lifted = function(args) {
return primitiveF.apply(null, args.slice(0, minArity).concat([args.slice(minArity)])); return primitiveF.apply(null, args.slice(0, minArity).concat([args.slice(minArity)]));
}; };
lifted.isEqual = function(other, cache) { lifted.equals = function(other, cache) {
return this === other; return this === other;
} }
lifted.toWrittenString = function(cache) { lifted.toWrittenString = function(cache) {
@ -1429,7 +1429,7 @@ String.prototype.toDisplayedString = function(cache) {
return parent; return parent;
}; };
ValuesWrapper.prototype.isEqual = function(other, aUnionFind) { ValuesWrapper.prototype.equals = function(other, aUnionFind) {
if (! other instanceof ValuesWrapper) { if (! other instanceof ValuesWrapper) {
return false; return false;
} }
@ -1437,7 +1437,7 @@ String.prototype.toDisplayedString = function(cache) {
return false; return false;
} }
for (var i = 0; i < this.elts.length; i++) { for (var i = 0; i < this.elts.length; i++) {
if (! isEqual(this.elts[i], other.elts[i], aUnionFind)) { if (! equals(this.elts[i], other.elts[i], aUnionFind)) {
return false; return false;
} }
} }
@ -2096,7 +2096,7 @@ String.prototype.toDisplayedString = function(cache) {
types.TRUE = true; types.TRUE = true;
types.EMPTY = Empty.EMPTY; types.EMPTY = Empty.EMPTY;
types.isEqual = isEqual; types.equals = equals;
types.isNumber = isNumber; types.isNumber = isNumber;
types.isReal = jsnums.isReal; types.isReal = jsnums.isReal;

View File

@ -370,10 +370,23 @@ other hand, have full access to the machine, but they are responsible
for calling the continuation and popping off their arguments when for calling the continuation and popping off their arguments when
they're finished. they're finished.
@;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@subsection{Types} @subsection{Values}
@;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
All values should support the following functions
@itemlist[
@item{plt.runtime.toDomNode(x, mode): produces a dom representation. mode can be either 'write', 'display', or 'print'}
@item{plt.runtime.equals(x, y): tests if two values are equal to each other}
]
@ -428,10 +441,35 @@ time of this writing, it does NOT check for cycles.
@subsection{Vectors}
Vectors can be constructed with @{plt.runtime.makeVector(x ...)}, which takes
in any number of arguments. They can be tested with @tt{plt.runtime.isVector},
and support the following methods and attributes:
@itemlist[
@item{ref(n): get the nth element}
@item{set(n, v): set the nth element with value v}
@item{length: the length of the vector }]
@subsection{Strings} @subsection{Strings}
Immutable strings are represented as regular JavaScript strings. Immutable strings are represented as regular JavaScript strings.
Mutable strings haven't been mapped yet.
@subsection{VOID}
The distinguished void value is @tt{plt.runtime.VOID}; functions
implemented in JavaScript that don't have a useful return value should
return @tt{plt.runtime.VOID}.
@subsection{Undefined}
The undefined values is