From 52da9c556a170ed8e5f811c3acd56088baf94c80 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 26 Jun 2022 20:14:19 -0700 Subject: Finish CPS. Wow we actually finished CPS. Next is closure conversion, then codegen, and then we should be able to run some end to end tests. Then we can look at garbage collection, and from there continue building features down the long road to self hosting. --- csc/cps-test.csc | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'csc/cps-test.csc') diff --git a/csc/cps-test.csc b/csc/cps-test.csc index ea1d177..d51d10c 100644 --- a/csc/cps-test.csc +++ b/csc/cps-test.csc @@ -6,6 +6,9 @@ make-constant make-define-syntax make-if + make-lambda + make-lambda-case + make-letrec make-lexical-ref make-lexical-set make-library-ref @@ -15,9 +18,11 @@ make-atom make-branch make-call-closure + make-closure make-kargs make-klabel make-ktail + make-lambda-args make-update) (only (csc loop) loop @@ -130,3 +135,57 @@ (cons 2 (make-klabel (make-atom (make-constant 2) 1)))) (soup->alist (ir1->ir2 (make-sequence (make-constant 1) (make-constant 2)))))) + + +(test closure + (assert-equal soup=? + (list + (cons 0 (make-klabel + (make-closure + (list (make-lambda-args 2 #t 3)) + 1))) + (cons 1 (make-ktail)) + (cons 2 (make-ktail)) + (cons 3 (make-kargs (list (make-lexical-ref 'a #f) + (make-lexical-ref 'b #f) + (make-lexical-ref 'c #f)) + (make-atom (make-constant 5) 2)))) + (soup->alist (ir1->ir2 (make-lambda + (make-lambda-case + '(a b) + 'c + '(#f #f #f) + (make-constant 5) + #f)))))) + + +(test letrec-to-lambda + (assert-equal soup=? + (list + ; God help you when it's time to debug this test. + (cons 0 (make-klabel + (make-closure + (list + (make-lambda-args 1 #f 7)) + 3))) + (cons 1 (make-ktail)) + (cons 2 (make-kargs (list (make-lexical-ref 'generated-symbol #f)) + (make-call-closure + (make-lexical-ref 'generated-symbol #f) + (list (make-lexical-ref 'generated-symbol #f)) + 1))) + (cons 3 (make-kargs (list (make-lexical-ref 'generated-symbol #f)) + (make-atom (make-constant #f) 2))) + (cons 4 (make-ktail)) + (cons 5 (make-klabel + (make-atom (make-constant 2) 4))) + (cons 6 (make-kargs (list (make-lexical-ref 'generated-symbol #f)) + (make-update (make-lexical-ref 'a #f) (make-lexical-ref 'generated-symbol #f) 5))) + (cons 7 (make-kargs (list (make-lexical-ref 'a #f)) + (make-atom (make-constant 1) 6)))) + (soup->alist (ir1->ir2 (make-letrec + #t + '(a) + '(#f) + (list (make-constant 1)) + (make-constant 2)))))) -- cgit v1.3.1