#lang racket (require "test-util.rkt") (require "uniquify.rkt") (require "c2.rkt") (test-eq ((uniquify-exp (make-immutable-hash) (make-immutable-hash)) `(read)) `(#hash() (read))) (let ([tbl (hash-set (make-immutable-hash) `x 1)]) (test-eq ((uniquify-exp tbl tbl) `x) `(#hash((x . 1)) x.1))) (let ([tbl (hash-set (make-immutable-hash) `x 1)]) (test-eq ((uniquify-exp tbl tbl) `(let ([x 2]) 3)) `(#hash((x . 2)) (let ([x.2 2]) 3)))) (test-eq ((uniquify-exp (make-immutable-hash) (make-immutable-hash)) `(let ([x 2]) (+ x 3))) `(#hash((x . 1)) (let ([x.1 2]) (+ x.1 3)))) (test-eq (uniquify `(program () (let ([x 32]) (+ (let ([x 10]) x) x)))) `(#hash((x . 2)) (program () (let ([x.1 32]) (+ (let ([x.2 10]) x.2) x.1))))) (test-eq (uniquify `(program () (let ([x 32]) (- x)))) `(#hash((x . 1)) (program () (let ([x.1 32]) (- x.1))))) (test-eq (uniquify `(program () (let ([x 32]) (+ (let ([x 10]) x) (let ([x 3]) x) x)))) `(#hash((x . 3)) (program () (let ([x.1 32]) (+ (let ([x.2 10]) x.2) (let ([x.3 3]) x.3) x.1))))) (test-eq (uniquify `(program () (let ([x (let ([x 4]) (+ x 1))]) (+ x 2)))) `(#hash((x . 2)) (program () (let ([x.1 (let ([x.2 4]) (+ x.2 1))]) (+ x.1 2))))) (define p1 `(program () (let ([x 32]) (+ (+ (let ([x 10]) x) (let ([x 3]) x)) x)))) (define env1 '()) (define p2 `(program () (let ([x (let ([y 9]) y)]) (+ x y)))) (define env2 '((y 5))) (for ([program (list p1 p2)] [env (list env1 env2)]) (test-eq ((interp-R1 env) program) ((interp-R1 env) (cadr (uniquify program)))))