[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
More RTL Tests
From: |
Noah Lavine |
Subject: |
More RTL Tests |
Date: |
Sun, 14 Oct 2012 15:59:41 -0400 |
Hello,
I have been working on understanding RTL, and I wrote the following
tests. They're mostly to illustrate for myself how calling works in
RTL, but they also serve to test it. Any objections if I commit them
as part of rtl.test?
(with-test-prefix "call"
(assert-equal 42
(let ((call ;; (lambda (x) (x))
(assemble-program
'((begin-program call)
(assert-nargs-ee/locals 1 0)
(call 1 0 ())
(return 1) ;; MVRA from call
(return 1))))) ;; RA from call
(call (lambda () 42))))
(assert-equal 6
(let ((call-with-3 ;; (lambda (x) (x 3))
(assemble-program
'((begin-program call-with-3)
(assert-nargs-ee/locals 1 1)
(load-constant 1 3)
(call 2 0 (1))
(return 2) ;; MVRA from call
(return 2))))) ;; RA from call
(call-with-3 (lambda (x) (* x 2))))))
(with-test-prefix "tail-call"
(assert-equal 3
(let ((call ;; (lambda (x) (x))
(assemble-program
'((begin-program call)
(assert-nargs-ee/locals 1 0)
(tail-call 0 0)))))
(call (lambda () 3))))
(assert-equal 6
(let ((call-with-3 ;; (lambda (x) (x 3))
(assemble-program
'((begin-program call-with-3)
(assert-nargs-ee/locals 1 1)
(mov 1 0) ;; R1 <- R0
(load-constant 0 3) ;; R0 <- 3
(tail-call 1 1)))))
(call-with-3 (lambda (x) (* x 2))))))
My next goal is to learn to reference top-level variables. Could
anyone tell me how that works, to make it easier?
Thanks,
Noah
- More RTL Tests,
Noah Lavine <=