diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-07-25 20:54:54 -0700 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-07-25 20:54:54 -0700 |
| commit | 63a7c0103c47e3735f7d21e9666124924be9e18e (patch) | |
| tree | 87cf9aa62e2978ec86ffa19c41c8c364d8d85e74 /csc/encoding-test.csc | |
| parent | e1da69922aa0869e136c91def848b8fc028f3a39 (diff) | |
| download | chromatopelma-63a7c0103c47e3735f7d21e9666124924be9e18e.tar.zst | |
Re-write the encoding library.
I greatly improved the library, and changed it to expect register
bytecode instead of stack-based.
Diffstat (limited to 'csc/encoding-test.csc')
| -rw-r--r-- | csc/encoding-test.csc | 118 |
1 files changed, 60 insertions, 58 deletions
diff --git a/csc/encoding-test.csc b/csc/encoding-test.csc index a7f4ace..fb9fe21 100644 --- a/csc/encoding-test.csc +++ b/csc/encoding-test.csc @@ -1,117 +1,119 @@ (import (scheme base) - (only (csc testing) test assert-equal) + (only (csc testing) + assert-equal + test) (csc encoding)) -(test encode-const +(test encode-mov (assert-equal - '(#xf2 #x3 0 0 0 0 0 0 #xf6 #xff #xff #xff #xff #xff #xff #xff) - (encode '((const -10))))) + #u8(0 1 2) + (encode '((mov (local 1) (local 2)))))) -(test encode-add +(test encode-int (assert-equal - '(#xfc #x3 0 0 0 0 0 0) - (encode '(add)))) + #u8(2 1 #x15 0 0 0 0 0 0 0) + (encode '((mov (local 1) (const 10)))))) -(test encode-sub +(test encode-negative-int (assert-equal - '(#x6 #x4 0 0 0 0 0 0) - (encode '(sub)))) + #u8(2 1 #xed #xff #xff #xff #xff #xff #xff #xff) + (encode '((mov (local 1) (const -10)))))) -(test encode-mul +(test encode-true (assert-equal - '(#x10 #x4 0 0 0 0 0 0) - (encode '(mul)))) + #u8(2 1 #xa 0 0 0 0 0 0 0) + (encode '((mov (local 1) (const #t)))))) -(test encode-div +(test encode-false (assert-equal - '(#x1a #x4 0 0 0 0 0 0) - (encode '(div)))) + #u8(2 1 #x2 0 0 0 0 0 0 0) + (encode '((mov (local 1) (const #f)))))) -(test encode-mod +(test encode-nil (assert-equal - '(#x24 #x4 0 0 0 0 0 0) - (encode '(mod)))) + #u8(2 1 #x12 0 0 0 0 0 0 0) + (encode '((mov (local 1) (const ())))))) -(test encode-alloc +(test encode-jmpif (assert-equal - '(#xda #x7 0 0 0 0 0 0) - (encode '(alloc)))) + #u8(4 1 2) + (encode '((jmpif (local 1) (local 2)))))) -(test encode-peek +(test encode-jmp (assert-equal - '(#xe4 #x7 0 0 0 0 0 0 #xa) - (encode '((peek 10))))) + #u8(8 1) + (encode '((jmp (local 1)))))) -(test encode-poke +(test encode-alloc (assert-equal - '(#xee #x7 0 0 0 0 0 0 #xa) - (encode '((poke 10))))) + #u8(12 1 2) + (encode '((alloc (local 1) (local 2)))))) -(test encode-peekbyte +(test encode-peek (assert-equal - '(#xf8 #x7 0 0 0 0 0 0) - (encode '(peekbyte)))) + #u8(17 1 2 1 0 0 0 0 0 0 0) + (encode '((peek (local 1) (local 2) (const 0)))))) -(test encode-pokebyte +(test encode-poke (assert-equal - '(#x2 #x8 0 0 0 0 0 0) - (encode '(pokebyte)))) + #u8(23 #x15 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0) + (encode '((poke (const 10) (local 1) (const 0)))))) -(test encode-pop +(test encode-add (assert-equal - '(#xc2 #xb 0 0 0 0 0 0) - (encode '(pop)))) + #u8(24 1 2 3) + (encode '((add (local 1) (local 2) (local 3)))))) -(test encode-local +(test encode-sub (assert-equal - '(#xcc #xb 0 0 0 0 0 0 #xa) - (encode '((local 10))))) + #u8(28 1 2 3) + (encode '((sub (local 1) (local 2) (local 3)))))) -(test encode-if +(test encode-mul (assert-equal - '(#xaa #xf 0 0 0 0 0 0 #xf6 #xff #xff #xff #xff #xff #xff #xff) - (encode '((if -10))))) + #u8(32 1 2 3) + (encode '((mul (local 1) (local 2) (local 3)))))) -(test encode-call +(test encode-div (assert-equal - '(#xb4 #xf 0 0 0 0 0 0 #xa) - (encode '((call 10))))) + #u8(36 1 2 3) + (encode '((div (local 1) (local 2) (local 3)))))) -(test encode-ret +(test encode-mod (assert-equal - '(#xbe #xf 0 0 0 0 0 0) - (encode '(ret)))) + #u8(40 1 2 3) + (encode '((mod (local 1) (local 2) (local 3)))))) -(test encode-exit +(test encode-peekbyte (assert-equal - '(#xc8 #xf 0 0 0 0 0 0) - (encode '(exit)))) + #u8(44 1 2 3) + (encode '((peekbyte (local 1) (local 2) (local 3)))))) -(test encode-putc +(test encode-pokebyte (assert-equal - '(#x92 #x13 0 0 0 0 0 0) - (encode '(putc)))) + #u8(48 1 2 3) + (encode '((pokebyte (local 1) (local 2) (local 3)))))) -(test encode-getc +(test encode-exit (assert-equal - '(#x9c #x13 0 0 0 0 0 0) - (encode '(getc)))) + #u8(52) + (encode '((exit))))) |
