[gambit-list] Segfault while running Gambit; values/receive efficiency
Marc Feeley
feeley at iro.umontreal.ca
Sun Aug 19 11:43:27 EDT 2007
On 18-Aug-07, at 9:13 AM, andrew cooke wrote:
> Hi,
>
> Well, first of all this segfaults:
> qp6 napito: ./napito-base.scm
> Segmentation fault
> which I guess is a bug.
Yes it is. The problem is that your code has a syntax error, so the
runtime system tries to raise a syntax error exception.
Unfortunately there is a bug in this branch when the code was macro
expanded, or passed to eval. Anyway, the fix is to replace the line
(head (##source-code (##car code)))
by
(head (##source-code (##sourcify (##car code) src)))
in lib/_eval.scm and then rebuild Gambit with a make.
>
> But also, I got a bit carried away trying to remove function calls in
> matrix multiplication. I'd appreciate some advice - if the code
> worked,
> would it be efficient? In particular, do the values/receive pairs get
> "compiled away"?
No they don't. The call (values 1 2 3) actually creates a vector-
like object, tagged as a multiple-value. So the code is the same
efficiency as (vector 1 2 3). You'll get much better optimization by
using a CPS-style. This is easy in your case: just pass in the
consumer of your values as a parameter, i.e. replace
(define-syntax row1
(syntax-rules ()
((_ a b c d e f) (values a b c))))
(receive (x y z) (row1 1 2 3 4 5 6) (list x y z))
by
(define-syntax row1
(syntax-rules ()
((_ a b c d e f consumer) (consumer a b c))))
(row1 1 2 3 4 5 6 (lambda (x y z) (list x y z)))
I am considering adding a deforestation optimization to the Gambit
compiler to eliminate the construction of multiple-values objects
(and pairs, vectors, etc) when it is easy. But that's still under
development.
Marc
More information about the Gambit-list
mailing list