guile-devel
[Top][All Lists]
Advanced

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

How do I call functions in RTL?


From: Noah Lavine
Subject: How do I call functions in RTL?
Date: Sun, 15 Jul 2012 15:36:27 -0400

Hello,

I'm trying to understand the call instruction in RTL, and having some
trouble. I'm trying to write the simplest function I can that calls
another function. I decided to do the equivalent of (lambda (x) (x)),
so I don't have to worry about top-level variable references. So I
tried the following in the latest git wip-rtl:

(define (const) 3)
(define call-arg (assemble-program '((begin-program call-arg)
(assert-nargs-ee/local 1 1) (call 1 1 1 ()) (return 1))))
(call-arg const)

If I understand correctly, call-arg is called with the procedure const
in register 0. Then it calls const, asking const to put its result in
register 1, and finally returns const's result, which is 3. Instead, I
got this error:

ERROR: In procedure (#<procedure const ()> . #0#):
ERROR: Wrong type to apply: (#<procedure const ()> . #0#)

I didn't understand this error, but after puzzling over the code for a
while, I realized that I was calling const from register 1 instead of
register 0. So I don't understand why const was even in the error, but
I fixed the typo and tried again like this:

 (define call-arg (assemble-program '((begin-program call-arg)
(assert-nargs-ee/locals 1 1) (call 1 1 0 ()) (return 1))))
(call-arg const)

That gave a segmentation fault.

So I have three questions: What did my first attempt really do? Why
did my second attempt fail? And how do I really use the call
instruction?

Thanks,
Noah



reply via email to

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