aboutsummaryrefslogtreecommitdiffstats
path: root/csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-07-24 20:29:19 -0700
committerRose Hogenson <rhogenson@posteo.net>2022-07-24 20:29:19 -0700
commitac23fca796d6dc6fc7aab0ac5bdf8987aa490761 (patch)
tree05280a50eb2f9fb4229bb0e9d2be037ca4aa3d5c /csc
parent498040c3d1532bb6de01dbbb55348f631c3745d6 (diff)
downloadchromatopelma-ac23fca796d6dc6fc7aab0ac5bdf8987aa490761.tar.zst
Write a test for codegen.
I'm not sure yet how to test regalloc.
Diffstat (limited to 'csc')
-rw-r--r--csc/codegen-test.csc17
-rw-r--r--csc/codegen.csc3
-rw-r--r--csc/ir2.csc1
-rw-r--r--csc/macros-test.csc3
4 files changed, 18 insertions, 6 deletions
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))))