aboutsummaryrefslogtreecommitdiffstats
path: root/csc/cps-test.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-06-26 20:14:19 -0700
committerRose Hogenson <rhogenson@posteo.net>2022-06-26 20:14:19 -0700
commit52da9c556a170ed8e5f811c3acd56088baf94c80 (patch)
tree938762f3056d9b14b1a2dfba69cff6d30a7ca836 /csc/cps-test.csc
parentMore CPS. (diff)
downloadchromatopelma-52da9c556a170ed8e5f811c3acd56088baf94c80.tar.zst
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.
Diffstat (limited to 'csc/cps-test.csc')
-rw-r--r--csc/cps-test.csc59
1 files changed, 59 insertions, 0 deletions
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))))))