trying to integrate with moby's vectors

This commit is contained in:
Danny Yoo 2011-06-07 16:48:56 -04:00
parent cfdcd215be
commit 9050882d4d
9 changed files with 329 additions and 311 deletions

10
NOTES
View File

@ -691,11 +691,11 @@ Working out the type mappings between values in Racket and values in JavaScript
Racket JavaScript Racket JavaScript Switched over?
number jsnums.SchemeNumber number jsnums.SchemeNumber yes
immutable strings JavaScript strings immutable strings JavaScript string
mutable strings types.Str mutable strings types.Str
vector vector
@ -710,8 +710,8 @@ Working out the type mappings between values in Racket and values in JavaScript
symbol symbol
keyword keyword
pair pair yes
empty empty yes
eq-hashtable eq-hashtable
equal-hashtable equal-hashtable

View File

@ -101,7 +101,7 @@
(cond [(symbol? val) (cond [(symbol? val)
(format "~s" (symbol->string val))] (format "~s" (symbol->string val))]
[(pair? val) [(pair? val)
(format "[~a, ~a]" (format "RUNTIME.makePair(~a, ~a)"
(loop (car val)) (loop (car val))
(loop (cdr val)))] (loop (cdr val)))]
[(boolean? val) [(boolean? val)
@ -122,7 +122,7 @@
[(empty? vals) [(empty? vals)
"RUNTIME.NULL"] "RUNTIME.NULL"]
[else [else
(format "[~a, ~a]" (first vals) (loop (rest vals)))]))) (format "RUNTIME.makePair(~a, ~a)" (first vals) (loop (rest vals)))])))

View File

@ -68,26 +68,21 @@
[(>=) [(>=)
(assemble-boolean-chain "jsnums.greaterThanOrEqual" checked-operands)] (assemble-boolean-chain "jsnums.greaterThanOrEqual" checked-operands)]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
[(cons) [(cons)
(format "[~a, ~a]" (first checked-operands) (second checked-operands))] (format "RUNTIME.makePair(~a, ~a)"
(first checked-operands)
(second checked-operands))]
[(car) [(car)
(format "(~a)[0]" (first checked-operands))] (format "(~a).first" (first checked-operands))]
[(cdr) [(cdr)
(format "(~a)[1]" (first checked-operands))] (format "(~a).rest" (first checked-operands))]
[(list) [(list)
(let loop ([checked-operands checked-operands]) (let loop ([checked-operands checked-operands])
(cond (assemble-listof-assembled-values checked-operands))]
[(empty? checked-operands)
"RUNTIME.NULL"]
[else
(format "[~a,~a]" (first checked-operands) (loop (rest checked-operands)))]))]
[(null?) [(null?)
(format "(~a === RUNTIME.NULL)" (first checked-operands))] (format "(~a === RUNTIME.NULL)" (first checked-operands))]
@ -151,17 +146,15 @@
(let: ([test-string : String (let: ([test-string : String
(case domain (case domain
[(number) [(number)
(format "(jsnums.isSchemeNumber(~a))" (format "jsnums.isSchemeNumber(~a)"
operand-string)] operand-string)]
[(string) [(string)
(format "(typeof(~a) === 'string')" (format "(typeof(~a) === 'string')"
operand-string)] operand-string)]
[(list) [(list)
(format "(~a === [] || (typeof(~a) === 'object' && (~a).length === 2))" (format "RUNTIME.isList(~a)" operand-string)]
operand-string operand-string operand-string)]
[(pair) [(pair)
(format "(typeof(~a) === 'object' && (~a).length === 2)" (format "RUNTIME.isPair(~a)" operand-string)]
operand-string operand-string)]
[(box) [(box)
(format "(typeof(~a) === 'object' && (~a).length === 1)" (format "(typeof(~a) === 'object' && (~a).length === 1)"
operand-string operand-string)])]) operand-string operand-string)])])

View File

@ -4,6 +4,7 @@
"quote-cdata.rkt" "quote-cdata.rkt"
"../make.rkt" "../make.rkt"
"../make-structs.rkt" "../make-structs.rkt"
"../parameters.rkt"
(planet dyoo/closure-compile:1:1) (planet dyoo/closure-compile:1:1)
(prefix-in runtime: "get-runtime.rkt") (prefix-in runtime: "get-runtime.rkt")
(prefix-in racket: racket/base)) (prefix-in racket: racket/base))
@ -114,12 +115,19 @@
(make (list only-bootstrapped-code) packaging-configuration) (make (list only-bootstrapped-code) packaging-configuration)
(fprintf op "})(plt.runtime.currentMachine,\nfunction(){ plt.runtime.setReadyTrue(); },\nfunction(){},\n{});\n"))) (fprintf op "})(plt.runtime.currentMachine,\nfunction(){ plt.runtime.setReadyTrue(); },\nfunction(){},\n{});\n")))
(define (compress x)
(if (current-compress-javascript?)
(closure-compile x)
x))
(define *the-runtime* (define *the-runtime*
(let ([buffer (open-output-string)]) (let ([buffer (open-output-string)])
(write-runtime buffer) (write-runtime buffer)
(closure-compile (compress
(get-output-string buffer)))) (get-output-string buffer))))
@ -152,7 +160,7 @@ EOF
(package source-code (package source-code
#:should-follow? (lambda (src p) #t) #:should-follow? (lambda (src p) #t)
#:output-port buffer) #:output-port buffer)
(closure-compile (compress
(get-output-string buffer)))) (get-output-string buffer))))
@ -161,7 +169,7 @@ EOF
(define (get-standalone-code source-code) (define (get-standalone-code source-code)
(let ([buffer (open-output-string)]) (let ([buffer (open-output-string)])
(write-standalone-code source-code buffer) (write-standalone-code source-code buffer)
(closure-compile (compress
(get-output-string buffer)))) (get-output-string buffer))))

View File

@ -777,16 +777,49 @@ if (! this['plt']) { this['plt'] = {}; }
// rationalToDomNode: rational -> dom-node // rationalToDomNode: rational -> dom-node
var rationalToDomNode = function(n) { var rationalToDomNode = function(n) {
var node = document.createElement("span"); var repeatingDecimalNode = document.createElement("span");
var chunks = jsnums.toRepeatingDecimal(jsnums.numerator(n), var chunks = jsnums.toRepeatingDecimal(jsnums.numerator(n),
jsnums.denominator(n)); jsnums.denominator(n),
node.appendChild(document.createTextNode(chunks[0] + '.')) {limit: 25});
node.appendChild(document.createTextNode(chunks[1])); repeatingDecimalNode.appendChild(document.createTextNode(chunks[0] + '.'))
var overlineSpan = document.createElement("span"); repeatingDecimalNode.appendChild(document.createTextNode(chunks[1]));
overlineSpan.style.textDecoration = 'overline'; if (chunks[2] === '...') {
overlineSpan.appendChild(document.createTextNode(chunks[2])); repeatingDecimalNode.appendChild(
node.appendChild(overlineSpan); document.createTextNode(chunks[2]));
return node; } else if (chunks[2] !== '0') {
var overlineSpan = document.createElement("span");
overlineSpan.style.textDecoration = 'overline';
overlineSpan.appendChild(document.createTextNode(chunks[2]));
repeatingDecimalNode.appendChild(overlineSpan);
}
var fractionalNode = document.createElement("span");
var numeratorNode = document.createElement("sup");
numeratorNode.appendChild(document.createTextNode(String(jsnums.numerator(n))));
var denominatorNode = document.createElement("sub");
denominatorNode.appendChild(document.createTextNode(String(jsnums.denominator(n))));
fractionalNode.appendChild(numeratorNode);
fractionalNode.appendChild(document.createTextNode("/"));
fractionalNode.appendChild(denominatorNode);
var numberNode = document.createElement("span");
numberNode.appendChild(repeatingDecimalNode);
numberNode.appendChild(fractionalNode);
fractionalNode.style['display'] = 'none';
var showingRepeating = true;
numberNode.onclick = function(e) {
showingRepeating = !showingRepeating;
repeatingDecimalNode.style['display'] =
(showingRepeating ? 'inline' : 'none')
fractionalNode.style['display'] =
(!showingRepeating ? 'inline' : 'none')
};
numberNode.style['cursor'] = 'pointer';
return numberNode;
} }

