Add a unit test for the supercombinators
This commit is contained in:
parent
1a39377ca1
commit
4176d439e5
1 changed files with 30 additions and 0 deletions
30
tests/eval.rkt
Normal file
30
tests/eval.rkt
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#lang typed/racket
|
||||||
|
(require "../semantics.rkt")
|
||||||
|
(require "../ast.rkt")
|
||||||
|
(require typed/rackunit)
|
||||||
|
|
||||||
|
(: exp->program (-> CoreExpr CoreProgram))
|
||||||
|
(define (exp->program i)
|
||||||
|
(list `(define (main) ,i)))
|
||||||
|
|
||||||
|
(define-syntax ap-exp
|
||||||
|
(syntax-rules ()
|
||||||
|
[(ap-exp a) a]
|
||||||
|
[(ap-exp a b c ...)
|
||||||
|
(ap-exp (list a b) c ...)]))
|
||||||
|
|
||||||
|
(: program-final-node (-> CoreProgram Node))
|
||||||
|
(define (program-final-node prog)
|
||||||
|
(let* ([st (last (eval-state (compile-core prog)))]
|
||||||
|
[stack (State-stack st)]
|
||||||
|
[heap (State-heap st)])
|
||||||
|
(if (null? stack)
|
||||||
|
(error "impossible: not a final node")
|
||||||
|
(lookup-node heap (first stack)))))
|
||||||
|
|
||||||
|
(: exp-final-node (-> CoreExpr Node))
|
||||||
|
(define (exp-final-node e)
|
||||||
|
(program-final-node (exp->program e)))
|
||||||
|
|
||||||
|
(check-equal? (exp-final-node (ap-exp 'S 'K 'K 3)) 3)
|
||||||
|
(check-equal? (exp-final-node (ap-exp 'K 100 99)) 100)
|
Loading…
Add table
Add a link
Reference in a new issue