baffled: I'm getting a different set of parse trees out of earley, and not enough of them.
This commit is contained in:
parent
d209f3113b
commit
2148cb047e
|
@ -319,7 +319,7 @@ EOF
|
||||||
(let*: ([test : PrimitiveTest (TestAndBranchStatement-op stmt)])
|
(let*: ([test : PrimitiveTest (TestAndBranchStatement-op stmt)])
|
||||||
(cond
|
(cond
|
||||||
[(eq? test 'false?)
|
[(eq? test 'false?)
|
||||||
(format "if (! ~a) { ~a }"
|
(format "if (~a === false) { ~a }"
|
||||||
(assemble-reg (make-Reg (TestAndBranchStatement-register stmt)))
|
(assemble-reg (make-Reg (TestAndBranchStatement-register stmt)))
|
||||||
(assemble-jump (make-Label (TestAndBranchStatement-label stmt))))]
|
(assemble-jump (make-Label (TestAndBranchStatement-label stmt))))]
|
||||||
[(eq? test 'one?)
|
[(eq? test 'one?)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
|
|
||||||
;; The following are primitives that the compiler knows about:
|
;; The following are primitives that the compiler knows about:
|
||||||
(define-type KernelPrimitiveName (U) #;(U '+
|
(define-type KernelPrimitiveName (U '+
|
||||||
'-
|
'-
|
||||||
'*
|
'*
|
||||||
'/
|
'/
|
||||||
|
|
46
runtime.js
46
runtime.js
|
@ -34,7 +34,8 @@
|
||||||
|
|
||||||
|
|
||||||
var isPair = function(x) { return (typeof(x) == 'object' &&
|
var isPair = function(x) { return (typeof(x) == 'object' &&
|
||||||
x.length === 2) };
|
x.length === 2 &&
|
||||||
|
x.type !== 'vector') };
|
||||||
var isList = function(x) {
|
var isList = function(x) {
|
||||||
while (x !== NULL) {
|
while (x !== NULL) {
|
||||||
if (typeof(x) == 'object' && x.length === 2) {
|
if (typeof(x) == 'object' && x.length === 2) {
|
||||||
|
@ -47,7 +48,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var isVector = function(x) { return (typeof(x) == 'object' &&
|
var isVector = function(x) { return (typeof(x) == 'object' &&
|
||||||
x.length !== undefined) };
|
x.type === 'vector') };
|
||||||
|
|
||||||
var Machine = function() {
|
var Machine = function() {
|
||||||
this.callsBeforeTrampoline = 100;
|
this.callsBeforeTrampoline = 100;
|
||||||
|
@ -739,6 +740,7 @@
|
||||||
for (i = 0; i < MACHINE.argcount; i++) {
|
for (i = 0; i < MACHINE.argcount; i++) {
|
||||||
result.push(MACHINE.env[MACHINE.env.length-1-i]);
|
result.push(MACHINE.env[MACHINE.env.length-1-i]);
|
||||||
}
|
}
|
||||||
|
result.type = 'vector';
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Primitives['vector'].arity = new ArityAtLeast(0);
|
Primitives['vector'].arity = new ArityAtLeast(0);
|
||||||
|
@ -769,6 +771,7 @@
|
||||||
result.push(firstArg[0]);
|
result.push(firstArg[0]);
|
||||||
firstArg = firstArg[1];
|
firstArg = firstArg[1];
|
||||||
}
|
}
|
||||||
|
result.type='vector';
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Primitives['list->vector'].arity = 1;
|
Primitives['list->vector'].arity = 1;
|
||||||
|
@ -835,6 +838,7 @@
|
||||||
for(var i = 0; i < length; i++) {
|
for(var i = 0; i < length; i++) {
|
||||||
arr[i] = value;
|
arr[i] = value;
|
||||||
}
|
}
|
||||||
|
arr.type='vector';
|
||||||
return arr;
|
return arr;
|
||||||
};
|
};
|
||||||
Primitives['make-vector'].arity = [1, [2, NULL]];
|
Primitives['make-vector'].arity = [1, [2, NULL]];
|
||||||
|
@ -969,6 +973,28 @@
|
||||||
Primitives['member'].displayName = 'member';
|
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
|
// recomputeGas: state number -> number
|
||||||
var recomputeMaxNumBouncesBeforeYield = function(MACHINE, observedDelay) {
|
var recomputeMaxNumBouncesBeforeYield = function(MACHINE, observedDelay) {
|
||||||
// We'd like to see a delay of DESIRED_DELAY_BETWEEN_BOUNCES so
|
// 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 trampoline = function(MACHINE, initialJump) {
|
||||||
var thunk = initialJump;
|
var thunk = initialJump;
|
||||||
|
|
|
@ -144,6 +144,11 @@ EOF
|
||||||
(test '(displayln (add1 1))
|
(test '(displayln (add1 1))
|
||||||
"2\n")
|
"2\n")
|
||||||
|
|
||||||
|
|
||||||
|
(test '(displayln (if 0 1 2))
|
||||||
|
"1\n")
|
||||||
|
|
||||||
|
|
||||||
(test/exn '(displayln (add1 "0"))
|
(test/exn '(displayln (add1 "0"))
|
||||||
"Error: add1: expected number as argument 1 but received 0")
|
"Error: add1: expected number as argument 1 but received 0")
|
||||||
|
|
||||||
|
@ -460,6 +465,16 @@ EOF
|
||||||
"true\n")
|
"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")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -820,8 +820,6 @@
|
||||||
(lambda (l)
|
(lambda (l)
|
||||||
(map (lambda (x) (list x x)) l)))))
|
(map (lambda (x) (list x x)) l)))))
|
||||||
(let ((x (p (vector->list (make-vector k 'a)))))
|
(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)))
|
(display (length (parse->trees x 's '0 k)))
|
||||||
(newline)))))
|
(newline)))))
|
||||||
(test '12))
|
(test '12))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user