View File

@ -195,7 +195,7 @@ That way, we can do a simple grep.
var length = function(lst) { var length = function(lst) {
checkList(lst, 'length', 1, [lst]); checkList(lst, 'length', 1, [lst]);
var ret = 0; var ret = 0;
for (; !lst.isEmpty(); lst = lst.rest()) { for (; !lst.isEmpty(); lst = lst.rest) {
ret = ret+1; ret = ret+1;
} }
return ret; return ret;
@ -224,8 +224,8 @@ That way, we can do a simple grep.
var fArgs = []; var fArgs = [];
var argsRest = []; var argsRest = [];
for (var i = 0; i < args.length; i++) { for (var i = 0; i < args.length; i++) {
fArgs.push(args[i].first()); fArgs.push(args[i].first);
argsRest.push(args[i].rest()); argsRest.push(args[i].rest);
} }
fArgs.push(acc); fArgs.push(acc);
return CALL(f, fArgs, return CALL(f, fArgs,
@ -246,20 +246,20 @@ That way, we can do a simple grep.
} }
var compYes = new PrimProc('compYes', 1, false, false, var compYes = new PrimProc('compYes', 1, false, false,
function(x) { return CALL(comp, [x, lst.first()], id); }); function(x) { return CALL(comp, [x, lst.first], id); });
var compNo = new PrimProc('compNo', 1, false, false, var compNo = new PrimProc('compNo', 1, false, false,
function(x) { return CALL(comp, [x, lst.first()], function(x) { return CALL(comp, [x, lst.first],
function(res) { return !res; }); function(res) { return !res; });
}); });
return CALL(PRIMITIVES['filter'], return CALL(PRIMITIVES['filter'],
[compYes, lst.rest()], [compYes, lst.rest],
quicksortHelp(function(sorted1) { quicksortHelp(function(sorted1) {
return CALL(PRIMITIVES['filter'], return CALL(PRIMITIVES['filter'],
[compNo, lst.rest()], [compNo, lst.rest],
quicksortHelp(function(sorted2) { quicksortHelp(function(sorted2) {
return k( append([sorted1, return k( append([sorted1,
types.list([lst.first()]), types.list([lst.first]),
sorted2]) ); sorted2]) );
})); }));
})); }));
@ -487,7 +487,7 @@ That way, we can do a simple grep.
var isAssocList = function(x) { var isAssocList = function(x) {
return isPair(x) && isPair(x.rest()) && isEmpty(x.rest().rest()); return isPair(x) && isPair(x.rest) && isEmpty(x.rest.rest);
}; };
@ -725,8 +725,8 @@ That way, we can do a simple grep.
var argsFirst = []; var argsFirst = [];
var argsRest = []; var argsRest = [];
for (var i = 0; i < args.length; i++) { for (var i = 0; i < args.length; i++) {
argsFirst.push(args[i].first()); argsFirst.push(args[i].first);
argsRest.push(args[i].rest()); argsRest.push(args[i].rest);
} }
return CALL(f, argsFirst, return CALL(f, argsFirst,
@ -1109,11 +1109,11 @@ That way, we can do a simple grep.
return CALL(new PrimProc('', 1, false, false, return CALL(new PrimProc('', 1, false, false,
function(args) { function(args) {
return callWithValues(fList.first(), args); return callWithValues(fList.first, args);
}), }),
[x], [x],
function(result) { function(result) {
return composeHelp(result, fList.rest()); return composeHelp(result, fList.rest);
}); });
} }
return new PrimProc('', 0, true, false, return new PrimProc('', 0, true, false,
@ -2032,9 +2032,9 @@ That way, we can do a simple grep.
var nextResult = parse(child); var nextResult = parse(child);
if (isString(nextResult) && if (isString(nextResult) &&
!result.isEmpty() && !result.isEmpty() &&
isString(result.first())) { isString(result.first)) {
result = types.cons(result.first() + nextResult, result = types.cons(result.first + nextResult,
result.rest()); result.rest);
} else { } else {
result = types.cons(nextResult, result); result = types.cons(nextResult, result);
} }
@ -2219,7 +2219,7 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
check(lst, isPair, 'car', 'pair', 1); check(lst, isPair, 'car', 'pair', 1);
return lst.first(); return lst.first;
}); });
PRIMITIVES['cdr'] = PRIMITIVES['cdr'] =
@ -2228,7 +2228,7 @@ That way, we can do a simple grep.
false, false, false, false,
function (lst) { function (lst) {
check(lst, isPair, 'cdr', 'pair', 1); check(lst, isPair, 'cdr', 'pair', 1);
return lst.rest(); return lst.rest;
}); });
PRIMITIVES['caar'] = PRIMITIVES['caar'] =
@ -2236,9 +2236,9 @@ That way, we can do a simple grep.
1, 1,
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return (isPair(x) && isPair(x.first())); }, check(lst, function(x) { return (isPair(x) && isPair(x.first)); },
'caar', 'caarable value', 1); 'caar', 'caarable value', 1);
return lst.first().first(); return lst.first.first;
}); });
PRIMITIVES['cadr'] = PRIMITIVES['cadr'] =
@ -2246,9 +2246,9 @@ That way, we can do a simple grep.
1, 1,
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return isPair(x) && isPair(x.rest()); }, check(lst, function(x) { return isPair(x) && isPair(x.rest); },
'cadr', 'cadrable value', 1); 'cadr', 'cadrable value', 1);
return lst.rest().first(); return lst.rest.first;
}); });
PRIMITIVES['cdar'] = PRIMITIVES['cdar'] =
@ -2256,9 +2256,9 @@ That way, we can do a simple grep.
1, 1,
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return isPair(x) && isPair(x.first()); }, check(lst, function(x) { return isPair(x) && isPair(x.first); },
'cdar', 'cdarable value', 1); 'cdar', 'cdarable value', 1);
return lst.first().rest(); return lst.first.rest;
}); });
PRIMITIVES['cddr'] = PRIMITIVES['cddr'] =
@ -2266,9 +2266,9 @@ That way, we can do a simple grep.
1, 1,
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return isPair(x) && isPair(x.rest()); }, check(lst, function(x) { return isPair(x) && isPair(x.rest); },
'cddr', 'cddrable value', 1); 'cddr', 'cddrable value', 1);
return lst.rest().rest(); return lst.rest.rest;
}); });
PRIMITIVES['caaar'] = PRIMITIVES['caaar'] =
@ -2277,10 +2277,10 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return ( isPair(x) && check(lst, function(x) { return ( isPair(x) &&
isPair(x.first()) && isPair(x.first) &&
isPair(x.first().first()) ); }, isPair(x.first.first) ); },
'caaar', 'caaarable value', 1); 'caaar', 'caaarable value', 1);
return lst.first().first().first(); return lst.first.first.first;
}); });
PRIMITIVES['caadr'] = PRIMITIVES['caadr'] =
@ -2289,10 +2289,10 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return ( isPair(x) && check(lst, function(x) { return ( isPair(x) &&
isPair(x.rest()) && isPair(x.rest) &&
isPair(x.rest().first()) ); }, isPair(x.rest.first) ); },
'caadr', 'caadrable value', 1); 'caadr', 'caadrable value', 1);
return lst.rest().first().first(); return lst.rest.first.first;
}); });
PRIMITIVES['cadar'] = PRIMITIVES['cadar'] =
@ -2301,10 +2301,10 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return ( isPair(x) && check(lst, function(x) { return ( isPair(x) &&
isPair(x.first()) && isPair(x.first) &&
isPair(x.first().rest()) ); }, isPair(x.first.rest) ); },
'cadar', 'cadarable value', 1); 'cadar', 'cadarable value', 1);
return lst.first().rest().first(); return lst.first.rest.first;
}); });
PRIMITIVES['cdaar'] = PRIMITIVES['cdaar'] =
@ -2313,10 +2313,10 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return ( isPair(x) && check(lst, function(x) { return ( isPair(x) &&
isPair(x.first()) && isPair(x.first) &&
isPair(x.first().first()) ); }, isPair(x.first.first) ); },
'cdaar', 'cdaarable value', 1); 'cdaar', 'cdaarable value', 1);
return lst.first().first().rest(); return lst.first.first.rest;
}); });
PRIMITIVES['cdadr'] = PRIMITIVES['cdadr'] =
@ -2325,10 +2325,10 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return ( isPair(x) && check(lst, function(x) { return ( isPair(x) &&
isPair(x.rest()) && isPair(x.rest) &&
isPair(x.rest().first()) ); }, isPair(x.rest.first) ); },
'cdadr', 'cdadrable value', 1); 'cdadr', 'cdadrable value', 1);
return lst.rest().first().rest(); return lst.rest.first.rest;
}); });
PRIMITIVES['cddar'] = PRIMITIVES['cddar'] =
@ -2337,10 +2337,10 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return ( isPair(x) && check(lst, function(x) { return ( isPair(x) &&
isPair(x.first()) && isPair(x.first) &&
isPair(x.first().rest()) ); }, isPair(x.first.rest) ); },
'cddar', 'cddarable value', 1); 'cddar', 'cddarable value', 1);
return lst.first().rest().rest(); return lst.first.rest.rest;
}); });
PRIMITIVES['caddr'] = PRIMITIVES['caddr'] =
@ -2349,10 +2349,10 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return ( isPair(x) && check(lst, function(x) { return ( isPair(x) &&
isPair(x.rest()) && isPair(x.rest) &&
isPair(x.rest().rest()) ); }, isPair(x.rest.rest) ); },
'caddr', 'caddrable value', 1); 'caddr', 'caddrable value', 1);
return lst.rest().rest().first(); return lst.rest.rest.first;
}); });
PRIMITIVES['cdddr'] = PRIMITIVES['cdddr'] =
@ -2361,10 +2361,10 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return ( isPair(x) && check(lst, function(x) { return ( isPair(x) &&
isPair(x.rest()) && isPair(x.rest) &&
isPair(x.rest().rest()) ); }, isPair(x.rest.rest) ); },
'cdddr', 'cdddrable value', 1); 'cdddr', 'cdddrable value', 1);
return lst.rest().rest().rest(); return lst.rest.rest.rest;
}); });
PRIMITIVES['cadddr'] = PRIMITIVES['cadddr'] =
@ -2373,11 +2373,11 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
check(lst, function(x) { return ( isPair(x) && check(lst, function(x) { return ( isPair(x) &&
isPair(x.rest()) && isPair(x.rest) &&
isPair(x.rest().rest()) && isPair(x.rest.rest) &&
isPair(x.rest().rest().rest()) ); }, isPair(x.rest.rest.rest) ); },
'cadddr', 'cadddrable value', 1); 'cadddr', 'cadddrable value', 1);
return lst.rest().rest().rest().first(); return lst.rest.rest.rest.first;
}); });
@ -2388,7 +2388,7 @@ That way, we can do a simple grep.
function(lst) { function(lst) {
check(lst, function(x) { return isList(x) && !isEmpty(x); }, check(lst, function(x) { return isList(x) && !isEmpty(x); },
'rest', 'non-empty list', 1); 'rest', 'non-empty list', 1);
return lst.rest(); return lst.rest;
}); });
PRIMITIVES['first'] = PRIMITIVES['first'] =
@ -2398,7 +2398,7 @@ That way, we can do a simple grep.
function(lst) { function(lst) {
check(lst, function(x) { return isList(x) && !isEmpty(x); }, check(lst, function(x) { return isList(x) && !isEmpty(x); },
'first', 'non-empty list', 1); 'first', 'non-empty list', 1);
return lst.first(); return lst.first;
}); });
PRIMITIVES['second'] = PRIMITIVES['second'] =
@ -2407,7 +2407,7 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
checkListOfLength(lst, 2, 'second', 1); checkListOfLength(lst, 2, 'second', 1);
return lst.rest().first(); return lst.rest.first;
}); });
PRIMITIVES['third'] = PRIMITIVES['third'] =
@ -2416,7 +2416,7 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
checkListOfLength(lst, 3, 'third', 1); checkListOfLength(lst, 3, 'third', 1);
return lst.rest().rest().first(); return lst.rest.rest.first;
}); });
PRIMITIVES['fourth'] = PRIMITIVES['fourth'] =
@ -2425,7 +2425,7 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
checkListOfLength(lst, 4, 'fourth', 1); checkListOfLength(lst, 4, 'fourth', 1);
return lst.rest().rest().rest().first(); return lst.rest.rest.rest.first;
}); });
PRIMITIVES['fifth'] = PRIMITIVES['fifth'] =
@ -2434,7 +2434,7 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
checkListOfLength(lst, 5, 'fifth', 1); checkListOfLength(lst, 5, 'fifth', 1);
return lst.rest().rest().rest().rest().first(); return lst.rest.rest.rest.rest.first;
}); });
PRIMITIVES['sixth'] = PRIMITIVES['sixth'] =
@ -2443,7 +2443,7 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
checkListOfLength(lst, 6, 'sixth', 1); checkListOfLength(lst, 6, 'sixth', 1);
return lst.rest().rest().rest().rest().rest().first(); return lst.rest.rest.rest.rest.rest.first;
}); });
PRIMITIVES['seventh'] = PRIMITIVES['seventh'] =
@ -2453,7 +2453,7 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
checkListOfLength(lst, 7, 'seventh', 1); checkListOfLength(lst, 7, 'seventh', 1);
return lst.rest().rest().rest().rest().rest().rest().first(); return lst.rest.rest.rest.rest.rest.rest.first;
}); });
PRIMITIVES['eighth'] = PRIMITIVES['eighth'] =
@ -2462,7 +2462,7 @@ That way, we can do a simple grep.
false, false, false, false,
function(lst) { function(lst) {
checkListOfLength(lst, 8, 'eighth', 1); checkListOfLength(lst, 8, 'eighth', 1);
return lst.rest().rest().rest().rest().rest().rest().rest().first(); return lst.rest.rest.rest.rest.rest.rest.rest.first;
}); });
@ -2536,7 +2536,7 @@ That way, we can do a simple grep.
helpers.toDisplayedString(origList)); helpers.toDisplayedString(origList));
raise( types.incompleteExn(types.exnFailContract, msg, []) ); raise( types.incompleteExn(types.exnFailContract, msg, []) );
} }
lst = lst.rest(); lst = lst.rest;
} }
@ -2548,7 +2548,7 @@ That way, we can do a simple grep.
msg, msg,
[]) ); []) );
} }
return lst.first(); return lst.first;
}); });
PRIMITIVES['list-tail'] = PRIMITIVES['list-tail'] =
@ -2578,7 +2578,7 @@ That way, we can do a simple grep.
helpers.toDisplayedString(origList)); helpers.toDisplayedString(origList));
raise( types.incompleteExn(types.exnFailContract, msg, []) ); raise( types.incompleteExn(types.exnFailContract, msg, []) );
} }
lst = lst.rest(); lst = lst.rest;
} }
return lst; return lst;
}); });
@ -2622,8 +2622,8 @@ That way, we can do a simple grep.
var argsFirst = []; var argsFirst = [];
var argsRest = []; var argsRest = [];
for (var i = 0; i < args.length; i++) { for (var i = 0; i < args.length; i++) {
argsFirst.push(args[i].first()); argsFirst.push(args[i].first);
argsRest.push(args[i].rest()); argsRest.push(args[i].rest);
} }
var result = CALL(f, argsFirst, var result = CALL(f, argsFirst,
function(result) { function(result) {
@ -2658,8 +2658,8 @@ That way, we can do a simple grep.
var argsFirst = []; var argsFirst = [];
var argsRest = []; var argsRest = [];
for (var i = 0; i < args.length; i++) { for (var i = 0; i < args.length; i++) {
argsFirst.push(args[i].first()); argsFirst.push(args[i].first);
argsRest.push(args[i].rest()); argsRest.push(args[i].rest);
} }
return CALL(f, argsFirst, return CALL(f, argsFirst,
@ -2699,8 +2699,8 @@ That way, we can do a simple grep.
var argsFirst = []; var argsFirst = [];
var argsRest = []; var argsRest = [];
for (var i = 0; i < args.length; i++) { for (var i = 0; i < args.length; i++) {
argsFirst.push(args[i].first()); argsFirst.push(args[i].first);
argsRest.push(args[i].rest()); argsRest.push(args[i].rest);
} }
return CALL(f, argsFirst, return CALL(f, argsFirst,
@ -2734,10 +2734,10 @@ That way, we can do a simple grep.
} }
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
if ( isEq(item, lst.first()) ) { if ( isEq(item, lst.first) ) {
return lst; return lst;
} }
lst = lst.rest(); lst = lst.rest;
if (! isPair(lst) && lst !== types.EMPTY) { if (! isPair(lst) && lst !== types.EMPTY) {
var msg = ('memq: not a proper list: ' + var msg = ('memq: not a proper list: ' +
helpers.toDisplayedString(origList)); helpers.toDisplayedString(origList));
@ -2764,10 +2764,10 @@ That way, we can do a simple grep.
[]) ); []) );
} }
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
if ( isEqv(item, lst.first()) ) { if ( isEqv(item, lst.first) ) {
return lst; return lst;
} }
lst = lst.rest(); lst = lst.rest;
if (! isPair(lst) && lst !== types.EMPTY) { if (! isPair(lst) && lst !== types.EMPTY) {
var msg = ('memv: not a proper list: ' + var msg = ('memv: not a proper list: ' +
helpers.toDisplayedString(origList)); helpers.toDisplayedString(origList));
@ -2795,10 +2795,10 @@ That way, we can do a simple grep.
[]) ); []) );
} }
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
if ( isEqual(item, lst.first()) ) { if ( isEqual(item, lst.first) ) {
return lst; return lst;
} }
lst = lst.rest(); lst = lst.rest;
if (! isPair(lst) && lst !== types.EMPTY) { if (! isPair(lst) && lst !== types.EMPTY) {
var msg = ('member: not a proper list: ' + var msg = ('member: not a proper list: ' +
@ -2825,12 +2825,12 @@ That way, we can do a simple grep.
return false; return false;
} }
return CALL(f, [lst.first()], return CALL(f, [lst.first],
function(result) { function(result) {
if (result) { if (result) {
return lst; return lst;
} }
return memfHelp(lst.rest()); return memfHelp(lst.rest);
}); });
} }
return memfHelp(initList); return memfHelp(initList);
@ -2852,18 +2852,18 @@ That way, we can do a simple grep.
[]) ); []) );
} }
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
if (! isPair(lst.first())) { if (! isPair(lst.first)) {
var msg = ('assq: non-pair found in list: ' + var msg = ('assq: non-pair found in list: ' +
helpers.toDisplayedString(lst.first()) +' in ' + helpers.toDisplayedString(lst.first) +' in ' +
helpers.toDisplayedString(origList)); helpers.toDisplayedString(origList));
raise( types.incompleteExn(types.exnFailContract, raise( types.incompleteExn(types.exnFailContract,
msg, msg,
[]) ); []) );
} }
if ( isEq(item, lst.first().first()) ) { if ( isEq(item, lst.first.first) ) {
return lst.first(); return lst.first;
} }
lst = lst.rest(); lst = lst.rest;
if (! isPair(lst) && lst !== types.EMPTY) { if (! isPair(lst) && lst !== types.EMPTY) {
var msg = ('assq: not a proper list: ' + var msg = ('assq: not a proper list: ' +
@ -2892,18 +2892,18 @@ That way, we can do a simple grep.
[]) ); []) );
} }
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
if (! isPair(lst.first())) { if (! isPair(lst.first)) {
var msg = ('assv: non-pair found in list: ' + var msg = ('assv: non-pair found in list: ' +
helpers.toDisplayedString(lst.first()) +' in ' + helpers.toDisplayedString(lst.first) +' in ' +
helpers.toDisplayedString(origList)); helpers.toDisplayedString(origList));
raise( types.incompleteExn(types.exnFailContract, raise( types.incompleteExn(types.exnFailContract,
msg, msg,
[]) ); []) );
} }
if ( isEqv(item, lst.first().first()) ) { if ( isEqv(item, lst.first.first) ) {
return lst.first(); return lst.first;
} }
lst = lst.rest(); lst = lst.rest;
if (! isPair(lst) && lst !== types.EMPTY) { if (! isPair(lst) && lst !== types.EMPTY) {
var msg = ('assv: not a proper list: ' + var msg = ('assv: not a proper list: ' +
helpers.toDisplayedString(origList)); helpers.toDisplayedString(origList));
@ -2931,18 +2931,18 @@ That way, we can do a simple grep.
[]) ); []) );
} }
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
if (! isPair(lst.first())) { if (! isPair(lst.first)) {
var msg = ('assoc: non-pair found in list: ' + var msg = ('assoc: non-pair found in list: ' +
helpers.toDisplayedString(lst.first()) +' in ' + helpers.toDisplayedString(lst.first) +' in ' +
helpers.toDisplayedString(origList)); helpers.toDisplayedString(origList));
raise( types.incompleteExn(types.exnFailContract, raise( types.incompleteExn(types.exnFailContract,
msg, msg,
[]) ); []) );
} }
if ( isEqual(item, lst.first().first()) ) { if ( isEqual(item, lst.first.first) ) {
return lst.first(); return lst.first;
} }
lst = lst.rest(); lst = lst.rest;
if (! isPair(lst) && lst !== types.EMPTY) { if (! isPair(lst) && lst !== types.EMPTY) {
var msg = ('assoc: not a proper list: ' + var msg = ('assoc: not a proper list: ' +
@ -2965,11 +2965,11 @@ That way, we can do a simple grep.
var originalLst = lst; var originalLst = lst;
var result = types.EMPTY; var result = types.EMPTY;
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
if ( isEqual(item, lst.first()) ) { if ( isEqual(item, lst.first) ) {
return append([result.reverse(), lst.rest()]); return append([result.reverse(), lst.rest]);
} else { } else {
result = types.cons(lst.first(), result); result = types.cons(lst.first, result);
lst = lst.rest(); lst = lst.rest;
} }
} }
return originalLst; return originalLst;
@ -2989,14 +2989,14 @@ That way, we can do a simple grep.
return acc.reverse(); return acc.reverse();
} }
return CALL(f, [lst.first()], return CALL(f, [lst.first],
function(result) { function(result) {
if (result) { if (result) {
return filterHelp(f, lst.rest(), return filterHelp(f, lst.rest,
types.cons(lst.first(), acc)); types.cons(lst.first, acc));
} }
else { else {
return filterHelp(f, lst.rest(), acc); return filterHelp(f, lst.rest, acc);
} }
}); });
} }
@ -3055,22 +3055,22 @@ That way, we can do a simple grep.
return curMaxElt; return curMaxElt;
} }
return CALL(f, [lst.first()], return CALL(f, [lst.first],
function(result) { function(result) {
check(result, isReal, 'argmax', check(result, isReal, 'argmax',
'procedure that returns real numbers', 1, args); 'procedure that returns real numbers', 1, args);
if (jsnums.greaterThan(result, curMaxVal)) { if (jsnums.greaterThan(result, curMaxVal)) {
return argmaxHelp(lst.rest(), result, lst.first()); return argmaxHelp(lst.rest, result, lst.first);
} }
else { else {
return argmaxHelp(lst.rest(), curMaxVal, curMaxElt); return argmaxHelp(lst.rest, curMaxVal, curMaxElt);
} }
}); });
} }
return CALL(f, [initList.first()], return CALL(f, [initList.first],
function(result) { function(result) {
check(result, isReal, 'argmax', 'procedure that returns real numbers', 1, args); check(result, isReal, 'argmax', 'procedure that returns real numbers', 1, args);
return argmaxHelp(initList.rest(), result, initList.first()); return argmaxHelp(initList.rest, result, initList.first);
}); });
}); });
@ -3089,22 +3089,22 @@ That way, we can do a simple grep.
return curMaxElt; return curMaxElt;
} }
return CALL(f, [lst.first()], return CALL(f, [lst.first],
function(result) { function(result) {
check(result, isReal, 'argmin', check(result, isReal, 'argmin',
'procedure that returns real numbers', 1, args); 'procedure that returns real numbers', 1, args);
if (jsnums.lessThan(result, curMaxVal)) { if (jsnums.lessThan(result, curMaxVal)) {
return argminHelp(lst.rest(), result, lst.first()); return argminHelp(lst.rest, result, lst.first);
} }
else { else {
return argminHelp(lst.rest(), curMaxVal, curMaxElt); return argminHelp(lst.rest, curMaxVal, curMaxElt);
} }
}); });
} }
return CALL(f, [initList.first()], return CALL(f, [initList.first],
function(result) { function(result) {
check(result, isReal, 'argmin', 'procedure that returns real numbers', 1, args); check(result, isReal, 'argmin', 'procedure that returns real numbers', 1, args);
return argminHelp(initList.rest(), result, initList.first()); return argminHelp(initList.rest, result, initList.first);
}); });
}); });
@ -3614,8 +3614,8 @@ That way, we can do a simple grep.
var ret = []; var ret = [];
while( !lst.isEmpty() ) { while( !lst.isEmpty() ) {
ret.push(lst.first().val); ret.push(lst.first.val);
lst = lst.rest(); lst = lst.rest;
} }
return types.string(ret); return types.string(ret);
}); });
@ -3728,8 +3728,8 @@ That way, we can do a simple grep.
'implode', 'list of 1-letter strings', 1); 'implode', 'list of 1-letter strings', 1);
var ret = []; var ret = [];
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
ret.push( lst.first().toString() ); ret.push( lst.first.toString() );
lst = lst.rest(); lst = lst.rest;
} }
return types.string(ret); return types.string(ret);
}); });
@ -4139,8 +4139,8 @@ That way, we can do a simple grep.
var ret = []; var ret = [];
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
ret.push(lst.first()); ret.push(lst.first);
lst = lst.rest(); lst = lst.rest;
} }
return types.bytes(ret, true); return types.bytes(ret, true);
}); });

