trying to add enough to allow the internal implementation of lists to run

This commit is contained in:
Danny Yoo 2011-07-28 14:06:03 -04:00
parent ab55c29540
commit 50dbc2319a
3 changed files with 91 additions and 10 deletions

View File

@ -98,14 +98,24 @@
expectedTypeName,
argumentOffset,
actualValue) {
raise(MACHINE,
new Error(
plt.baselib.format.format(
"~a: expected ~a as argument ~e but received ~e",
[callerName,
expectedTypeName,
(argumentOffset + 1),
actualValue])));
if (argumentOffset !== undefined) {
raise(MACHINE,
new Error(
plt.baselib.format.format(
"~a: expected ~a as argument ~e but received ~e",
[callerName,
expectedTypeName,
(argumentOffset + 1),
actualValue])));
} else {
raise(MACHINE,
new Error(
plt.baselib.format.format(
"~a: expected ~a but received ~e",
[callerName,
expectedTypeName,
actualValue])));
}
};
var raiseContextExpectedValuesError = function(MACHINE, expected) {

View File

@ -883,6 +883,15 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
return isPair(firstArg);
});
installPrimitiveProcedure(
'list?',
1,
function(MACHINE) {
return isList(MACHINE.env[MACHINE.env.length -1]);
});
installPrimitiveProcedure(
'set-car!',
2,
@ -1581,8 +1590,69 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
});
installPrimitiveProcedure(
'error',
plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) {
if (MACHINE.argcount === 1) {
var sym = checkSymbol(MACHINE, 'error', 1);
// FIXME: we should collect the current continuation marks here...
raise(MACHINE, plt.baselib.exceptions.makeExnFail(String(sym), undefined));
}
if (isString(MACHINE.env[MACHINE.env.length - 1])) {
var vs = [];
for (var i = 1; i < MACHINE.argcount; i++) {
vs.push(plt.baselib.format.format("~e", [MACHINE.env[MACHINE.env.length - 1 - i]]));
}
raise(MACHINE, plt.baselib.exceptions.makeExnFail(String(MACHINE.env[MACHINE.env.length - 1]) +
": " +
vs.join(' '),
undefined));
}
if (isSymbol(MACHINE.env[MACHINE.env.length - 1])) {
var fmtString = checkString(MACHINE, 'error', 1);
var args = [MACHINE.env[MACHINE.env.length - 1]];
for (i = 2; i < MACHINE.argcount; i++) {
args.push(MACHINE.env[MACHINE.env.length - 1 - i]);
}
raise(MACHINE, plt.baselib.exceptions.makeExnFail(
plt.baselib.format.format('~s: ' + String(fmtString),
args),
undefined));
}
// Fall-through
raiseArgumentTypeError(MACHINE, 'error', 'symbol or string', 0, MACHINE.env[MACHINE.env.length - 1]);
});
installPrimitiveProcedure(
'raise-type-error',
plt.baselib.arity.makeArityAtLeast(3),
function(MACHINE) {
var name = checkSymbol(MACHINE, 'raise-type-error', 0);
var expected = checkString(MACHINE, 'raise-type-error', 1);
if (MACHINE.argcount === 3) {
raiseArgumentTypeError(MACHINE,
name,
expected,
undefined,
MACHINE.env[MACHINE.env.length - 1 - 2]);
} else {
raiseArgumentTypeError(MACHINE,
name,
expected,
checkNatural(MACHINE, 'raise-type-error', 2),
MACHINE.env[MACHINE.env.length - 1 - 2]);
}
});
installPrimitiveClosure(
'make-struct-type',
makeList(4, 5, 6, 7, 8, 9, 10, 11),

View File

@ -192,6 +192,7 @@
;; (identity -identity)
;; raise
error
raise-type-error
;; make-exn
;; make-exn:fail
@ -251,7 +252,8 @@ error
string->number
;; procedure?
pair?
;; (undefined? -undefined?)
list?
;; (undefined? -undefined?)
;; immutable?
;; void?
symbol?
@ -293,7 +295,6 @@ exact?
;; cdddr
;; cadddr
length
;; list?
;; list*
list-ref
;; list-tail