in the middle of fixing the type checks on primitives'

This commit is contained in:
Danny Yoo 2011-07-10 20:21:03 -04:00
parent dbdde36997
commit 1a7e66d3fe
4 changed files with 279 additions and 598 deletions

View File

@ -19,6 +19,7 @@
};
// testArgument: (X -> boolean) X number string string -> boolean
// Produces true if val is true, and otherwise raises an error.
var testArgument = function(MACHINE,
@ -51,11 +52,61 @@
var checkOutputPort = makeCheckArgumentType(
plt.baselib.ports.isOutputPort,
'output port');
var checkString = makeCheckArgumentType(
plt.baselib.strings.isString,
'string');
var checkFunction = makeCheckArgumentType(
plt.baselib.functions.isFunction,
'function');
var checkNumber = makeCheckArgumentType(
plt.baselib.numbers.isNumber,
'number');
var checkReal = makeCheckArgumentType(
plt.baselib.numbers.isReal,
'real');
var checkNatural = makeCheckArgumentType(
plt.baselib.numbers.isNatural,
'natural');
var checkInteger = makeCheckArgumentType(
plt.baselib.numbers.isInteger,
'integer');
var checkRational = makeCheckArgumentType(
plt.baselib.numbers.isRational,
'rational');
var checkNonNegativeReal = makeCheckArgumentType(
plt.baselib.numbers.isNonNegativeReal,
'non-negative real');
var checkPair = makeCheckArgumentType(
plt.baselib.lists.isPair,
'pair');
var checkList = makeCheckArgumentType(
plt.baselib.lists.isList,
'list');
var checkVector = makeCheckArgumentType(
plt.baselib.vectors.isVector,
'vector');
var checkBox = makeCheckArgumentType(
plt.baselib.boxes.isBox,
'box');
var checkMutableBox = makeCheckArgumentType(
plt.baselib.boxes.isMutableBox,
'mutable box');
//var checkOutputPort = makeCheckArgumentType()
@ -67,8 +118,20 @@
exports.testArity = testArity;
exports.makeCheckArgumentType = makeCheckArgumentType;
//exports.checkOutputPort = checkOutputPort;
exports.checkOutputPort = checkOutputPort;
exports.checkString = checkString;
exports.checkFunction = checkFunction;
exports.checkNumber = checkNumber;
exports.checkReal = checkReal;
exports.checkNonNegativeReal = checkNonNegativeReal;
exports.checkNatural = checkNatural;
exports.checkInteger = checkInteger;
exports.checkRational = checkRational;
exports.checkPair = checkPair;
exports.checkList = checkList;
exports.checkVector = checkVector;
exports.checkBox = checkBox;
exports.checkMutableBox = checkMutableBox;
})(this['plt'].baselib);

View File

@ -84,6 +84,20 @@
};
var isPrimitiveProcedure = function(x) {
return typeof(x) === 'function';
};
var isClosure = function(x) {
return x instanceof Closure;
};
var isFunction = function(x) {
return (typeof(x) === 'function' ||
x instanceof Closure);
};
@ -91,5 +105,9 @@
exports.Closure = Closure;
exports.finalizeClosureCall = finalizeClosureCall;
exports.makePrimitiveProcedure = makePrimitiveProcedure;
exports.isPrimitiveProcedure = isPrimitiveProcedure;
exports.isClosure = isClosure;
exports.isFunction = isFunction;
})(this['plt'].baselib);

View File

@ -10,6 +10,8 @@
Empty = function() {
};
Empty.EMPTY = new Empty();
var EMPTY = Empty.EMPTY;
Empty.prototype.equals = function(other, aUnionFind) {
@ -44,8 +46,8 @@
Cons.prototype.reverse = function() {
var lst = this;
var ret = Empty.EMPTY;
while (!isEmpty(lst)){
var ret = EMPTY;
while (lst !== EMPTY) {
ret = Cons.makeInstance(lst.first, ret);
lst = lst.rest;
}
@ -70,11 +72,11 @@
// Cons.append: (listof X) -> (listof X)
Cons.prototype.append = function(b){
if (b === Empty.EMPTY)
if (b === EMPTY)
return this;
var ret = b;
var lst = this.reverse();
while ( !isEmpty(lst) ) {
while (lst !== EMPTY) {
ret = Cons.makeInstance(lst.first, ret);
lst = lst.rest;
}
@ -94,7 +96,7 @@
break;
}
}
if ( p !== Empty.EMPTY ) {
if ( p !== EMPTY ) {
texts.push('.');
texts.push(plt.baselib.format.toWrittenString(p, cache));
}
@ -179,12 +181,19 @@
var reverse = function(lst) {
var rev = EMPTY;
while(lst !== EMPTY) {
rev = makePair(lst.first, rev);
lst = lst.rest;
}
return rev;
};
//////////////////////////////////////////////////////////////////////
exports.EMPTY = Empty.EMPTY;
exports.EMPTY = EMPTY;
exports.Empty = Empty;
exports.Cons = Cons;
exports.isPair = isPair;
@ -192,6 +201,7 @@
exports.isEmpty = isEmpty;
exports.makePair = makePair;
exports.makeList = makeList;
exports.reverse = reverse;
})(this['plt'].baselib);

File diff suppressed because it is too large Load Diff