View File

@ -9,8 +9,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
scope['runtime'] = runtime; scope['runtime'] = runtime;
var helpers = plt.helpers; var helpers = plt.helpers;
var types = plt.types;
var heir = helpers.heir;
// Consumes a class and creates a predicate that recognizes subclasses. // Consumes a class and creates a predicate that recognizes subclasses.
@ -19,27 +19,32 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
}; };
var isNumber = jsnums.isSchemeNumber;
var isNatural = function(x) { return (jsnums.isInteger(x) &&
jsnums.greaterThanOrEqual(x, 0)); }
var isPair = function(x) { return (typeof(x) == 'object' &&
x.length === 2 &&
x.type !== 'vector') };
var isList = function(x) {
while (x !== NULL) {
if (typeof(x) == 'object' && x.length === 2) {
x = x[1];
} else {
return false;
}
}
return true;
};
var isVector = function(x) { return (typeof(x) == 'object' &&
x.type === 'vector') }; //////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// We try to isolate the effect of external modules: all the identifiers we
// pull from external modules should be listed here, and should otherwise not
// show up outside this section!
var isNumber = types.isNumber;
var isNatural = types.isNatural;
var isPair = types.isPair;
var isList = types.isList;
var isVector = types.isVector;
var NULL = types.EMPTY;
var makeVector = types.vector;
var makeList = types.list;
var makePair = types.pair;
var heir = helpers.heir;
var toDomNode = helpers.toDomNode;
//////////////////////////////////////////////////////////////////////]
// This value will be dynamically determined. // This value will be dynamically determined.
@ -77,7 +82,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
'currentSuccessHandler': function(MACHINE) {}, 'currentSuccessHandler': function(MACHINE) {},
'currentErrorHandler': function(MACHINE, exn) { 'currentErrorHandler': function(MACHINE, exn) {
MACHINE.params.currentErrorDisplayer( MACHINE.params.currentErrorDisplayer(
helpers.toDomNode(exn.message, 'print')); toDomNode(exn.message, 'print'));
}, },
'currentNamespace': {}, 'currentNamespace': {},
@ -105,8 +110,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
var outputPort = var outputPort =
MACHINE.params.currentOutputPort; MACHINE.params.currentOutputPort;
if (elt !== undefined) { if (elt !== undefined) {
outputPort.writeDomNode(MACHINE, helpers.toDomNode(elt, 'print')); outputPort.writeDomNode(MACHINE, toDomNode(elt, 'print'));
outputPort.writeDomNode(MACHINE, helpers.toDomNode("\n", 'print')); outputPort.writeDomNode(MACHINE, toDomNode("\n", 'print'));
} }
var frame = MACHINE.control.pop(); var frame = MACHINE.control.pop();
return frame.label(MACHINE); return frame.label(MACHINE);
@ -314,7 +319,6 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
new ContinuationPromptTag("default-continuation-prompt-tag"); new ContinuationPromptTag("default-continuation-prompt-tag");
var NULL = [];
var raise = function(MACHINE, e) { var raise = function(MACHINE, e) {
@ -452,8 +456,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
var lst = MACHINE.env[MACHINE.env.length - 1 - depth]; var lst = MACHINE.env[MACHINE.env.length - 1 - depth];
var vals = []; var vals = [];
while(lst !== NULL) { while(lst !== NULL) {
vals.push(lst[0]); vals.push(lst.first);
lst = lst[1]; lst = lst.rest;
} }
vals.reverse(); vals.reverse();
MACHINE.env.splice.apply(MACHINE.env, MACHINE.env.splice.apply(MACHINE.env,
@ -466,7 +470,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
var lst = NULL; var lst = NULL;
var i; var i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
lst = [MACHINE.env[MACHINE.env.length - depth - length + i], lst]; lst = makePair(MACHINE.env[MACHINE.env.length - depth - length + i],
lst);
} }
MACHINE.env.splice(MACHINE.env.length - depth - length, MACHINE.env.splice(MACHINE.env.length - depth - length,
length, length,
@ -492,12 +497,12 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
return n >= arity.value; return n >= arity.value;
} else { } else {
while (arity !== NULL) { while (arity !== NULL) {
if (typeof(arity[0]) === 'number') { if (typeof(arity.first) === 'number') {
if (arity[0] === n) { return true; } if (arity.first === n) { return true; }
} else if (arity instanceof ArityAtLeast) { } else if (arity instanceof ArityAtLeast) {
if (n >= arity[0].value) { return true; } if (n >= arity.first.value) { return true; }
} }
arity = arity[1]; arity = arity.rest;
} }
return false; return false;
} }
@ -524,9 +529,9 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
'display'); 'display');
outputPort = MACHINE.env[MACHINE.env.length-2]; outputPort = MACHINE.env[MACHINE.env.length-2];
} }
outputPort.writeDomNode(MACHINE, helpers.toDomNode(firstArg, 'display')); outputPort.writeDomNode(MACHINE, toDomNode(firstArg, 'display'));
}; };
Primitives['display'].arity = [1, [2, NULL]]; Primitives['display'].arity = makeList(1, 2);
Primitives['display'].displayName = 'display'; Primitives['display'].displayName = 'display';
@ -541,9 +546,9 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
'newline'); 'newline');
outputPort = MACHINE.env[MACHINE.env.length-1]; outputPort = MACHINE.env[MACHINE.env.length-1];
} }
outputPort.writeDomNode(MACHINE, helpers.toDomNode("\n", 'display')); outputPort.writeDomNode(MACHINE, toDomNode("\n", 'display'));
}; };
Primitives['newline'].arity = [0, [1, NULL]]; Primitives['newline'].arity = makeList(0, 1);
Primitives['newline'].displayName = 'newline'; Primitives['newline'].displayName = 'newline';
@ -559,10 +564,10 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
'displayln'); 'displayln');
outputPort = MACHINE.env[MACHINE.env.length-2]; outputPort = MACHINE.env[MACHINE.env.length-2];
} }
outputPort.writeDomNode(MACHINE, helpers.toDomNode(firstArg, 'display')); outputPort.writeDomNode(MACHINE, toDomNode(firstArg, 'display'));
outputPort.writeDomNode(MACHINE, helpers.toDomNode("\n", 'display')); outputPort.writeDomNode(MACHINE, toDomNode("\n", 'display'));
}; };
Primitives['displayln'].arity = [1, [2, NULL]]; Primitives['displayln'].arity = makeList(1, 2);
Primitives['displayln'].displayName = 'displayln'; Primitives['displayln'].displayName = 'displayln';
@ -570,7 +575,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
Primitives['current-print'] = function(MACHINE) { Primitives['current-print'] = function(MACHINE) {
return MACHINE.params['current-print']; return MACHINE.params['current-print'];
}; };
Primitives['current-print'].arity = [0, [1, NULL]]; Primitives['current-print'].arity = makeList(0, 1);
Primitives['current-print'].displayName = "current-print"; Primitives['current-print'].displayName = "current-print";
Primitives['pi'] = jsnums.pi; Primitives['pi'] = jsnums.pi;
@ -811,7 +816,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
Primitives['cons'] = function(MACHINE) { Primitives['cons'] = 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 [firstArg, secondArg]; return makePair(firstArg, secondArg);
}; };
Primitives['cons'].arity = 2; Primitives['cons'].arity = 2;
Primitives['cons'].displayName = 'cons'; Primitives['cons'].displayName = 'cons';
@ -820,8 +825,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
Primitives['list'] = function(MACHINE) { Primitives['list'] = function(MACHINE) {
var result = NULL; var result = NULL;
for (var i = 0; i < MACHINE.argcount; i++) { for (var i = 0; i < MACHINE.argcount; i++) {
result = [MACHINE.env[MACHINE.env.length - (MACHINE.argcount - i)], result = makePair(MACHINE.env[MACHINE.env.length - (MACHINE.argcount - i)],
result]; result);
} }
return result; return result;
}; };
@ -836,7 +841,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
0, 0,
'car'); 'car');
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
return firstArg[0]; return firstArg.first;
}; };
Primitives['car'].arity = 1; Primitives['car'].arity = 1;
Primitives['car'].displayName = 'car'; Primitives['car'].displayName = 'car';
@ -849,7 +854,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
0, 0,
'cdr'); 'cdr');
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
return firstArg[1]; return firstArg.rest;
}; };
Primitives['cdr'].arity = 1; Primitives['cdr'].arity = 1;
Primitives['cdr'].displayName = 'cdr'; Primitives['cdr'].displayName = 'cdr';
@ -870,7 +875,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
'set-car!'); 'set-car!');
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];
firstArg[0] = secondArg; firstArg.first = secondArg;
}; };
Primitives['set-car!'].arity = 2; Primitives['set-car!'].arity = 2;
Primitives['set-car!'].displayName = 'set-car!'; Primitives['set-car!'].displayName = 'set-car!';
@ -884,7 +889,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
'set-cdr!'); 'set-cdr!');
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];
firstArg[1] = secondArg; firstArg.rest = secondArg;
}; };
Primitives['set-cdr!'].arity = 2; Primitives['set-cdr!'].arity = 2;
Primitives['set-cdr!'].displayName = 'set-cdr!'; Primitives['set-cdr!'].displayName = 'set-cdr!';
@ -912,7 +917,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
result.push(MACHINE.env[MACHINE.env.length-1-i]); result.push(MACHINE.env[MACHINE.env.length-1-i]);
} }
result.type = 'vector'; result.type = 'vector';
return result; return makeVector.apply(null, result);
}; };
Primitives['vector'].arity = new ArityAtLeast(0); Primitives['vector'].arity = new ArityAtLeast(0);
Primitives['vector'].displayName = 'vector'; Primitives['vector'].displayName = 'vector';
@ -924,11 +929,11 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'vector->list'); 'vector->list');
var firstArg = MACHINE.env[MACHINE.env.length-1]; var elts = MACHINE.env[MACHINE.env.length-1].elts;
var i; var i;
var result = NULL; var result = NULL;
for (i = 0; i < firstArg.length; i++) { for (i = 0; i < elts.length; i++) {
result = [firstArg[firstArg.length - 1 - i], result]; result = makePair(elts[elts.length - 1 - i], result);
} }
return result; return result;
}; };
@ -939,11 +944,10 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
var result = []; var result = [];
while (firstArg !== NULL) { while (firstArg !== NULL) {
result.push(firstArg[0]); result.push(firstArg.first);
firstArg = firstArg[1]; firstArg = firstArg.rest;
} }
result.type='vector'; return makeVector.apply(null, result);
return result;
}; };
Primitives['list->vector'].arity = 1; Primitives['list->vector'].arity = 1;
Primitives['list->vector'].displayName = 'list->vector'; Primitives['list->vector'].displayName = 'list->vector';
@ -955,9 +959,9 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'vector-ref'); 'vector-ref');
var firstArg = MACHINE.env[MACHINE.env.length-1]; var elts = MACHINE.env[MACHINE.env.length-1].elts;
var secondArg = MACHINE.env[MACHINE.env.length-2]; var index = MACHINE.env[MACHINE.env.length-2];
return firstArg[secondArg]; return elts[index];
}; };
Primitives['vector-ref'].arity = 2; Primitives['vector-ref'].arity = 2;
Primitives['vector-ref'].displayName = 'vector-ref'; Primitives['vector-ref'].displayName = 'vector-ref';
@ -969,10 +973,10 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'vector-set!'); 'vector-set!');
var firstArg = MACHINE.env[MACHINE.env.length-1]; var elts = MACHINE.env[MACHINE.env.length-1].elts;
var secondArg = jsnums.toFixnum(MACHINE.env[MACHINE.env.length-2]); var index = jsnums.toFixnum(MACHINE.env[MACHINE.env.length-2]);
var thirdArg = MACHINE.env[MACHINE.env.length-3]; var val = MACHINE.env[MACHINE.env.length-3];
firstArg[secondArg] = thirdArg; elts[index] = val;
return null; return null;
}; };
Primitives['vector-set!'].arity = 3; Primitives['vector-set!'].arity = 3;
@ -986,7 +990,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'vector-length'); 'vector-length');
var firstArg = MACHINE.env[jsnums.toFixnum(MACHINE.env.length-1)]; var firstArg = MACHINE.env[MACHINE.env.length-1].elts;
return firstArg.length; return firstArg.length;
}; };
Primitives['vector-length'].arity = 1; Primitives['vector-length'].arity = 1;
@ -1009,10 +1013,9 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
for(var i = 0; i < length; i++) { for(var i = 0; i < length; i++) {
arr[i] = value; arr[i] = value;
} }
arr.type='vector'; return makeVector.apply(null, arr);
return arr;
}; };
Primitives['make-vector'].arity = [1, [2, NULL]]; Primitives['make-vector'].arity = makeList(1, 2);
Primitives['make-vector'].displayName = 'make-vector'; Primitives['make-vector'].displayName = 'make-vector';
@ -1098,27 +1101,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
Primitives['equal?'].displayName = 'equal?'; Primitives['equal?'].displayName = 'equal?';
var isEqual = types.isEqual;
var isEqual = function(firstArg, secondArg) {
var lset = [firstArg], rset = [secondArg];
while (lset.length !== 0 && rset.length !== 0) {
var lhs = lset.pop();
var rhs = rset.pop();
if (lhs === rhs) {
continue;
} else if (typeof(lhs) === 'object' &&
typeof(rhs) === 'object' &&
typeof(lhs.length) === 'number' &&
typeof(rhs.length) === 'number' &&
lhs.length === rhs.length) {
lset.push.apply(lset, lhs);
rset.push.apply(rset, rhs);
} else {
return false;
}
}
return true;
};
Primitives['member'] = function(MACHINE) { Primitives['member'] = function(MACHINE) {
@ -1134,10 +1117,10 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
if (lst === NULL) { if (lst === NULL) {
return false; return false;
} }
if (isEqual(x, (lst[0]))) { if (isEqual(x, (lst.first))) {
return lst; return lst;
} }
lst = lst[1]; lst = lst.rest;
} }
}; };
Primitives['member'].arity = 2; Primitives['member'].arity = 2;
@ -1151,8 +1134,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
while(lst !== NULL) { while(lst !== NULL) {
testArgument(MACHINE, testArgument(MACHINE,
'pair', isPair, lst, 0, 'reverse'); 'pair', isPair, lst, 0, 'reverse');
rev = [lst[0], rev]; rev = makePair(lst.first, rev);
lst = lst[1]; lst = lst.rest;
} }
return rev; return rev;
}; };
@ -1389,6 +1372,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
exports['unspliceRestFromStack'] = unspliceRestFromStack; exports['unspliceRestFromStack'] = unspliceRestFromStack;
// Type predicates
exports['isNumber'] = isNumber; exports['isNumber'] = isNumber;
exports['isNatural'] = isNatural; exports['isNatural'] = isNatural;
exports['isPair'] = isPair; exports['isPair'] = isPair;
@ -1398,6 +1382,12 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
exports['isOutputStringPort'] = isOutputStringPort; exports['isOutputStringPort'] = isOutputStringPort;
exports['isEqual'] = isEqual; exports['isEqual'] = isEqual;
// Type constructors
exports['makeList'] = makeList;
exports['makePair'] = makePair;
exports['ArityAtLeast'] = ArityAtLeast; exports['ArityAtLeast'] = ArityAtLeast;
exports['isArityMatching'] = isArityMatching; exports['isArityMatching'] = isArityMatching;

