baffled: I'm getting a different set of parse trees out of earley, and not enough of them.

This commit is contained in:
Danny Yoo 2011-04-14 16:26:06 -04:00
parent d209f3113b
commit 2148cb047e
5 changed files with 45 additions and 22 deletions

View File

@ -319,7 +319,7 @@ EOF
(let*: ([test : PrimitiveTest (TestAndBranchStatement-op stmt)])
(cond
[(eq? test 'false?)
(format "if (! ~a) { ~a }"
(format "if (~a === false) { ~a }"
(assemble-reg (make-Reg (TestAndBranchStatement-register stmt)))
(assemble-jump (make-Label (TestAndBranchStatement-label stmt))))]
[(eq? test 'one?)

View File

@ -12,7 +12,7 @@
;; The following are primitives that the compiler knows about:
(define-type KernelPrimitiveName (U) #;(U '+
(define-type KernelPrimitiveName (U '+
'-
'*
'/

View File

@ -34,7 +34,8 @@
var isPair = function(x) { return (typeof(x) == 'object' &&
x.length === 2) };
x.length === 2 &&
x.type !== 'vector') };
var isList = function(x) {
while (x !== NULL) {
if (typeof(x) == 'object' && x.length === 2) {
@ -47,7 +48,7 @@
};
var isVector = function(x) { return (typeof(x) == 'object' &&
x.length !== undefined) };
x.type === 'vector') };
var Machine = function() {
this.callsBeforeTrampoline = 100;
@ -739,6 +740,7 @@
for (i = 0; i < MACHINE.argcount; i++) {
result.push(MACHINE.env[MACHINE.env.length-1-i]);
}
result.type = 'vector';
return result;
};
Primitives['vector'].arity = new ArityAtLeast(0);
@ -769,6 +771,7 @@
result.push(firstArg[0]);
firstArg = firstArg[1];
}
result.type='vector';
return result;
};
Primitives['list->vector'].arity = 1;
@ -835,6 +838,7 @@
for(var i = 0; i < length; i++) {
arr[i] = value;
}
arr.type='vector';
return arr;
};
Primitives['make-vector'].arity = [1, [2, NULL]];
@ -969,6 +973,28 @@
Primitives['member'].displayName = 'member';
Primitives['reverse'] = function(MACHINE) {
var rev = NULL;
var lst = MACHINE.env[MACHINE.env.length-1];
while(lst !== NULL) {
testArgument(MACHINE,
'pair', isPair, lst, 0, 'reverse');
rev = [lst[0], rev];
lst = lst[1];
}
return rev;
};
Primitives['reverse'].arity = 1;
Primitives['reverse'].displayName = 'reverse';
// recomputeGas: state number -> number
var recomputeMaxNumBouncesBeforeYield = function(MACHINE, observedDelay) {
// We'd like to see a delay of DESIRED_DELAY_BETWEEN_BOUNCES so
@ -987,22 +1013,6 @@
Primitives['reverse'] = function(MACHINE) {
var rev = NULL;
var lst = MACHINE.env[MACHINE.env.length-1];
while(lst !== NULL) {
testArgument(MACHINE,
'pair', isPair, lst, 0, 'reverse');
rev = [lst[0], rev];
lst = lst[1];
}
return rev;
};
Primitives['reverse'].arity = 1;
Primitives['reverse'].displayName = 'reverse';
var trampoline = function(MACHINE, initialJump) {
var thunk = initialJump;

View File

@ -144,6 +144,11 @@ EOF
(test '(displayln (add1 1))
"2\n")
(test '(displayln (if 0 1 2))
"1\n")
(test/exn '(displayln (add1 "0"))
"Error: add1: expected number as argument 1 but received 0")
@ -459,6 +464,16 @@ EOF
'(1 2 (3))))
"true\n")
(test '(displayln (equal? (list 1 2 (vector 3))
(list 1 2 (vector 3))))
"true\n")
(test '(displayln (equal? (list 1 2 (vector 4))
(list 1 2 (vector 3))))
"false\n")

View File

@ -820,8 +820,6 @@
(lambda (l)
(map (lambda (x) (list x x)) l)))))
(let ((x (p (vector->list (make-vector k 'a)))))
;(displayln x)
;(displayln (parse->trees x 's '0 k)) ;; dyoo : temporary
(display (length (parse->trees x 's '0 k)))
(newline)))))
(test '12))