diff --git a/tests/eval.rkt b/tests/eval.rkt index 8e9ac3b..c142e70 100644 --- a/tests/eval.rkt +++ b/tests/eval.rkt @@ -27,8 +27,17 @@ (define (exp-final-node e) (program-final-node (exp->program e))) +(define rec-program + '((define (pair x y f) ((f x) y)) + (define (fst p) (p K)) + (define (snd p) (p K1)) + (define (f x y) + (letrec ((a ((pair x) b)) (b ((pair y) a))) (fst (snd (snd (snd a)))))) + (define (main) ((f 3) 4)))) + (check-equal? (exp-final-node (ap-exp 'S 'K 'K 3)) 3) (check-equal? (exp-final-node (ap-exp 'K 100 99)) 100) (check-equal? (exp-final-node `(let ((x ,(ap-exp 'S 'K 'K 3)) (y 5)) ,(ap-exp 'K 'x 'x))) 3) (check-equal? (exp-final-node `(let ((x ,(ap-exp 'S 'K 'K 3)) (y 5)) ,(ap-exp 'K 'y 'x))) 5) (check-equal? (exp-final-node `(letrec ((y x) (x ,(ap-exp 'S 'K 'K 3))) ,(ap-exp 'K 'y 'x))) 3) +(check-equal? (program-final-node rec-program) 4) diff --git a/typed-parser.rkt b/typed-parser.rkt index dfc67b3..be60d1f 100644 --- a/typed-parser.rkt +++ b/typed-parser.rkt @@ -1,7 +1,25 @@ #lang typed/racket (require "ast.rkt") +(require racket/cmdline) (require/typed "parser.rkt" [parse-from-port (-> Input-Port CoreProgram)] [parse-from-string (-> String CoreProgram)]) + + +(module* main #f + (: filename Path-String) + (define filename + (let ([result (command-line + #:program "core-parser" + #:args (filename) + filename)]) + (if (path-string? result) + result + (error "Commandline parser returned unexpected results")))) + + + (pretty-print (parse-from-port + (open-input-file filename)))) + (provide parse-from-port parse-from-string)