diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-07-25 20:54:17 -0700 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-07-25 20:54:17 -0700 |
| commit | e1da69922aa0869e136c91def848b8fc028f3a39 (patch) | |
| tree | e10d1d6560d7f7be39362e287cb318ec33b22f17 /csc/linker-test.csc | |
| parent | Slightly improve loop. (diff) | |
| download | chromatopelma-e1da69922aa0869e136c91def848b8fc028f3a39.tar.zst | |
Re-write the linker.
Diffstat (limited to 'csc/linker-test.csc')
| -rw-r--r-- | csc/linker-test.csc | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/csc/linker-test.csc b/csc/linker-test.csc index 084e9ae..cc07a74 100644 --- a/csc/linker-test.csc +++ b/csc/linker-test.csc @@ -1,24 +1,63 @@ (import (scheme base) - (only (csc encoding) encode) + (only (csc format) + sprintf) + (only (csc hash-map) + alist->map + hash-bytevector + make-comparer + make-map) + (only (csc list) + all) (only (csc testing) assert-equal test) (csc linker)) -(test link-if +(define compare-globals + (make-comparer + (lambda (x) + (hash-bytevector (string->utf8 (sprintf "{}" x)))) + (lambda (x y) + (cond + ((equal? x y) 0) + ((string<? (sprintf "{}" x) (sprintf "{}" y)) -1) + (else 1))))) + + +(test link-labels (assert-equal - (encode '((const 5) (const 1) (if 2) (const 5) add exit)) - (link '((const 5) (const 1) (if "label1") (const 5) add (label "label1") exit)))) + '((jmp (const 1)) + (jmp (const 0))) + (link + '(((label 0) + (jmp (label 1)) + (label 1) + (jmp (label 0)))) + (make-map compare-globals)))) -(test link-backwards-if +(test link-labels-are-unique-per-program (assert-equal - (encode '((const 10) (const 5) add (if -3))) - (link '((const 10) (label "label1") (const 5) add (if "label1"))))) + '((jmp (const 1)) + (jmp (const 0)) + (jmp (const 3)) + (jmp (const 2))) + (link + '(((label 0) + (jmp (label 1)) + (label 1) + (jmp (label 0))) + ((label 0) + (jmp (label 1)) + (label 1) + (jmp (label 0)))) + (make-map compare-globals)))) -(test link-call +(test link-globals (assert-equal - (encode '((call 3) (const 10) exit (const 5) exit)) - (link '((call "label1") (const 10) (label "label0") exit (label "label1") (const 5) exit)))) + '((peek (local 0) (const 10))) + (link + '(((peek (local 0) (global cons (csc based))))) + (alist->map compare-globals '(((global cons (csc based)) . 10)))))) |
