From ac23fca796d6dc6fc7aab0ac5bdf8987aa490761 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 24 Jul 2022 20:29:19 -0700 Subject: Write a test for codegen. I'm not sure yet how to test regalloc. --- csc/codegen-test.csc | 17 ++++++++++++++--- csc/codegen.csc | 3 ++- csc/ir2.csc | 1 + csc/macros-test.csc | 3 +-- 4 files changed, 18 insertions(+), 6 deletions(-) (limited to 'csc') diff --git a/csc/codegen-test.csc b/csc/codegen-test.csc index 9c47661..b85ebc3 100644 --- a/csc/codegen-test.csc +++ b/csc/codegen-test.csc @@ -8,10 +8,14 @@ make-fix make-primitive make-variable) + (only (csc loop) + loop + return) (only (csc match) match) (only (csc testing) - assert-equal) + assert-equal + test) (csc codegen)) @@ -21,7 +25,12 @@ (match expr (('label _) #t) (_ #f))) - (lambda (expr) 'label)))) + (lambda (expr) 'label)) + (cons (lambda (expr) + (match expr + (('local _) #t) + (_ #f))) + (lambda (expr) 'local)))) (define (test-var) @@ -30,7 +39,9 @@ (test codegen-apply (assert-equal - 'something + '((peek (local #f) (local #f) (const 5)) + (mov (local #f) (const 10)) + (jmp (local #f))) (ir2->ir3 (make-fix '() (make-primitive 'peek (list *globals* (make-constant 5)) (list (test-var)) diff --git a/csc/codegen.csc b/csc/codegen.csc index c51420e..aab8e23 100644 --- a/csc/codegen.csc +++ b/csc/codegen.csc @@ -27,6 +27,7 @@ closure-arguments closure-body closure-name + constant-expression constant? fix-body fix-functions @@ -186,7 +187,7 @@ else if (globals? arg) do (set! in->out (insert in->out 0 i)) else if (constant? arg) - collect (list 'mov (list 'local i) (list 'const arg)) + collect (list 'mov (list 'local i) (list 'const (constant-expression arg))) else if (label? arg) collect (list 'mov (list 'local i) (list 'label (translate-label arg))) else if (library-ref? arg) diff --git a/csc/ir2.csc b/csc/ir2.csc index 642b86c..4e4c42e 100644 --- a/csc/ir2.csc +++ b/csc/ir2.csc @@ -68,6 +68,7 @@ (only (csc ir1) %constant %library-ref + constant-expression constant? lexical-ref-gensym lexical-ref-name diff --git a/csc/macros-test.csc b/csc/macros-test.csc index d1b8d2c..b2e2f3f 100644 --- a/csc/macros-test.csc +++ b/csc/macros-test.csc @@ -15,7 +15,6 @@ %library-ref %sequence call? - constant-expression constant? define-syntax? if? @@ -249,7 +248,7 @@ (test builtin-case-lambda-defines (assert-equal (make-lambda (list (test-ref 'x)) #f - (make-letrec #t '(a b) #f + (make-letrec #t '(a b) (list (gensym) (gensym)) (list (make-constant 6) (test-ref 'a)) (make-sequence (make-constant #f) (make-constant 7)))) -- cgit v1.3.1