Skip to content

Instantly share code, notes, and snippets.

@aiwen324
Created February 6, 2018 21:07
Show Gist options
  • Save aiwen324/2c308e91c2803fedd79b37dda239ee66 to your computer and use it in GitHub Desktop.
Save aiwen324/2c308e91c2803fedd79b37dda239ee66 to your computer and use it in GitHub Desktop.
test code for L2
(module+ test
(check-equal? (L1→L2 '(L1: var +)) (compiled:L2 '((L2: closure make_add)) '()))
(check-equal? (L1→L2 '(L1: var 3)) (compiled:L2 '((L2: variable 3)) '()))
(check-equal? (L1→L2 '(L1: λ 0 (L1: var 0)))
(compiled:L2 '((L2: closure lambda_0)) '((lambda_0 ((L2: variable 0))))))
(check-equal? (L1→L2 '(L1: λ 1 (L1: λ 0 (L1: var 0))))
(compiled:L2 '((L2: closure lambda_1))
'((lambda_1 ((L2: closure lambda_0)))
(lambda_0 ((L2: variable 0))))))
(check-equal? (L1→L2 '(L1: λ 2 (L1: λ 1 (L1: λ 0 (L1: var 2)))))
(compiled:L2 '((L2: closure lambda_2))
'((lambda_2 ((L2: closure lambda_1)))
(lambda_1 ((L2: closure lambda_0)))
(lambda_0 ((L2: variable 2))))))
(println "pass basic λ test")
(check-equal? (L1→L2 '(L1: app (L1: var 1) (L1: var 0)))
(compiled:L2 '((L2: variable 1)
(L2: push_result)
(L2: variable 0)
(L2: call))
'()))
(check-equal? (L1→L2 '(L1: λ 0 (L1: app (L1: var 1) (L1: var 0))))
(compiled:L2 '((L2: closure lambda_0))
'((lambda_0 ((L2: variable 1)
(L2: push_result)
(L2: variable 0)
(L2: call))))))
(check-equal? (L1→L2 '(L1: λ 1 (L1: λ 0 (L1: app (L1: var 1) (L1: var 0)))))
(compiled:L2 '((L2: closure lambda_1))
'((lambda_1 ((L2: closure lambda_0)))
(lambda_0 ((L2: variable 1)
(L2: push_result)
(L2: variable 0)
(L2: call))))))
(check-equal? (L1→L2 '(L1: app (L1: λ 1 (L1: λ 0 (L1: app (L1: var 1) (L1: var 0))))
(L1: λ 2 (L1: var 0))))
(compiled:L2 '((L2: closure lambda_1)
(L2: push_result)
(L2: closure lambda_2)
(L2: call))
'((lambda_1 ((L2: closure lambda_0)))
(lambda_0 ((L2: variable 1)
(L2: push_result)
(L2: variable 0)
(L2: call)))
(lambda_2 ((L2: variable 0))))))
(check-equal? (L1→L2 '(L1: app (L1: λ 0 (L1: var 0)) (L1: datum 3)))
(compiled:L2 '((L2: closure lambda_0)
(L2: push_result)
(L2: set_result 3)
(L2: call))
'((lambda_0 ((L2: variable 0))))))
(println "pass test for app")
(check-equal? (L1→L2 '(L1: set! 1 (L1: var 0)))
(compiled:L2 '((L2: variable 0)
(L2: set 1))
'()))
(check-equal? (L1→L2 '(L1: set! 1 (L1: λ 0 (L1: var 0))))
(compiled:L2 '((L2: closure lambda_0)
(L2: set 1))
'((lambda_0 ((L2: variable 0))))))
(check-equal? (L1→L2 '(L1: set! 1 (L1: app (L1: λ 1 (L1: λ 0 (L1: app (L1: var 1) (L1: var 0))))
(L1: λ 2 (L1: var 0)))))
(compiled:L2 '((L2: closure lambda_1)
(L2: push_result)
(L2: closure lambda_2)
(L2: call)
(L2: set 1))
'((lambda_1 ((L2: closure lambda_0)))
(lambda_0 ((L2: variable 1)
(L2: push_result)
(L2: variable 0)
(L2: call)))
(lambda_2 ((L2: variable 0))))))
(println "pass test for set!")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment