guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More RTL Tests


From: Stefan Israelsson Tampe
Subject: Re: More RTL Tests
Date: Sun, 14 Oct 2012 22:57:35 +0200



On Sun, Oct 14, 2012 at 9:59 PM, Noah Lavine <address@hidden> wrote:
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))))))

 
This look good to me

My next goal is to learn to reference top-level variables. Could
anyone tell me how that works, to make it easier?

The general way, use a symbol in loc a and a module in loc b and then issue
(resolve c b a)
(box-ref c c)

To put the symbol into c. The simplest way to check this is to pass b and a as arguments
to the funciton, you may set the toplevel by using box-set!

For reference inside functions you may use
(toplevel-ref dst var_label mod_label sym_label)

This is a bit complicated and I havenot found that all the infrastructure is in place to handle this
but basically one should need to prepare the code like this if I'm not missing anything

(program f)
(toplevel-ref 1 var mod sym)
...
(label var)
(store-slot SCM_BOOL_F)
(label mod)
(store-slot module)
(label sym)
(stire-slot 'symbol)
--------------------------------

where the stire-slot mechanism is not yet supported but should mean that aligned to SCM it stores
the needed references.

This is what I guess it all means, correct me if i'm wrong!

/Stefan


 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]