View File

@ -83,7 +83,7 @@ if (! this['plt']) { this['plt'] = {}; }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
StructType = function(name, type, numberOfArgs, numberOfFields, firstField, var StructType = function(name, type, numberOfArgs, numberOfFields, firstField,
applyGuard, constructor, predicate, accessor, mutator) { applyGuard, constructor, predicate, accessor, mutator) {
this.name = name; this.name = name;
this.type = type; this.type = type;
@ -696,17 +696,24 @@ if (! this['plt']) { this['plt'] = {}; }
return b; return b;
}; };
Cons = function(f, r) {
this.f = f;
this.r = r;
//////////////////////////////////////////////////////////////////////
// Cons Pairs
var Cons = function(f, r) {
this.first = f;
this.rest = r;
}; };
Cons.prototype.reverse = function() { Cons.prototype.reverse = function() {
var lst = this; var lst = this;
var ret = Empty.EMPTY; var ret = Empty.EMPTY;
while (!lst.isEmpty()){ while (!lst.isEmpty()){
ret = Cons.makeInstance(lst.first(), ret); ret = Cons.makeInstance(lst.first, ret);
lst = lst.rest(); lst = lst.rest;
} }
return ret; return ret;
}; };
@ -715,28 +722,21 @@ if (! this['plt']) { this['plt'] = {}; }
return new Cons(f, r); return new Cons(f, r);
}; };
// FIXME: can we reduce the recursion on this? // FIXME: can we reduce the recursion on this?
Cons.prototype.isEqual = function(other, aUnionFind) { Cons.prototype.isEqual = function(other, aUnionFind) {
if (! (other instanceof Cons)) { if (! (other instanceof Cons)) {
return Logic.FALSE; return Logic.FALSE;
} }
return (isEqual(this.first(), other.first(), aUnionFind) && return (isEqual(this.first, other.first, aUnionFind) &&
isEqual(this.rest(), other.rest(), aUnionFind)); isEqual(this.rest, other.rest, aUnionFind));
};
Cons.prototype.first = function() {
return this.f;
};
Cons.prototype.rest = function() {
return this.r;
}; };
Cons.prototype.isEmpty = function() { Cons.prototype.isEmpty = function() {
return false; return false;
}; };
// Cons.append: (listof X) -> (listof X) // Cons.append: (listof X) -> (listof X)
Cons.prototype.append = function(b){ Cons.prototype.append = function(b){
if (b === Empty.EMPTY) if (b === Empty.EMPTY)
@ -744,8 +744,8 @@ if (! this['plt']) { this['plt'] = {}; }
var ret = b; var ret = b;
var lst = this.reverse(); var lst = this.reverse();
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
ret = Cons.makeInstance(lst.first(), ret); ret = Cons.makeInstance(lst.first, ret);
lst = lst.rest(); lst = lst.rest;
} }
return ret; return ret;
@ -757,8 +757,8 @@ if (! this['plt']) { this['plt'] = {}; }
var texts = []; var texts = [];
var p = this; var p = this;
while ( p instanceof Cons ) { while ( p instanceof Cons ) {
texts.push(toWrittenString(p.first(), cache)); texts.push(toWrittenString(p.first, cache));
p = p.rest(); p = p.rest;
if (typeof(p) === 'object' && cache.containsKey(p)) { if (typeof(p) === 'object' && cache.containsKey(p)) {
break; break;
} }
@ -777,8 +777,8 @@ if (! this['plt']) { this['plt'] = {}; }
var texts = []; var texts = [];
var p = this; var p = this;
while ( p instanceof Cons ) { while ( p instanceof Cons ) {
texts.push(toDisplayedString(p.first(), cache)); texts.push(toDisplayedString(p.first, cache));
p = p.rest(); p = p.rest;
if (typeof(p) === 'object' && cache.containsKey(p)) { if (typeof(p) === 'object' && cache.containsKey(p)) {
break; break;
} }
@ -787,17 +787,6 @@ if (! this['plt']) { this['plt'] = {}; }
texts.push('.'); texts.push('.');
texts.push(toDisplayedString(p, cache)); texts.push(toDisplayedString(p, cache));
} }
// while (true) {
// if ((!(p instanceof Cons)) && (!(p instanceof Empty))) {
// texts.push(".");
// texts.push(toDisplayedString(p, cache));
// break;
// }
// if (p.isEmpty())
// break;
// texts.push(toDisplayedString(p.first(), cache));
// p = p.rest();
// }
return "(" + texts.join(" ") + ")"; return "(" + texts.join(" ") + ")";
}; };
@ -809,8 +798,8 @@ if (! this['plt']) { this['plt'] = {}; }
node.appendChild(document.createTextNode("(")); node.appendChild(document.createTextNode("("));
var p = this; var p = this;
while ( p instanceof Cons ) { while ( p instanceof Cons ) {
appendChild(node, toDomNode(p.first(), cache)); appendChild(node, toDomNode(p.first, cache));
p = p.rest(); p = p.rest;
if ( p !== Empty.EMPTY ) { if ( p !== Empty.EMPTY ) {
appendChild(node, document.createTextNode(" ")); appendChild(node, document.createTextNode(" "));
} }
@ -823,27 +812,27 @@ if (! this['plt']) { this['plt'] = {}; }
appendChild(node, document.createTextNode(" ")); appendChild(node, document.createTextNode(" "));
appendChild(node, toDomNode(p, cache)); appendChild(node, toDomNode(p, cache));
} }
// while (true) {
// if ((!(p instanceof Cons)) && (!(p instanceof Empty))) {
// appendChild(node, document.createTextNode(" "));
// appendChild(node, document.createTextNode("."));
// appendChild(node, document.createTextNode(" "));
// appendChild(node, toDomNode(p, cache));
// break;
// }
// if (p.isEmpty())
// break;
// appendChild(node, toDomNode(p.first(), cache));
// p = p.rest();
// if (! p.isEmpty()) {
// appendChild(node, document.createTextNode(" "));
// }
// }
node.appendChild(document.createTextNode(")")); node.appendChild(document.createTextNode(")"));
return node; return node;
}; };
// isList: Any -> Boolean
// Returns true if x is a list (a chain of pairs terminated by EMPTY).
var isList = function(x) {
while (x !== Empty.EMPTY) {
if (x instanceof Cons){
x = x.rest;
} else {
return false;
}
}
return true;
};
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -1953,22 +1942,22 @@ String.prototype.toDisplayedString = function(cache) {
var makeList = function(args) { var makeList = function() {
var result = Empty.EMPTY; var result = Empty.EMPTY;
for(var i = args.length-1; i >= 0; i--) { for(var i = arguments.length-1; i >= 0; i--) {
result = Cons.makeInstance(args[i], result); result = Cons.makeInstance(arguments[i], result);
} }
return result; return result;
}; };
var makeVector = function(args) { var makeVector = function(arguments) {
return Vector.makeInstance(args.length, args); return Vector.makeInstance(arguments.length, arguments);
}; };
var makeVectorImmutable = function(args) { var makeVectorImmutable = function(arguments) {
var v = Vector.makeInstance(args.length, args); var v = Vector.makeInstance(arguments.length, arguments);
v.mutable = false; v.mutable = false;
return v; return v;
}; };
@ -2000,8 +1989,8 @@ String.prototype.toDisplayedString = function(cache) {
var makeHashEq = function(lst) { var makeHashEq = function(lst) {
var newHash = new EqHashTable(); var newHash = new EqHashTable();
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
newHash.hash.put(lst.first().first(), lst.first().rest()); newHash.hash.put(lst.first.first, lst.first.rest);
lst = lst.rest(); lst = lst.rest;
} }
return newHash; return newHash;
} }
@ -2010,8 +1999,8 @@ String.prototype.toDisplayedString = function(cache) {
var makeHashEqual = function(lst) { var makeHashEqual = function(lst) {
var newHash = new EqualHashTable(); var newHash = new EqualHashTable();
while ( !lst.isEmpty() ) { while ( !lst.isEmpty() ) {
newHash.hash.put(lst.first().first(), lst.first().rest()); newHash.hash.put(lst.first.first, lst.first.rest);
lst = lst.rest(); lst = lst.rest;
} }
return newHash; return newHash;
} }
@ -2040,10 +2029,10 @@ String.prototype.toDisplayedString = function(cache) {
} }
if (types.isPair(x)) { if (types.isPair(x)) {
var consPair = types.cons(x.first(), x.rest()); var consPair = types.cons(x.first, x.rest);
objectHash.put(x, consPair); objectHash.put(x, consPair);
consPair.f = readerGraph(x.first(), objectHash, n+1); consPair.f = readerGraph(x.first, objectHash, n+1);
consPair.r = readerGraph(x.rest(), objectHash, n+1); consPair.r = readerGraph(x.rest, objectHash, n+1);
return consPair; return consPair;
} }
@ -2152,6 +2141,7 @@ String.prototype.toDisplayedString = function(cache) {
types.isChar = function(x) { return x instanceof Char; }; types.isChar = function(x) { return x instanceof Char; };
types.isString = isString; types.isString = isString;
types.isPair = function(x) { return x instanceof Cons; }; types.isPair = function(x) { return x instanceof Cons; };
types.isList = isList;
types.isEmpty = function(x) { return x === Empty.EMPTY; }; types.isEmpty = function(x) { return x === Empty.EMPTY; };
types.isVector = function(x) { return x instanceof Vector; }; types.isVector = function(x) { return x instanceof Vector; };
types.isBox = function(x) { return x instanceof Box; }; types.isBox = function(x) { return x instanceof Box; };

View File

@ -11,7 +11,8 @@
current-root-path current-root-path
current-warn-unimplemented-kernel-primitive current-warn-unimplemented-kernel-primitive
current-seen-unimplemented-kernel-primitives current-seen-unimplemented-kernel-primitives
current-kernel-module-locator?) current-kernel-module-locator?
current-compress-javascript?)
@ -47,6 +48,9 @@
(: current-compress-javascript? (Parameterof Boolean))
(define current-compress-javascript? (make-parameter #f))